Unit Testing Abstract Models in Django

Django
2018-09-25 19:10 (6 years ago) ytyng

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()
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011