diff options
| author | Tim Graham <timograham@gmail.com> | 2015-05-18 09:09:13 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-18 10:14:57 -0400 |
| commit | 3c0e03ef42eda07adefaae0656613803a74e8699 (patch) | |
| tree | e13d08e5e8c9cb0fb532e2c343bc09c72fd3cb59 | |
| parent | 436f914dc5451557990629b4ff1c32f67c67002f (diff) | |
[1.8.x] Fixed #24812 -- Fixed app registry RuntimeWarnings in schema and migrations tests.
Backport of f5da4380723c93998a4f5a845b6f26fa51a2cfe1 from master
| -rw-r--r-- | tests/migrations/test_state.py | 9 | ||||
| -rw-r--r-- | tests/schema/tests.py | 13 |
2 files changed, 19 insertions, 3 deletions
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index 45f5d1d38d..1fdb305e41 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -378,17 +378,22 @@ class StateTests(TestCase): #24573 - Adding relations to existing models should reload the referenced models too. """ + new_apps = Apps() + class A(models.Model): class Meta: app_label = 'something' + apps = new_apps class B(A): class Meta: app_label = 'something' + apps = new_apps class C(models.Model): class Meta: app_label = 'something' + apps = new_apps project_state = ProjectState() project_state.add_model(ModelState.from_model(A)) @@ -429,15 +434,19 @@ class StateTests(TestCase): #24225 - Tests that relations between models are updated while remaining the relations and references for models of an old state. """ + new_apps = Apps() + class A(models.Model): class Meta: app_label = "something" + apps = new_apps class B(models.Model): to_a = models.ForeignKey(A) class Meta: app_label = "something" + apps = new_apps def get_model_a(state): return [mod for mod in state.apps.get_models() if mod._meta.model_name == 'a'][0] diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 1b8b02e01b..67a3738fd5 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -765,8 +765,10 @@ class SchemaTests(TransactionTestCase): app_label = 'schema' apps = new_apps - self.local_models = [LocalBookWithM2M] - + self.local_models = [ + LocalBookWithM2M, + LocalBookWithM2M._meta.get_field('tags').rel.through, + ] # Create the tables with connection.schema_editor() as editor: editor.create_model(Author) @@ -845,6 +847,7 @@ class SchemaTests(TransactionTestCase): # Create an M2M field new_field = M2MFieldClass("schema.TagM2MTest", related_name="authors") new_field.contribute_to_class(LocalAuthorWithM2M, "tags") + self.local_models += [new_field.rel.through] # Ensure there's no m2m table there self.assertRaises(DatabaseError, self.column_classes, new_field.rel.through) # Add the field @@ -934,7 +937,10 @@ class SchemaTests(TransactionTestCase): app_label = 'schema' apps = new_apps - self.local_models = [LocalBookWithM2M] + self.local_models = [ + LocalBookWithM2M, + LocalBookWithM2M._meta.get_field('tags').rel.through, + ] # Create the tables with connection.schema_editor() as editor: @@ -955,6 +961,7 @@ class SchemaTests(TransactionTestCase): old_field = LocalBookWithM2M._meta.get_field("tags") new_field = M2MFieldClass(UniqueTest) new_field.contribute_to_class(LocalBookWithM2M, "uniques") + self.local_models += [new_field.rel.through] with connection.schema_editor() as editor: editor.alter_field(LocalBookWithM2M, old_field, new_field) # Ensure old M2M is gone |
