summaryrefslogtreecommitdiff
path: root/tests/field_deconstruction
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2021-04-28 21:15:26 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-28 20:25:59 +0200
commitb9df2b74b98b4d63933e8061d3cfc1f6f39eb747 (patch)
treeef8464e74158f7f103bec75463f9177b891388d2 /tests/field_deconstruction
parentb746596f5f0e1fcac791b0f7c8bfc3d69dfef2ff (diff)
downloaddjango-b9df2b74b98b4d63933e8061d3cfc1f6f39eb747.tar.gz
Fixed #32676 -- Prevented migrations from rendering related field attributes when not passed during initialization.
Thanks Simon Charette for the implementation idea.
Diffstat (limited to 'tests/field_deconstruction')
-rw-r--r--tests/field_deconstruction/tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py
index b746e46458..846f6d3ed7 100644
--- a/tests/field_deconstruction/tests.py
+++ b/tests/field_deconstruction/tests.py
@@ -432,6 +432,34 @@ class FieldDeconstructionTests(SimpleTestCase):
self.assertEqual(kwargs, {"to": "auth.Permission"})
self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
+ def test_many_to_many_field_related_name(self):
+ class MyModel(models.Model):
+ flag = models.BooleanField(default=True)
+ m2m = models.ManyToManyField('self')
+ m2m_related_name = models.ManyToManyField(
+ 'self',
+ related_name='custom_name',
+ related_query_name='custom_query_name',
+ limit_choices_to={'flag': True},
+ )
+
+ name, path, args, kwargs = MyModel.m2m.field.deconstruct()
+ self.assertEqual(path, 'django.db.models.ManyToManyField')
+ self.assertEqual(args, [])
+ # deconstruct() should not include attributes which were not passed to
+ # the field during initialization.
+ self.assertEqual(kwargs, {'to': 'field_deconstruction.MyModel'})
+ # Passed attributes.
+ name, path, args, kwargs = MyModel.m2m_related_name.field.deconstruct()
+ self.assertEqual(path, 'django.db.models.ManyToManyField')
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {
+ 'to': 'field_deconstruction.MyModel',
+ 'related_name': 'custom_name',
+ 'related_query_name': 'custom_query_name',
+ 'limit_choices_to': {'flag': True},
+ })
+
def test_positive_integer_field(self):
field = models.PositiveIntegerField()
name, path, args, kwargs = field.deconstruct()