mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #22537 -- Add tests and improved docs for field subclass with choices.
This commit is contained in:
parent
8ec388a69d
commit
7fd1b35ed7
4 changed files with 30 additions and 5 deletions
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue