summaryrefslogtreecommitdiff
path: root/tracdb
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2024-10-27 00:36:40 +0200
committerBaptiste Mispelon <bmispelon@gmail.com>2024-11-07 15:20:19 +0100
commitba9446cd0860be0eeb7c2b3f1d7f18e9a9a13c23 (patch)
tree1e8cf5b289a1e95eaf94abcaa5a1b7c8d924790a /tracdb
parent1729f8282880759348017b6e91726500b09ed9f1 (diff)
Fixed issues with TracDBCreateDatabaseMixin
- The mixin is now compatible with TestCase.setUpTestData - The mixin now has teardown logic and can be used more than once in the testsuite
Diffstat (limited to 'tracdb')
-rw-r--r--tracdb/testutils.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tracdb/testutils.py b/tracdb/testutils.py
index 1a969893..1d15d48c 100644
--- a/tracdb/testutils.py
+++ b/tracdb/testutils.py
@@ -67,6 +67,17 @@ def create_db_tables_for_unmanaged_models(schema_editor):
_create_db_table_for_model(model, schema_editor)
+def destroy_db_tables_for_unmanaged_models(schema_editor):
+ """
+ Destroy tables for all unmanaged models in the tracdb app
+ """
+ appconfig = apps.get_app_config("tracdb")
+ for model in appconfig.get_models():
+ if model._meta.managed:
+ continue
+ schema_editor.delete_model(model)
+
+
class TracDBCreateDatabaseMixin:
"""
A TestCase mixin that creates test tables for all the tracdb apps.
@@ -75,6 +86,12 @@ class TracDBCreateDatabaseMixin:
@classmethod
def setUpClass(cls):
- super().setUpClass()
with connections["trac"].schema_editor() as schema_editor:
create_db_tables_for_unmanaged_models(schema_editor)
+ super().setUpClass()
+
+ @classmethod
+ def tearDownClass(cls):
+ super().tearDownClass()
+ with connections["trac"].schema_editor() as schema_editor:
+ destroy_db_tables_for_unmanaged_models(schema_editor)