diff options
| author | Adam BogdaĆ <adam@bogdal.pl> | 2016-11-11 02:38:16 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-14 08:57:24 -0400 |
| commit | cd2fe829dddb4c8914ac62c93cd6d750a4e9c30c (patch) | |
| tree | 4cda6296e3abf0d1c466da30fd5836f4614c2db6 /tests | |
| parent | f2b698631719c6df082a627b6f7ddf2d7f9fa751 (diff) | |
Fixed #24195 -- Deconstructed the limit_choices_to option of related fields.
Migrations will now be created for changes to limit_choices_to.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/field_deconstruction/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index 7b816b8bf0..8bf705b1ad 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -214,6 +214,15 @@ class FieldDeconstructionTests(SimpleTestCase): self.assertEqual(path, "django.db.models.ForeignKey") self.assertEqual(args, []) self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "foobar", "on_delete": models.CASCADE}) + # Test limit_choices_to + field = models.ForeignKey("auth.Permission", models.CASCADE, limit_choices_to={'foo': 'bar'}) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.ForeignKey") + self.assertEqual(args, []) + self.assertEqual( + kwargs, + {"to": "auth.Permission", "limit_choices_to": {'foo': 'bar'}, "on_delete": models.CASCADE} + ) @override_settings(AUTH_USER_MODEL="auth.Permission") def test_foreign_key_swapped(self): @@ -228,6 +237,17 @@ class FieldDeconstructionTests(SimpleTestCase): self.assertEqual(kwargs, {"to": "auth.Permission", "on_delete": models.CASCADE}) self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL") + def test_one_to_one(self): + # Test limit_choices_to + field = models.OneToOneField("auth.Permission", models.CASCADE, limit_choices_to={'foo': 'bar'}) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.OneToOneField") + self.assertEqual(args, []) + self.assertEqual( + kwargs, + {"to": "auth.Permission", "limit_choices_to": {'foo': 'bar'}, "on_delete": models.CASCADE} + ) + def test_image_field(self): field = models.ImageField(upload_to="foo/barness", width_field="width", height_field="height") name, path, args, kwargs = field.deconstruct() @@ -294,6 +314,12 @@ class FieldDeconstructionTests(SimpleTestCase): self.assertEqual(path, "django.db.models.ManyToManyField") self.assertEqual(args, []) self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "custom_table"}) + # Test limit_choices_to + field = models.ManyToManyField("auth.Permission", limit_choices_to={'foo': 'bar'}) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.ManyToManyField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {"to": "auth.Permission", "limit_choices_to": {'foo': 'bar'}}) @override_settings(AUTH_USER_MODEL="auth.Permission") def test_many_to_many_field_swapped(self): |
