diff options
| author | Niclas Olofsson <n@niclasolofsson.se> | 2014-07-26 11:06:30 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-07-31 15:29:46 -0400 |
| commit | cdc25ac4747bf5a6cdc2e70461c2d43c54529d35 (patch) | |
| tree | 98987ea8e79363268cd59368b445e0a86dd6b7b6 /tests/model_forms | |
| parent | 75790808993691d2869db577df6db47ecbef6f5a (diff) | |
Fixed #22808 -- Made ModelMultipleChoiceField validation more robust to invalid data types..
Thanks Mattias Lindvall for the report and inital patch.
Diffstat (limited to 'tests/model_forms')
| -rw-r--r-- | tests/model_forms/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 03a498c4cd..3efc724c38 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1391,6 +1391,13 @@ class ModelChoiceFieldTests(TestCase): f.clean(None) with self.assertRaises(ValidationError): f.clean(0) + + # Invalid types that require TypeError to be caught (#22808). + with self.assertRaises(ValidationError): + f.clean([['fail']]) + with self.assertRaises(ValidationError): + f.clean([{'foo': 'bar'}]) + self.assertEqual(f.clean(self.c2.id).name, "It's a test") self.assertEqual(f.clean(self.c3.id).name, 'Third') @@ -1495,6 +1502,12 @@ class ModelMultipleChoiceFieldTests(TestCase): with self.assertRaises(ValidationError): f.clean(['fail']) + # Invalid types that require TypeError to be caught (#22808). + with self.assertRaises(ValidationError): + f.clean([['fail']]) + with self.assertRaises(ValidationError): + f.clean([{'foo': 'bar'}]) + # Add a Category object *after* the ModelMultipleChoiceField has already been # instantiated. This proves clean() checks the database during clean() rather # than caching it at time of instantiation. |
