summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-09-06 12:14:09 -0500
committerAndrew Godwin <andrew@aeracode.org>2013-09-06 12:16:03 -0500
commitcdeff3acc2b7d77b7f309db7e98878e08ad9ff25 (patch)
treeb0b4707ec72465390e7859c9c9f349cfeadfc341 /tests
parent6f7977bb63ea592faaa7b3bdf2898f8361f30260 (diff)
Project/ModelState now correctly serialize multi-model inheritance
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_state.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index 1a903cb4f2..2a6fef0ac1 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -25,6 +25,13 @@ class StateTests(TestCase):
app_cache = new_app_cache
unique_together = ["name", "bio"]
+ class AuthorProxy(Author):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+ proxy = True
+ ordering = ["name"]
+
class Book(models.Model):
title = models.CharField(max_length=1000)
author = models.ForeignKey(Author)
@@ -36,6 +43,7 @@ class StateTests(TestCase):
project_state = ProjectState.from_app_cache(new_app_cache)
author_state = project_state.models['migrations', 'author']
+ author_proxy_state = project_state.models['migrations', 'authorproxy']
book_state = project_state.models['migrations', 'book']
self.assertEqual(author_state.app_label, "migrations")
@@ -54,6 +62,12 @@ class StateTests(TestCase):
self.assertEqual(book_state.fields[2][1].null, False)
self.assertEqual(book_state.options, {"verbose_name": "tome", "db_table": "test_tome"})
self.assertEqual(book_state.bases, (models.Model, ))
+
+ self.assertEqual(author_proxy_state.app_label, "migrations")
+ self.assertEqual(author_proxy_state.name, "AuthorProxy")
+ self.assertEqual(author_proxy_state.fields, [])
+ self.assertEqual(author_proxy_state.options, {"proxy": True, "ordering": ["name"]})
+ self.assertEqual(author_proxy_state.bases, ("migrations.author", ))
def test_render(self):
"""
@@ -92,5 +106,63 @@ class StateTests(TestCase):
app_label = "migrations"
app_cache = new_app_cache
+ # First, test rendering individually
yet_another_app_cache = BaseAppCache()
+
+ # We shouldn't be able to render yet
+ with self.assertRaises(ValueError):
+ ModelState.from_model(Novel).render(yet_another_app_cache)
+
+ # Once the parent model is in the app cache, it should be fine
+ ModelState.from_model(Book).render(yet_another_app_cache)
ModelState.from_model(Novel).render(yet_another_app_cache)
+
+ def test_render_project_dependencies(self):
+ """
+ Tests that the ProjectState render method correctly renders models
+ to account for inter-model base dependencies.
+ """
+ new_app_cache = BaseAppCache()
+
+ class A(models.Model):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+
+ class B(A):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+
+ class C(B):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+
+ class D(A):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+
+ class E(B):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+ proxy = True
+
+ class F(D):
+ class Meta:
+ app_label = "migrations"
+ app_cache = new_app_cache
+ proxy = True
+
+ # Make a ProjectState and render it
+ project_state = ProjectState()
+ project_state.add_model_state(ModelState.from_model(A))
+ project_state.add_model_state(ModelState.from_model(B))
+ project_state.add_model_state(ModelState.from_model(C))
+ project_state.add_model_state(ModelState.from_model(D))
+ project_state.add_model_state(ModelState.from_model(E))
+ project_state.add_model_state(ModelState.from_model(F))
+ final_app_cache = project_state.render()
+ self.assertEqual(len(final_app_cache.get_models()), 6)