diff options
| author | Tim Graham <timograham@gmail.com> | 2014-03-25 18:30:29 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-03-25 18:30:58 -0400 |
| commit | 42336c84a0daedfd8242333622eefe202e32398e (patch) | |
| tree | b60843d02fee1983d2f9696ed4fb3ac7c05062a3 /tests | |
| parent | 378359de1c927e8b323b6b9fa2c4d2d2606a613f (diff) | |
Fixed #22331 -- Made MigrationAutodetector ignore unmanaged models.
This commit reverts 69d4b1c and tackle the issue from a different angle.
Models remain present in the project state, but are now ignored by the
autodetector.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 27 | ||||
| -rw-r--r-- | tests/migrations/test_state.py | 11 |
2 files changed, 27 insertions, 11 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index cb628de269..5ceadc7430 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -24,6 +24,8 @@ class AutodetectorTests(TestCase): author_with_custom_user = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("user", models.ForeignKey("thirdapp.CustomUser"))]) author_proxy = ModelState("testapp", "AuthorProxy", [], {"proxy": True}, ("testapp.author", )) author_proxy_notproxy = ModelState("testapp", "AuthorProxy", [], {}, ("testapp.author", )) + author_unmanaged = ModelState("testapp", "AuthorUnmanaged", [], {"managed": False}, ("testapp.author", )) + author_unmanaged_managed = ModelState("testapp", "AuthorUnmanaged", [], {}, ("testapp.author", )) publisher = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=100))]) publisher_with_author = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("name", models.CharField(max_length=100))]) publisher_with_book = ModelState("testapp", "Publisher", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("otherapp.Book")), ("name", models.CharField(max_length=100))]) @@ -488,6 +490,31 @@ class AutodetectorTests(TestCase): self.assertEqual(action.__class__.__name__, "CreateModel") self.assertEqual(action.name, "AuthorProxy") + def test_unmanaged_ignorance(self): + "Tests that the autodetector correctly ignores managed models" + # First, we test adding an unmanaged model + before = self.make_project_state([self.author_empty]) + after = self.make_project_state([self.author_empty, self.author_unmanaged]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + # Right number of migrations? + self.assertEqual(len(changes), 0) + + # Now, we test turning an unmanaged model into a managed model + before = self.make_project_state([self.author_empty, self.author_unmanaged]) + after = self.make_project_state([self.author_empty, self.author_unmanaged_managed]) + 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, "AuthorUnmanaged") + @override_settings(AUTH_USER_MODEL="thirdapp.CustomUser") def test_swappable(self): before = self.make_project_state([self.custom_user]) diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index 80ae8922bf..10f5e7d9ab 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -52,22 +52,11 @@ class StateTests(TestCase): verbose_name = "tome" db_table = "test_tome" - class Unmanaged(models.Model): - title = models.CharField(max_length=1000) - - class Meta: - app_label = "migrations" - apps = new_apps - managed = False - project_state = ProjectState.from_apps(new_apps) author_state = project_state.models['migrations', 'author'] author_proxy_state = project_state.models['migrations', 'authorproxy'] sub_author_state = project_state.models['migrations', 'subauthor'] book_state = project_state.models['migrations', 'book'] - # unmanaged models should not appear in migrations - with self.assertRaises(KeyError): - project_state.models['migrations', 'unmanaged'] self.assertEqual(author_state.app_label, "migrations") self.assertEqual(author_state.name, "Author") |
