def test_filter(self): query = SuggestQuery(search_text="text", suggester_name="sg") assert query.request.filter is None query.filter("expr0") assert query.request.filter == "expr0" query = SuggestQuery(search_text="text", suggester_name="sg", filter="expr1") assert query.request.filter == "expr1" query.filter("expr2") assert query.request.filter == "expr2"
def test_suggest_query_argument(self, mock_suggest_post): client = SearchClient("endpoint", "index name", CREDENTIAL) result = client.suggest( SuggestQuery(search_text="search text", suggester_name="sg")) assert mock_suggest_post.called assert mock_suggest_post.call_args[0] == () assert mock_suggest_post.call_args[1]["headers"] == client._headers assert (mock_suggest_post.call_args[1]["suggest_request"].search_text == "search text")
def test_suggest(self, api_key, endpoint, index_name, **kwargs): client = SearchClient( endpoint, index_name, AzureKeyCredential(api_key) ) query = SuggestQuery(search_text="mot", suggester_name="sg") results = client.suggest(query=query) assert results == [ {"hotelId": "2", "text": "Cheapest hotel in town. Infact, a motel."}, {"hotelId": "9", "text": "Secret Point Motel"}, ]
def test_repr(self): query = SuggestQuery(search_text="foo bar", suggester_name="sg") assert repr(query) == "<SuggestQuery [foo bar]>" query = SuggestQuery(search_text="aaaaabbbbb" * 200, suggester_name="sg") assert len(repr(query)) == 1024
def test_kwargs_forwarded(self, mock_request): mock_request.return_value = None SuggestQuery(foo=10, bar=20) assert mock_request.called assert mock_request.call_args[0] == () assert mock_request.call_args[1] == {"foo": 10, "bar": 20}
def test_init(self): query = SuggestQuery(search_text="text", suggester_name="sg") assert type(query.request) is SuggestRequest assert query.request.filter is None