aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTom Christie2015-01-23 16:33:37 +0000
committerTom Christie2015-01-23 16:33:37 +0000
commit8f6d7f4a5a34a144700d943cb8fcf496d0d3734a (patch)
tree10d78980e5511e1aa41175b8a11fc2b97e26f429 /tests
parentb07d931261c2e9f722fb2de63ab17f088142b6f1 (diff)
parent35f6a8246299d31ecce4f791f9527bf34cebe6e2 (diff)
downloaddjango-rest-framework-8f6d7f4a5a34a144700d943cb8fcf496d0d3734a.tar.bz2
Merge pull request #2451 from tomchristie/dict-field
Added DictField and support for HStoreField.
Diffstat (limited to 'tests')
-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.
# ---------------------