summaryrefslogtreecommitdiff
path: root/tests/schema/tests.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-11-13 17:13:27 -0500
committerSimon Charette <charette.s@gmail.com>2015-11-14 12:15:51 -0500
commitafe84c71ebddfe295ed33105f38f3be7ea3f2fb0 (patch)
tree0d163715f24adbf260366546027aeb3caac3ce91 /tests/schema/tests.py
parentda20004a61f73a104bbac41ccb08b9f94f008171 (diff)
[1.8.x] Refs #25745 -- Avoided multiple registration of the same model in schema tests.
Conflicts: tests/schema/tests.py Backport of 64240263f22055cb539159e9359e64d5096f39d9 from master
Diffstat (limited to 'tests/schema/tests.py')
-rw-r--r--tests/schema/tests.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index cc1b65d563..bbf45f1cc6 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -58,6 +58,10 @@ class SchemaTests(TransactionTestCase):
model._meta._expire_cache()
if 'schema' in new_apps.all_models:
for model in self.local_models:
+ for many_to_many in model._meta.many_to_many:
+ through = many_to_many.rel.through
+ if through and through._meta.auto_created:
+ del new_apps.all_models['schema'][through._meta.model_name]
del new_apps.all_models['schema'][model._meta.model_name]
def delete_tables(self):
@@ -927,13 +931,12 @@ class SchemaTests(TransactionTestCase):
# Ensure there's no m2m table there
self.assertRaises(DatabaseError, self.column_classes, new_field.rel.through)
- # Need to tear down using a model without the added M2M field that's
- # been removed.
- class LocalAuthorWithM2M(Model):
- class Meta:
- app_label = 'schema'
- apps = new_apps
- self.local_models = [LocalAuthorWithM2M]
+ # Make sure the model state is coherent with the table one now that
+ # we've removed the tags field.
+ opts = LocalAuthorWithM2M._meta
+ opts.local_many_to_many.remove(new_field)
+ del new_apps.all_models['schema'][new_field.rel.through._meta.model_name]
+ opts._expire_cache()
def test_m2m(self):
self._test_m2m(ManyToManyField)
@@ -1032,14 +1035,8 @@ class SchemaTests(TransactionTestCase):
self.assertRaises(DatabaseError, self.column_classes, LocalBookWithM2M._meta.get_field("tags").rel.through)
# This model looks like the new model and is used for teardown.
- class LocalBookWithM2M(Model):
- uniques = M2MFieldClass(UniqueTest)
-
- class Meta:
- app_label = 'schema'
- apps = new_apps
-
- self.local_models = [LocalBookWithM2M]
+ opts = LocalBookWithM2M._meta
+ opts.local_many_to_many.remove(old_field)
# Ensure the new M2M exists and points to UniqueTest
constraints = self.get_constraints(new_field.rel.through._meta.db_table)
if connection.features.supports_foreign_keys: