summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests/test_ordinary_fields.py
diff options
context:
space:
mode:
authorFrançois Freitag <mail+github@franek.fr>2017-11-29 22:33:24 -0800
committerTim Graham <timograham@gmail.com>2018-01-24 10:34:24 -0500
commitf9844f484186fa13399bf8b96f58616687fe158a (patch)
tree7c3894efc5f59a3b635e520b15ef6574009bd5b7 /tests/invalid_models_tests/test_ordinary_fields.py
parent8cdeb8acfcbe66289123d588dafcd438a9c28ea7 (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.py38
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')