Unit Testing Abstract Models in Django
Django
2018-09-25 10:10 (8 years ago)

Django: Best way to unit-test an abstract model - Stack Overflow
https://stackoverflow.com/questions/4281670/django-best-way-to-unit-test-an-abstract-model
Refer to this for more information
class CodeMemoBaseTest(TestCase):
model = None
@classmethod
def setUpClass(cls):
cls.model = ModelBase(
'__TestModel__' +
CodeMemoBase.__name__, (CodeMemoBase,),
{'__module__': CodeMemoBase.__module__}
)
# Create the schema for our test model
with connection.schema_editor() as schema_editor:
schema_editor.create_model(cls.model)
super().setUpClass()
@classmethod
def tearDownClass(cls):
# Delete the schema for the test model
with connection.schema_editor() as schema_editor:
schema_editor.delete_model(cls.model)
super().tearDownClass()
Please rate this article (No signup or login required)
Currently unrated
Related posts
How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1
Return Login and Redirect Views by Hardcoding Social Account Provider in django-allauth (When Using AWS Cognito, etc.)
After Upgrading to Django 5 and Updating Dependencies, SSL: CERTIFICATE_VERIFY_FAILED Error Occurs When Sending Emails
The "first" and "second" Arguments of assertEqual in Django's Unit Tests are Actually "expected" and "actual"
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.