MCPcopy Create free account
hub / github.com/cosdata/cosdata / test_json_value

Function test_json_value

tests/test-key-value-store.py:224–250  ·  view source on GitHub ↗

Test storing JSON as value

(name)

Source from the content-addressed store, hash-verified

222 results.error(f"large value ({size:,} bytes)", e)
223
224def test_json_value(name):
225 """Test storing JSON as value"""
226 print("\n[Test: JSON Values]")
227
228 test_data = {
229 "simple_json": {"name": "test", "value": 123},
230 "nested_json": {"level1": {"level2": {"level3": [1, 2, 3]}}},
231 "array_json": [1, "two", 3.0, None, True, False],
232 "complex_json": {
233 "users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}],
234 "metadata": {"created": "2024-01-01", "version": 1.5}
235 }
236 }
237
238 def do_upsert(txn_id):
239 for k, v in test_data.items():
240 upsert(name, txn_id, k, json.dumps(v))
241
242 run_in_txn(name, do_upsert)
243
244 for key, expected in test_data.items():
245 actual_str = lookup(name, key)
246 actual = json.loads(actual_str)
247 if actual == expected:
248 results.ok(f"json: {key}")
249 else:
250 results.fail(f"json: {key}", expected, actual)
251
252def test_bulk_upsert(name):
253 """Test bulk upsert of multiple items"""

Callers 1

mainFunction · 0.85

Calls 4

run_in_txnFunction · 0.85
okMethod · 0.80
failMethod · 0.80
lookupFunction · 0.70

Tested by

no test coverage detected