summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-04-30 12:25:12 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-04-30 12:26:11 -0700
commit35c2a14a49ac3cb25dcff818b280bf0b4c290287 (patch)
tree38db27a3058ccd3a1db9a77c7ddec9b23968877c /tests
parenta6ecd5dbb34249f756a337c359eef1e8d78dc01e (diff)
[1.7.x] Fixed #22485: Include all unmigrated apps in project state by default.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_loader.py8
-rw-r--r--tests/migrations/test_state.py25
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):