diff options
| author | François Freitag <mail+github@franek.fr> | 2018-01-24 10:16:08 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-24 10:27:27 -0500 |
| commit | 8cdeb8acfcbe66289123d588dafcd438a9c28ea7 (patch) | |
| tree | a8ec618a524a0dbee158cb945e892d43ec22160b /tests/invalid_models_tests/test_ordinary_fields.py | |
| parent | 9d129b72cea9e9e3850f3f657136ba3bbf6f633f (diff) | |
Added more tests for model field choices validation.
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 27 |
1 files changed, 27 insertions, 0 deletions
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') |
