diff options
| author | Chris Beaven <smileychris@gmail.com> | 2014-05-02 14:50:56 +1200 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2014-05-02 15:12:42 +1200 |
| commit | 5ab93bbe747f5af185631a4ea591a501e3f8a06c (patch) | |
| tree | ca2e3a757a10c214b89de47da5a5dfddad0a8876 /tests | |
| parent | d5a9d74eec66ce7e21eae2d9a5065fdd637333c5 (diff) | |
[1.7.x] Fix migration autodector to work correctly with custom deconstructed values
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 2b8e940c4e..c92dda8377 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -7,6 +7,15 @@ from django.db.migrations.graph import MigrationGraph from django.db import models +class DeconstructableObject(object): + """ + A custom deconstructable object. + """ + + def deconstruct(self): + return self.__module__ + '.' + self.__class__.__name__, [], {} + + class AutodetectorTests(TestCase): """ Tests the migration autodetector. @@ -17,6 +26,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_name_default = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200, default='Ada Lovelace'))]) + author_name_deconstructable_1 = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200, default=DeconstructableObject()))]) + author_name_deconstructable_2 = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200, default=DeconstructableObject()))]) author_with_book = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("book", models.ForeignKey("otherapp.Book"))]) author_renamed_with_book = ModelState("testapp", "Writer", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("book", models.ForeignKey("otherapp.Book"))]) author_with_publisher_string = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200)), ("publisher_name", models.CharField(max_length=200))]) @@ -550,6 +561,17 @@ class AutodetectorTests(TestCase): self.assertEqual(action.__class__.__name__, "AddField") self.assertEqual(action.name, "name") + def test_custom_deconstructable(self): + """ + Two instances which deconstruct to the same value aren't considered a + change. + """ + before = self.make_project_state([self.author_name_deconstructable_1]) + after = self.make_project_state([self.author_name_deconstructable_2]) + autodetector = MigrationAutodetector(before, after) + changes = autodetector._detect_changes() + self.assertEqual(changes, {}) + def test_replace_string_with_foreignkey(self): """ Adding an FK in the same "spot" as a deleted CharField should work. (#22300). |
