mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #31262 -- Added support for mappings on model fields and ChoiceField's choices.
This commit is contained in:
@@ -2,6 +2,7 @@ from django.apps import apps
|
||||
from django.db import models
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.test.utils import isolate_lru_cache
|
||||
from django.utils.choices import normalize_choices
|
||||
|
||||
|
||||
class FieldDeconstructionTests(SimpleTestCase):
|
||||
@@ -105,12 +106,22 @@ class FieldDeconstructionTests(SimpleTestCase):
|
||||
self.assertEqual(kwargs, {"choices": [(0, "0"), (1, "1"), (2, "2")]})
|
||||
|
||||
def test_choices_iterable(self):
|
||||
# Pass an iterator (but not an iterable) to choices.
|
||||
# Pass an iterable (but not an iterator) 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"]})
|
||||
self.assertEqual(kwargs, {"choices": normalize_choices("012345")})
|
||||
|
||||
def test_choices_callable(self):
|
||||
def get_choices():
|
||||
return [(i, str(i)) for i in range(3)]
|
||||
|
||||
field = models.IntegerField(choices=get_choices)
|
||||
name, path, args, kwargs = field.deconstruct()
|
||||
self.assertEqual(path, "django.db.models.IntegerField")
|
||||
self.assertEqual(args, [])
|
||||
self.assertEqual(kwargs, {"choices": get_choices})
|
||||
|
||||
def test_csi_field(self):
|
||||
field = models.CommaSeparatedIntegerField(max_length=100)
|
||||
|
||||
Reference in New Issue
Block a user