diff options
| author | Mike Fogel <mike@fogel.ca> | 2014-04-11 23:58:56 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-04-30 07:57:35 -0400 |
| commit | bb5c7e4e8d783bf3a2880ab5cf1fa57fd35cd198 (patch) | |
| tree | fed00c72054a0ce1be074370c52a0603ce91a6fa /tests/field_subclassing/tests.py | |
| parent | 6d4df45e2927c45344b9f014f739466d61f808c8 (diff) | |
[1.7.x] Fixed #22537 -- Add tests and improved docs for field subclass with choices.
Backport of 7fd1b35ed7 from master
Diffstat (limited to 'tests/field_subclassing/tests.py')
| -rw-r--r-- | tests/field_subclassing/tests.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/field_subclassing/tests.py b/tests/field_subclassing/tests.py index 5f1dbac8a3..5c695a455c 100644 --- a/tests/field_subclassing/tests.py +++ b/tests/field_subclassing/tests.py @@ -2,12 +2,12 @@ from __future__ import unicode_literals import inspect -from django.core import serializers +from django.core import exceptions, serializers from django.db import connection from django.test import TestCase from .fields import Small, CustomTypedField -from .models import DataModel, MyModel, OtherModel +from .models import ChoicesModel, DataModel, MyModel, OtherModel class CustomField(TestCase): @@ -106,6 +106,16 @@ class CustomField(TestCase): self.assertIn('__module__', data) self.assertEqual(data['__module__'], 'field_subclassing.models') + def test_validation_of_choices_for_custom_field(self): + # a valid choice + o = ChoicesModel.objects.create(data=Small('a', 'b')) + o.full_clean() + + # an invalid choice + o = ChoicesModel.objects.create(data=Small('d', 'e')) + with self.assertRaises(exceptions.ValidationError): + o.full_clean() + class TestDbType(TestCase): |
