aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_validation.py
diff options
context:
space:
mode:
authorTom Christie2014-09-11 13:20:44 +0100
committerTom Christie2014-09-11 13:20:44 +0100
commitde301f3b6647e1c79a506405a88071ef977418d1 (patch)
tree407f3497b422f334b47088b0bb35d39a8a3a520a /tests/test_validation.py
parent80ba0473473501968154c5cc5dd5922e53d96a70 (diff)
parent015a8122c7738dd8913939b42d3f0ec932d88711 (diff)
downloaddjango-rest-framework-de301f3b6647e1c79a506405a88071ef977418d1.tar.bz2
Merge master
Diffstat (limited to 'tests/test_validation.py')
-rw-r--r--tests/test_validation.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_validation.py b/tests/test_validation.py
index 40005486..c4506e7e 100644
--- a/tests/test_validation.py
+++ b/tests/test_validation.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
from django.core.validators import MaxValueValidator
+from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from rest_framework import generics, serializers, status
@@ -132,3 +133,42 @@ class TestMaxValueValidatorValidation(TestCase):
response = view(request, pk=obj.pk).render()
self.assertEqual(response.content, b'{"number_value": ["Ensure this value is less than or equal to 100."]}')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
+
+
+class TestChoiceFieldChoicesValidate(TestCase):
+ CHOICES = [
+ (0, 'Small'),
+ (1, 'Medium'),
+ (2, 'Large'),
+ ]
+
+ CHOICES_NESTED = [
+ ('Category', (
+ (1, 'First'),
+ (2, 'Second'),
+ (3, 'Third'),
+ )),
+ (4, 'Fourth'),
+ ]
+
+ def test_choices(self):
+ """
+ Make sure a value for choices works as expected.
+ """
+ f = serializers.ChoiceField(choices=self.CHOICES)
+ value = self.CHOICES[0][0]
+ try:
+ f.to_native(value)
+ except ValidationError:
+ self.fail("Value %s does not validate" % str(value))
+
+ # def test_nested_choices(self):
+ # """
+ # Make sure a nested value for choices works as expected.
+ # """
+ # f = serializers.ChoiceField(choices=self.CHOICES_NESTED)
+ # value = self.CHOICES_NESTED[0][1][0][0]
+ # try:
+ # f.to_native(value)
+ # except ValidationError:
+ # self.fail("Value %s does not validate" % str(value))