mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-23 14:40:06 +03:00
Add tests for set_value()
These tests follow the examples given in the method.
This commit is contained in:
parent
dcbdb7158c
commit
a487f85d2d
|
@ -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}}
|
||||
|
|
Loading…
Reference in New Issue
Block a user