diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_operations.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 553ed58ea4..cab0caf75a 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -5,7 +5,7 @@ import unittest from django.db import connection, migrations, models, transaction from django.db.migrations.migration import Migration from django.db.migrations.operations import CreateModel -from django.db.migrations.state import ProjectState +from django.db.migrations.state import ModelState, ProjectState from django.db.models.fields import NOT_PROVIDED from django.db.transaction import atomic from django.db.utils import IntegrityError @@ -590,6 +590,26 @@ class OperationTests(OperationTestBase): self.assertEqual(definition[1], []) self.assertEqual(definition[2], {'old_name': "Pony", 'new_name': "Horse"}) + def test_rename_model_state_forwards(self): + """ + RenameModel operations shouldn't trigger the caching of rendered apps + on state without prior apps. + """ + state = ProjectState() + state.add_model(ModelState('migrations', 'Foo', [])) + operation = migrations.RenameModel('Foo', 'Bar') + operation.state_forwards('migrations', state) + self.assertNotIn('apps', state.__dict__) + self.assertNotIn(('migrations', 'foo'), state.models) + self.assertIn(('migrations', 'bar'), state.models) + # Now with apps cached. + apps = state.apps + operation = migrations.RenameModel('Bar', 'Foo') + operation.state_forwards('migrations', state) + self.assertIs(state.apps, apps) + self.assertNotIn(('migrations', 'bar'), state.models) + self.assertIn(('migrations', 'foo'), state.models) + def test_rename_model_with_self_referential_fk(self): """ Tests the RenameModel operation on model with self referential FK. |
