Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests to ensure ListField does not except dictionary as input.
  • Loading branch information
pattisdr committed Nov 13, 2015
commit 5fdc4f22cff3e458fd2492d60133e47f607468f5
11 changes: 10 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ class TestListField(FieldValues):
]
invalid_inputs = [
('not a list', ['Expected a list of items but got type "str".']),
([1, 2, 'error'], ['A valid integer is required.'])
([1, 2, 'error'], ['A valid integer is required.']),
({'one': 'two'}, ['Expected a list of items but got type "dict".'])
]
outputs = [
([1, 2, 3], [1, 2, 3]),
Expand All @@ -1454,6 +1455,14 @@ def test_no_source_on_child(self):
"Remove `source=` from the field declaration."
)

def test_collection_types_are_invalid_input(self):
field = serializers.ListField(child=serializers.CharField())
input_value = ({'one': 'two'})

with pytest.raises(serializers.ValidationError) as exc_info:
field.to_internal_value(input_value)
assert exc_info.value.detail == [u'Expected a list of items but got type "dict".']


class TestEmptyListField(FieldValues):
"""
Expand Down