diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-09-06 12:32:52 -0500 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-09-06 12:39:46 -0500 |
| commit | 05e14e8eaf577e64dc45e26466ebb6117589e572 (patch) | |
| tree | 5be8b95ba8f5c991f66289e966b47c98e1d79e89 /tests | |
| parent | a962286b74f1e8c8cb19fb45a057800da8c2fb56 (diff) | |
Migration autodetector now corerctly deals with proxy models
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index de3b156ba6..a0ecd540cd 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -16,6 +16,8 @@ class AutodetectorTests(TestCase): author_name_longer = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=400))]) author_name_renamed = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("names", models.CharField(max_length=200))]) author_with_book = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("book", models.ForeignKey("otherapp.Book"))]) + author_proxy = ModelState("testapp", "AuthorProxy", [], {"proxy": True}, ("testapp.author", )) + author_proxy_notproxy = ModelState("testapp", "AuthorProxy", [], {}, ("testapp.author", )) other_pony = ModelState("otherapp", "Pony", [("id", models.AutoField(primary_key=True))]) other_stable = ModelState("otherapp", "Stable", [("id", models.AutoField(primary_key=True))]) third_thing = ModelState("thirdapp", "Thing", [("id", models.AutoField(primary_key=True))]) @@ -272,3 +274,28 @@ class AutodetectorTests(TestCase): self.assertEqual(action.__class__.__name__, "AlterUniqueTogether") self.assertEqual(action.name, "book") self.assertEqual(action.unique_together, set([("title", "author")])) + + def test_proxy_ignorance(self): + "Tests that the autodetector correctly ignores proxy models" + # First, we test adding a proxy model + before = self.make_project_state([self.author_empty]) + after = self.make_project_state([self.author_empty, self.author_proxy]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes), 0) + + # Now, we test turning a proxy model into a non-proxy model + before = self.make_project_state([self.author_empty, self.author_proxy]) + after = self.make_project_state([self.author_empty, self.author_proxy_notproxy]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes['testapp']), 1) + # Right number of actions? + migration = changes['testapp'][0] + self.assertEqual(len(migration.operations), 1) + # Right action? + action = migration.operations[0] + self.assertEqual(action.__class__.__name__, "CreateModel") + self.assertEqual(action.name, "AuthorProxy") |
