mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Add nested ListField/DictField tests
This commit is contained in:
parent
3fee0bf574
commit
1bb3669d08
|
@ -1794,6 +1794,25 @@ class TestListField(FieldValues):
|
||||||
assert exc_info.value.detail == ['Expected a list of items but got type "dict".']
|
assert exc_info.value.detail == ['Expected a list of items but got type "dict".']
|
||||||
|
|
||||||
|
|
||||||
|
class TestNestedListField(FieldValues):
|
||||||
|
"""
|
||||||
|
Values for nested `ListField` with IntegerField as child.
|
||||||
|
"""
|
||||||
|
valid_inputs = [
|
||||||
|
([[1, 2], [3]], [[1, 2], [3]]),
|
||||||
|
([[]], [[]])
|
||||||
|
]
|
||||||
|
invalid_inputs = [
|
||||||
|
(['not a list'], {0: ['Expected a list of items but got type "str".']}),
|
||||||
|
([[1, 2, 'error'], ['error']], {0: {2: ['A valid integer is required.']}, 1: {0: ['A valid integer is required.']}}),
|
||||||
|
([{'one': 'two'}], {0: ['Expected a list of items but got type "dict".']})
|
||||||
|
]
|
||||||
|
outputs = [
|
||||||
|
([[1, 2], [3]], [[1, 2], [3]]),
|
||||||
|
]
|
||||||
|
field = serializers.ListField(child=serializers.ListField(child=serializers.IntegerField()))
|
||||||
|
|
||||||
|
|
||||||
class TestEmptyListField(FieldValues):
|
class TestEmptyListField(FieldValues):
|
||||||
"""
|
"""
|
||||||
Values for `ListField` with allow_empty=False flag.
|
Values for `ListField` with allow_empty=False flag.
|
||||||
|
@ -1866,6 +1885,23 @@ class TestDictField(FieldValues):
|
||||||
assert output is None
|
assert output is None
|
||||||
|
|
||||||
|
|
||||||
|
class TestNestedDictField(FieldValues):
|
||||||
|
"""
|
||||||
|
Values for nested `DictField` with CharField as child.
|
||||||
|
"""
|
||||||
|
valid_inputs = [
|
||||||
|
({0: {'a': 1, 'b': '2'}, 1: {3: 3}}, {'0': {'a': '1', 'b': '2'}, '1': {'3': '3'}}),
|
||||||
|
]
|
||||||
|
invalid_inputs = [
|
||||||
|
({0: {'a': 1, 'b': None}, 1: {'c': None}}, {'0': {'b': ['This field may not be null.']}, '1': {'c': ['This field may not be null.']}}),
|
||||||
|
({0: 'not a dict'}, {'0': ['Expected a dictionary of items but got type "str".']}),
|
||||||
|
]
|
||||||
|
outputs = [
|
||||||
|
({0: {'a': 1, 'b': '2'}, 1: {3: 3}}, {'0': {'a': '1', 'b': '2'}, '1': {'3': '3'}}),
|
||||||
|
]
|
||||||
|
field = serializers.DictField(child=serializers.DictField(child=serializers.CharField()))
|
||||||
|
|
||||||
|
|
||||||
class TestDictFieldWithNullChild(FieldValues):
|
class TestDictFieldWithNullChild(FieldValues):
|
||||||
"""
|
"""
|
||||||
Values for `DictField` with allow_null CharField as child.
|
Values for `DictField` with allow_null CharField as child.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user