diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-08-12 12:49:20 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-08-12 12:51:11 -0700 |
| commit | 72fdd62e93cf8bc3a6bfad4d24b06a474ad56942 (patch) | |
| tree | ce9fbe8a073da858782a93fca2714108e59667d9 /tests | |
| parent | 8f9dd9f256239d77ef20d6b4d2f48f08208e504a (diff) | |
[1.7.x] Fixed #23275: Unmanaged models kept by autodetector, ignored by ops
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 22 | ||||
| -rw-r--r-- | tests/migrations/test_operations.py | 29 |
2 files changed, 39 insertions, 12 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 096102ed78..2ab96757bc 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -637,30 +637,28 @@ class AutodetectorTests(TestCase): self.assertOperationAttributes(changes, "testapp", 0, 0, name="AuthorProxy") self.assertOperationAttributes(changes, "testapp", 0, 1, name="AuthorProxy", options={}) - def test_unmanaged_ignorance(self): - "Tests that the autodetector correctly ignores managed models" + def test_unmanaged(self): + "Tests that the autodetector correctly deals with 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) - + self.assertNumberMigrations(changes, 'testapp', 1) + self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel"]) + self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged") + self.assertEqual(changes['testapp'][0].operations[0].options['managed'], False) # 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") + self.assertNumberMigrations(changes, 'testapp', 1) + self.assertOperationTypes(changes, 'testapp', 0, ["DeleteModel", "CreateModel"]) + self.assertOperationAttributes(changes, 'testapp', 0, 0, name="AuthorUnmanaged") + self.assertOperationAttributes(changes, 'testapp', 0, 1, name="AuthorUnmanaged") @override_settings(AUTH_USER_MODEL="thirdapp.CustomUser") def test_swappable(self): diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 985ff45648..8f6cb7b4cb 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -326,6 +326,35 @@ class OperationTests(OperationTestBase): self.assertTableNotExists("test_crprmo_proxypony") self.assertTableExists("test_crprmo_pony") + def test_create_unmanaged_model(self): + """ + Tests that CreateModel ignores unmanaged models. + """ + project_state = self.set_up_test_model("test_crummo") + # Test the state alteration + operation = migrations.CreateModel( + "UnmanagedPony", + [], + options={"proxy": True}, + bases=("test_crummo.Pony", ), + ) + self.assertEqual(operation.describe(), "Create proxy model UnmanagedPony") + new_state = project_state.clone() + operation.state_forwards("test_crummo", new_state) + self.assertIn(("test_crummo", "unmanagedpony"), new_state.models) + # Test the database alteration + self.assertTableNotExists("test_crummo_unmanagedpony") + self.assertTableExists("test_crummo_pony") + with connection.schema_editor() as editor: + operation.database_forwards("test_crummo", editor, project_state, new_state) + self.assertTableNotExists("test_crummo_unmanagedpony") + self.assertTableExists("test_crummo_pony") + # And test reversal + with connection.schema_editor() as editor: + operation.database_backwards("test_crummo", editor, new_state, project_state) + self.assertTableNotExists("test_crummo_unmanagedpony") + self.assertTableExists("test_crummo_pony") + def test_delete_model(self): """ Tests the DeleteModel operation. |
