aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_fields.py
diff options
context:
space:
mode:
authorXavier Ordoquy2014-06-23 14:02:45 +0200
committerXavier Ordoquy2014-06-23 14:02:45 +0200
commit2489e38a06f575aa144644eee683bd87f20186ef (patch)
treefc52fd2280d3ef6d0dc69d53a3771ee5f499ab29 /tests/test_fields.py
parent15c2c58b43a00ec29af99e0478b70eea57560fce (diff)
parente11f41ebc4ef088a5849771dfda5a7fba4f82904 (diff)
downloaddjango-rest-framework-2489e38a06f575aa144644eee683bd87f20186ef.tar.bz2
Merge remote-tracking branch 'origin/master' into 2.4.0
Conflicts: .travis.yml docs/api-guide/viewsets.md rest_framework/serializers.py rest_framework/throttling.py tests/test_generics.py tests/test_serializers.py tox.ini
Diffstat (limited to 'tests/test_fields.py')
-rw-r--r--tests/test_fields.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/tests/test_fields.py b/tests/test_fields.py
index e65a2fb3..73b15641 100644
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -4,6 +4,7 @@ General serializer field tests.
from __future__ import unicode_literals
import datetime
+import re
from decimal import Decimal
from uuid import uuid4
from django.core import validators
@@ -103,6 +104,16 @@ class BasicFieldTests(TestCase):
keys = list(field.to_native(ret).keys())
self.assertEqual(keys, ['c', 'b', 'a', 'z'])
+ def test_widget_html_attributes(self):
+ """
+ Make sure widget_html() renders the correct attributes
+ """
+ r = re.compile('(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']?')
+ form = TimeFieldModelSerializer().data
+ attributes = r.findall(form.fields['clock'].widget_html())
+ self.assertIn(('name', 'clock'), attributes)
+ self.assertIn(('id', 'clock'), attributes)
+
class DateFieldTest(TestCase):
"""
@@ -312,7 +323,7 @@ class DateTimeFieldTest(TestCase):
f.from_native('04:61:59')
except validators.ValidationError as e:
self.assertEqual(e.messages, ["Datetime has wrong format. Use one of these formats instead: "
- "YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HHMM|-HHMM|Z]"])
+ "YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]"])
else:
self.fail("ValidationError was not properly raised")
@@ -326,7 +337,7 @@ class DateTimeFieldTest(TestCase):
f.from_native('04 -- 31')
except validators.ValidationError as e:
self.assertEqual(e.messages, ["Datetime has wrong format. Use one of these formats instead: "
- "YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HHMM|-HHMM|Z]"])
+ "YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]"])
else:
self.fail("ValidationError was not properly raised")
@@ -706,6 +717,15 @@ class ChoiceFieldTests(TestCase):
f = serializers.ChoiceField(required=False, choices=SAMPLE_CHOICES)
self.assertEqual(f.choices, models.fields.BLANK_CHOICE_DASH + SAMPLE_CHOICES)
+ def test_blank_choice_display(self):
+ blank = 'No Preference'
+ f = serializers.ChoiceField(
+ required=False,
+ choices=SAMPLE_CHOICES,
+ blank_display_value=blank,
+ )
+ self.assertEqual(f.choices, [('', blank)] + SAMPLE_CHOICES)
+
def test_invalid_choice_model(self):
s = ChoiceFieldModelSerializer(data={'choice': 'wrong_value'})
self.assertFalse(s.is_valid())