aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_fields.py
diff options
context:
space:
mode:
authorTom Christie2015-01-23 16:27:23 +0000
committerTom Christie2015-01-23 16:27:23 +0000
commit35f6a8246299d31ecce4f791f9527bf34cebe6e2 (patch)
treee68af328d0e280d188e5de10b2feb1cf522fd961 /tests/test_fields.py
parent889a07f5563a0f970639a0958c0dcbc26e82919f (diff)
downloaddjango-rest-framework-35f6a8246299d31ecce4f791f9527bf34cebe6e2.tar.bz2
Added DictField and support for HStoreField.
Diffstat (limited to 'tests/test_fields.py')
-rw-r--r--tests/test_fields.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/test_fields.py b/tests/test_fields.py
index a46cc205..6744cf64 100644
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -1047,7 +1047,7 @@ class TestValidImageField(FieldValues):
class TestListField(FieldValues):
"""
- Values for `ListField`.
+ Values for `ListField` with IntegerField as child.
"""
valid_inputs = [
([1, 2, 3], [1, 2, 3]),
@@ -1064,6 +1064,55 @@ class TestListField(FieldValues):
field = serializers.ListField(child=serializers.IntegerField())
+class TestUnvalidatedListField(FieldValues):
+ """
+ Values for `ListField` with no `child` argument.
+ """
+ valid_inputs = [
+ ([1, '2', True, [4, 5, 6]], [1, '2', True, [4, 5, 6]]),
+ ]
+ invalid_inputs = [
+ ('not a list', ['Expected a list of items but got type `str`']),
+ ]
+ outputs = [
+ ([1, '2', True, [4, 5, 6]], [1, '2', True, [4, 5, 6]]),
+ ]
+ field = serializers.ListField()
+
+
+class TestDictField(FieldValues):
+ """
+ Values for `ListField` with CharField as child.
+ """
+ valid_inputs = [
+ ({'a': 1, 'b': '2', 3: 3}, {'a': '1', 'b': '2', '3': '3'}),
+ ]
+ invalid_inputs = [
+ ({'a': 1, 'b': None}, ['This field may not be null.']),
+ ('not a dict', ['Expected a dictionary of items but got type `str`']),
+ ]
+ outputs = [
+ ({'a': 1, 'b': '2', 3: 3}, {'a': '1', 'b': '2', '3': '3'}),
+ ]
+ field = serializers.DictField(child=serializers.CharField())
+
+
+class TestUnvalidatedDictField(FieldValues):
+ """
+ Values for `ListField` with no `child` argument.
+ """
+ valid_inputs = [
+ ({'a': 1, 'b': [4, 5, 6], 1: 123}, {'a': 1, 'b': [4, 5, 6], '1': 123}),
+ ]
+ invalid_inputs = [
+ ('not a dict', ['Expected a dictionary of items but got type `str`']),
+ ]
+ outputs = [
+ ({'a': 1, 'b': [4, 5, 6]}, {'a': 1, 'b': [4, 5, 6]}),
+ ]
+ field = serializers.DictField()
+
+
# Tests for FieldField.
# ---------------------