mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #28748 -- Made model field choices check more strict for named groups.
This commit is contained in:
committed by
Tim Graham
parent
8cdeb8acfc
commit
f9844f4841
@@ -210,6 +210,44 @@ class CharFieldTests(TestCase):
|
||||
|
||||
self.assertEqual(Model._meta.get_field('field').check(), [])
|
||||
|
||||
def test_choices_named_group_non_pairs(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(
|
||||
max_length=10,
|
||||
choices=[['knights', [['L', 'Lancelot', 'Du Lac']]]],
|
||||
)
|
||||
|
||||
field = Model._meta.get_field('field')
|
||||
self.assertEqual(field.check(), [
|
||||
Error(
|
||||
"'choices' must be an iterable containing (actual value, "
|
||||
"human readable name) tuples.",
|
||||
obj=field,
|
||||
id='fields.E005',
|
||||
),
|
||||
])
|
||||
|
||||
def test_choices_named_group_bad_structure(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(
|
||||
max_length=10, choices=[
|
||||
['knights', [
|
||||
['Noble', [['G', 'Galahad']]],
|
||||
['Combative', [['L', 'Lancelot']]],
|
||||
]],
|
||||
],
|
||||
)
|
||||
|
||||
field = Model._meta.get_field('field')
|
||||
self.assertEqual(field.check(), [
|
||||
Error(
|
||||
"'choices' must be an iterable containing (actual value, "
|
||||
"human readable name) tuples.",
|
||||
obj=field,
|
||||
id='fields.E005',
|
||||
),
|
||||
])
|
||||
|
||||
def test_bad_db_index_value(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(max_length=10, db_index='bad')
|
||||
|
||||
Reference in New Issue
Block a user