diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-04-30 12:25:12 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-04-30 12:25:12 -0700 |
| commit | 8f6dff372b174e772920de6d82bd085f1a74eaf2 (patch) | |
| tree | 96ad50fd35ecbcc48e063a65d742047be41afe7a /tests | |
| parent | 24ec9538b7ca400f68ba08fab380445ca95d7c02 (diff) | |
Fixed #22485: Include all unmigrated apps in project state by default.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_loader.py | 8 | ||||
| -rw-r--r-- | tests/migrations/test_state.py | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py index 0e9b9c23d7..34bc340495 100644 --- a/tests/migrations/test_loader.py +++ b/tests/migrations/test_loader.py @@ -61,7 +61,7 @@ class LoaderTests(TestCase): ], ) # Now render it out! - project_state = migration_loader.graph.project_state(("migrations", "0002_second")) + project_state = migration_loader.project_state(("migrations", "0002_second")) self.assertEqual(len(project_state.models), 2) author_state = project_state.models["migrations", "author"] @@ -76,6 +76,9 @@ class LoaderTests(TestCase): ["id", "author"] ) + # Ensure we've included unmigrated apps in there too + self.assertIn("contenttypes", project_state.real_apps) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_unmigdep"}) def test_load_unmigrated_dependency(self): """ @@ -86,12 +89,11 @@ class LoaderTests(TestCase): self.assertEqual( migration_loader.graph.forwards_plan(("migrations", "0001_initial")), [ - ("auth", "__first__"), ("migrations", "0001_initial"), ], ) # Now render it out! - project_state = migration_loader.graph.project_state(("migrations", "0001_initial")) + project_state = migration_loader.project_state(("migrations", "0001_initial")) self.assertEqual(len([m for a, m in project_state.models if a == "migrations"]), 1) book_state = project_state.models["migrations", "book"] diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index 9a97613485..e5cee5f6cd 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -338,6 +338,31 @@ class StateTests(TestCase): with self.assertRaises(ValueError): rendered_state = project_state.render() + def test_real_apps(self): + """ + Tests that including real apps can resolve dangling FK errors. + This test relies on the fact that contenttypes is always loaded. + """ + new_apps = Apps() + + class TestModel(models.Model): + ct = models.ForeignKey("contenttypes.ContentType") + class Meta: + app_label = "migrations" + apps = new_apps + + # If we just stick it into an empty state it should fail + project_state = ProjectState() + project_state.add_model_state(ModelState.from_model(TestModel)) + with self.assertRaises(ValueError): + rendered_state = project_state.render() + + # If we include the real app it should succeed + project_state = ProjectState(real_apps=["contenttypes"]) + project_state.add_model_state(ModelState.from_model(TestModel)) + rendered_state = project_state.render() + self.assertEqual(len(rendered_state.get_models()), 2) + class ModelStateTests(TestCase): def test_custom_model_base(self): |
