MCPcopy
hub / github.com/redis/redis-py / test_json_merge

Function test_json_merge

tests/test_json.py:153–181  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

151@pytest.mark.redismod
152@skip_ifmodversion_lt("2.06.00", "ReJSON") # todo: update after the release
153def test_json_merge(client):
154 # Test with root path $
155 assert client.json().set(
156 "person_data",
157 "$",
158 {"person1": {"personal_data": {"name": "John"}}},
159 )
160 assert client.json().merge(
161 "person_data", "$", {"person1": {"personal_data": {"hobbies": "reading"}}}
162 )
163 assert client.json().get("person_data") == {
164 "person1": {"personal_data": {"name": "John", "hobbies": "reading"}}
165 }
166
167 # Test with root path path $.person1.personal_data
168 assert client.json().merge(
169 "person_data", "$.person1.personal_data", {"country": "Israel"}
170 )
171 assert client.json().get("person_data") == {
172 "person1": {
173 "personal_data": {"name": "John", "hobbies": "reading", "country": "Israel"}
174 }
175 }
176
177 # Test with null value to delete a value
178 assert client.json().merge("person_data", "$.person1.personal_data", {"name": None})
179 assert client.json().get("person_data") == {
180 "person1": {"personal_data": {"country": "Israel", "hobbies": "reading"}}
181 }
182
183
184@pytest.mark.redismod

Callers

nothing calls this directly

Calls 4

setMethod · 0.45
jsonMethod · 0.45
mergeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected