summaryrefslogtreecommitdiff
path: root/tests/field_deconstruction
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2023-08-16 15:15:31 -0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-22 05:55:23 +0200
commitf1c0a3baf74baae94a0d4137782e15edcdf54a7e (patch)
treeb287002bf0df8b534244469d7383a34236a3b966 /tests/field_deconstruction
parent6934fc3f6eeaecc9363d0949c2f9691940a12121 (diff)
Added tests for model field's choices iterator/iterable values.
Diffstat (limited to 'tests/field_deconstruction')
-rw-r--r--tests/field_deconstruction/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py
index c78ed62876..3663886708 100644
--- a/tests/field_deconstruction/tests.py
+++ b/tests/field_deconstruction/tests.py
@@ -97,6 +97,21 @@ class FieldDeconstructionTests(SimpleTestCase):
kwargs, {"choices": [("A", "One"), ("B", "Two")], "max_length": 1}
)
+ def test_choices_iterator(self):
+ field = models.IntegerField(choices=((i, str(i)) for i in range(3)))
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.IntegerField")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"choices": [(0, "0"), (1, "1"), (2, "2")]})
+
+ def test_choices_iterable(self):
+ # Pass an iterator (but not an iterable) to choices.
+ field = models.IntegerField(choices="012345")
+ name, path, args, kwargs = field.deconstruct()
+ self.assertEqual(path, "django.db.models.IntegerField")
+ self.assertEqual(args, [])
+ self.assertEqual(kwargs, {"choices": ["0", "1", "2", "3", "4", "5"]})
+
def test_csi_field(self):
field = models.CommaSeparatedIntegerField(max_length=100)
name, path, args, kwargs = field.deconstruct()