@@ -1794,6 +1794,25 @@ def test_collection_types_are_invalid_input(self):
1794
1794
assert exc_info .value .detail == ['Expected a list of items but got type "dict".' ]
1795
1795
1796
1796
1797
+ class TestNestedListField (FieldValues ):
1798
+ """
1799
+ Values for nested `ListField` with IntegerField as child.
1800
+ """
1801
+ valid_inputs = [
1802
+ ([[1 , 2 ], [3 ]], [[1 , 2 ], [3 ]]),
1803
+ ([[]], [[]])
1804
+ ]
1805
+ invalid_inputs = [
1806
+ (['not a list' ], {0 : ['Expected a list of items but got type "str".' ]}),
1807
+ ([[1 , 2 , 'error' ], ['error' ]], {0 : {2 : ['A valid integer is required.' ]}, 1 : {0 : ['A valid integer is required.' ]}}),
1808
+ ([{'one' : 'two' }], {0 : ['Expected a list of items but got type "dict".' ]})
1809
+ ]
1810
+ outputs = [
1811
+ ([[1 , 2 ], [3 ]], [[1 , 2 ], [3 ]]),
1812
+ ]
1813
+ field = serializers .ListField (child = serializers .ListField (child = serializers .IntegerField ()))
1814
+
1815
+
1797
1816
class TestEmptyListField (FieldValues ):
1798
1817
"""
1799
1818
Values for `ListField` with allow_empty=False flag.
@@ -1866,6 +1885,23 @@ def test_allow_null(self):
1866
1885
assert output is None
1867
1886
1868
1887
1888
+ class TestNestedDictField (FieldValues ):
1889
+ """
1890
+ Values for nested `DictField` with CharField as child.
1891
+ """
1892
+ valid_inputs = [
1893
+ ({0 : {'a' : 1 , 'b' : '2' }, 1 : {3 : 3 }}, {'0' : {'a' : '1' , 'b' : '2' }, '1' : {'3' : '3' }}),
1894
+ ]
1895
+ invalid_inputs = [
1896
+ ({0 : {'a' : 1 , 'b' : None }, 1 : {'c' : None }}, {'0' : {'b' : ['This field may not be null.' ]}, '1' : {'c' : ['This field may not be null.' ]}}),
1897
+ ({0 : 'not a dict' }, {'0' : ['Expected a dictionary of items but got type "str".' ]}),
1898
+ ]
1899
+ outputs = [
1900
+ ({0 : {'a' : 1 , 'b' : '2' }, 1 : {3 : 3 }}, {'0' : {'a' : '1' , 'b' : '2' }, '1' : {'3' : '3' }}),
1901
+ ]
1902
+ field = serializers .DictField (child = serializers .DictField (child = serializers .CharField ()))
1903
+
1904
+
1869
1905
class TestDictFieldWithNullChild (FieldValues ):
1870
1906
"""
1871
1907
Values for `DictField` with allow_null CharField as child.
0 commit comments