mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
commit
46b313315a
|
@ -796,7 +796,7 @@ class ChoiceField(WritableField):
|
||||||
if value == smart_unicode(k2):
|
if value == smart_unicode(k2):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if value == smart_unicode(k):
|
if value == smart_unicode(k) or value == k:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ class RESTFrameworkModel(models.Model):
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class HasPositiveIntegerAsChoice(RESTFrameworkModel):
|
||||||
|
some_choices = ((1,'A'),(2,'B'),(3,'C'))
|
||||||
|
some_integer = models.PositiveIntegerField(choices=some_choices)
|
||||||
|
|
||||||
class Anchor(RESTFrameworkModel):
|
class Anchor(RESTFrameworkModel):
|
||||||
text = models.CharField(max_length=100, default='anchor')
|
text = models.CharField(max_length=100, default='anchor')
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
||||||
import pickle
|
import pickle
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.tests.models import (Album, ActionItem, Anchor, BasicModel,
|
from rest_framework.tests.models import (HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
||||||
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
||||||
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo)
|
||||||
|
|
||||||
|
@ -69,6 +69,11 @@ class AlbumsSerializer(serializers.ModelSerializer):
|
||||||
model = Album
|
model = Album
|
||||||
fields = ['title'] # lists are also valid options
|
fields = ['title'] # lists are also valid options
|
||||||
|
|
||||||
|
class PositiveIntegerAsChoiceSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = HasPositiveIntegerAsChoice
|
||||||
|
fields = ['some_integer']
|
||||||
|
|
||||||
|
|
||||||
class BasicTests(TestCase):
|
class BasicTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -285,6 +290,12 @@ class ValidationTests(TestCase):
|
||||||
self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']})
|
self.assertEquals(serializer.errors, {'info': [u'Ensure this value has at most 12 characters (it has 13).']})
|
||||||
|
|
||||||
|
|
||||||
|
class PositiveIntegerAsChoiceTests(TestCase):
|
||||||
|
def test_positive_integer_in_json_is_correctly_parsed(self):
|
||||||
|
data = {'some_integer':1}
|
||||||
|
serializer = PositiveIntegerAsChoiceSerializer(data=data)
|
||||||
|
self.assertEquals(serializer.is_valid(), True)
|
||||||
|
|
||||||
class ModelValidationTests(TestCase):
|
class ModelValidationTests(TestCase):
|
||||||
def test_validate_unique(self):
|
def test_validate_unique(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user