1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Added tests for model field's choices iterator/iterable values.

This commit is contained in:
Natalia
2023-08-16 15:15:31 -03:00
committed by Mariusz Felisiak
parent 6934fc3f6e
commit f1c0a3baf7
3 changed files with 28 additions and 0 deletions

View File

@@ -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()