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

Method test_json_with_multipath

tests/test_search.py:2542–2583  ·  view source on GitHub ↗

Create definition with IndexType.JSON as index type (ON JSON), and use json client to test it.

(self, client)

Source from the content-addressed store, hash-verified

2540 @pytest.mark.redismod
2541 @skip_ifmodversion_lt("2.2.0", "search")
2542 def test_json_with_multipath(self, client):
2543 """
2544 Create definition with IndexType.JSON as index type (ON JSON),
2545 and use json client to test it.
2546 """
2547 definition = IndexDefinition(prefix=["king:"], index_type=IndexType.JSON)
2548 client.ft().create_index(
2549 (TagField("$..name", as_name="name")), definition=definition
2550 )
2551
2552 client.json().set(
2553 "king:1",
2554 Path.root_path(),
2555 {"name": "henry", "country": {"name": "england"}},
2556 )
2557
2558 if expects_resp2_shape(client) or expects_unified_shape(client):
2559 res = client.ft().search("@name:{henry}")
2560 assert res.docs[0].id == "king:1"
2561 assert res.docs[0].json == '{"name":"henry","country":{"name":"england"}}'
2562 assert res.total == 1
2563
2564 res = client.ft().search("@name:{england}")
2565 assert res.docs[0].id == "king:1"
2566 assert res.docs[0].json == '{"name":"henry","country":{"name":"england"}}'
2567 assert res.total == 1
2568 elif expects_resp3_shape(client):
2569 res = client.ft().search("@name:{henry}")
2570 assert res["results"][0]["id"] == "king:1"
2571 assert (
2572 res["results"][0]["extra_attributes"]["$"]
2573 == '{"name":"henry","country":{"name":"england"}}'
2574 )
2575 assert res["total_results"] == 1
2576
2577 res = client.ft().search("@name:{england}")
2578 assert res["results"][0]["id"] == "king:1"
2579 assert (
2580 res["results"][0]["extra_attributes"]["$"]
2581 == '{"name":"henry","country":{"name":"england"}}'
2582 )
2583 assert res["total_results"] == 1
2584
2585 @pytest.mark.redismod
2586 @skip_ifmodversion_lt("2.2.0", "search")

Callers

nothing calls this directly

Calls 11

IndexDefinitionClass · 0.90
TagFieldClass · 0.90
expects_resp2_shapeFunction · 0.85
expects_unified_shapeFunction · 0.85
expects_resp3_shapeFunction · 0.85
create_indexMethod · 0.80
root_pathMethod · 0.80
ftMethod · 0.45
setMethod · 0.45
jsonMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected