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

Method test_fields_as_name

tests/test_search.py:1229–1252  ·  view source on GitHub ↗
(self, client)

Source from the content-addressed store, hash-verified

1227 @pytest.mark.redismod
1228 @skip_ifmodversion_lt("2.2.0", "search")
1229 def test_fields_as_name(self, client):
1230 # create index
1231 SCHEMA = (
1232 TextField("$.name", sortable=True, as_name="name"),
1233 NumericField("$.age", as_name="just_a_number"),
1234 )
1235 definition = IndexDefinition(index_type=IndexType.JSON)
1236 client.ft().create_index(SCHEMA, definition=definition)
1237
1238 # insert json data
1239 res = client.json().set("doc:1", Path.root_path(), {"name": "Jon", "age": 25})
1240 assert res
1241
1242 res = client.ft().search(Query("Jon").return_fields("name", "just_a_number"))
1243 if expects_resp2_shape(client) or expects_unified_shape(client):
1244 assert 1 == len(res.docs)
1245 assert "doc:1" == res.docs[0].id
1246 assert "Jon" == res.docs[0].name
1247 assert "25" == res.docs[0].just_a_number
1248 elif expects_resp3_shape(client):
1249 assert 1 == len(res["results"])
1250 assert "doc:1" == res["results"][0]["id"]
1251 assert "Jon" == res["results"][0]["extra_attributes"]["name"]
1252 assert "25" == res["results"][0]["extra_attributes"]["just_a_number"]
1253
1254 @pytest.mark.redismod
1255 def test_casesensitive(self, client):

Callers

nothing calls this directly

Calls 14

TextFieldClass · 0.90
NumericFieldClass · 0.90
IndexDefinitionClass · 0.90
QueryClass · 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
return_fieldsMethod · 0.80
ftMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected