diff options
| author | Simon Charette <charette.s@gmail.com> | 2014-05-22 18:51:11 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-06-01 15:10:38 -0400 |
| commit | 7a38f889222dfbdf0e0d8d22001c30264d420054 (patch) | |
| tree | d3b6f00405c594a73893b162d8124a5518c1a330 /tests | |
| parent | f384b638e20ba33fee948cbf5aa816e2512b0479 (diff) | |
Fixed #22659 -- Prevent model states from sharing field instances.
Thanks to Trac alias tbartelmess for the report and the test project.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 4 | ||||
| -rw-r--r-- | tests/migrations/test_state.py | 19 |
2 files changed, 20 insertions, 3 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 88b67d2c23..1fdab21061 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -241,7 +241,7 @@ class AutodetectorTests(TestCase): action = migration.operations[0] self.assertEqual(action.__class__.__name__, "AlterField") self.assertEqual(action.name, "author") - self.assertEqual(action.field.rel.to.__name__, "Writer") + self.assertEqual(action.field.rel.to, "testapp.Writer") def test_rename_model_with_renamed_rel_field(self): """ @@ -278,7 +278,7 @@ class AutodetectorTests(TestCase): action = migration.operations[1] self.assertEqual(action.__class__.__name__, "AlterField") self.assertEqual(action.name, "writer") - self.assertEqual(action.field.rel.to.__name__, "Writer") + self.assertEqual(action.field.rel.to, "testapp.Writer") def test_fk_dependency(self): "Tests that having a ForeignKey automatically adds a dependency" diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index ab65630105..9be04f3dfc 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -356,7 +356,7 @@ class StateTests(TestCase): project_state = ProjectState() project_state.add_model_state(ModelState.from_model(TestModel)) with self.assertRaises(ValueError): - rendered_state = project_state.render() + project_state.render() # If we include the real app it should succeed project_state = ProjectState(real_apps=["contenttypes"]) @@ -372,3 +372,20 @@ class ModelStateTests(TestCase): def test_custom_model_base(self): state = ModelState.from_model(ModelWithCustomBase) self.assertEqual(state.bases, (models.Model,)) + + def test_bound_field_sanity_check(self): + field = models.CharField(max_length=1) + field.model = models.Model + with self.assertRaisesMessage(ValueError, + 'ModelState.fields cannot be bound to a model - "field" is.'): + ModelState('app', 'Model', [('field', field)]) + + def test_fields_immutability(self): + """ + Tests that rendering a model state doesn't alter its internal fields. + """ + apps = Apps() + field = models.CharField(max_length=1) + state = ModelState('app', 'Model', [('name', field)]) + Model = state.render(apps) + self.assertNotEqual(Model._meta.get_field('name'), field) |
