diff options
| author | François Freitag <mail+github@franek.fr> | 2017-11-29 22:33:24 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-24 10:34:24 -0500 |
| commit | f9844f484186fa13399bf8b96f58616687fe158a (patch) | |
| tree | 7c3894efc5f59a3b635e520b15ef6574009bd5b7 /tests/invalid_models_tests/test_ordinary_fields.py | |
| parent | 8cdeb8acfcbe66289123d588dafcd438a9c28ea7 (diff) | |
Fixed #28748 -- Made model field choices check more strict for named groups.
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 2c78d60924..75e6148f98 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -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') |
