diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index d06f6dd689..2c78d60924 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -149,6 +149,21 @@ class CharFieldTests(TestCase): ), ]) + def test_non_iterable_choices_two_letters(self): + """Two letters isn't a valid choice pair.""" + class Model(models.Model): + field = models.CharField(max_length=10, choices=['ab']) + + 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_iterable_of_iterable_choices(self): class ThingItem: def __init__(self, value, display): @@ -183,6 +198,18 @@ class CharFieldTests(TestCase): ), ]) + def test_choices_named_group(self): + class Model(models.Model): + field = models.CharField( + max_length=10, choices=[ + ['knights', [['L', 'Lancelot'], ['G', 'Galahad']]], + ['wizards', [['T', 'Tim the Enchanter']]], + ['R', 'Random character'], + ], + ) + + self.assertEqual(Model._meta.get_field('field').check(), []) + def test_bad_db_index_value(self): class Model(models.Model): field = models.CharField(max_length=10, db_index='bad')