Add tests for set_value()

These tests follow the examples given in the method.
This commit is contained in:
Étienne Beaulé 2023-02-27 21:40:33 -04:00
parent dcbdb7158c
commit a487f85d2d

View File

@ -740,3 +740,24 @@ class TestDeclaredFieldInheritance:
'f4': serializers.CharField,
'f5': serializers.CharField,
}
class TestSetValueMethod:
# Serializer.set_value() modifies the first parameter in-place.
s = serializers.Serializer()
def test_no_keys(self):
ret = {'a': 1}
self.s.set_value(ret, [], {'b': 2})
assert ret == {'a': 1, 'b': 2}
def test_one_key(self):
ret = {'a': 1}
self.s.set_value(ret, ['x'], 2)
assert ret == {'a': 1, 'x': 2}
def test_nested_key(self):
ret = {'a': 1}
self.s.set_value(ret, ['x', 'y'], 2)
assert ret == {'a': 1, 'x': {'y': 2}}