diff --git a/tests/web/handlers/test_query.py b/tests/web/handlers/test_query.py index 92c5754fe..46e0cdfbb 100644 --- a/tests/web/handlers/test_query.py +++ b/tests/web/handlers/test_query.py @@ -601,8 +601,42 @@ def test_31_scroll_stale(self): res = self.request("/v1/query?scroll_id=", expect=400).json() assert res["success"] is False - def test_32_post_filters(self): + def test_32_filter(self): """ + apply filter changes the facet result: + { + 'facets': { + 'type_of_gene': { + '_type': 'terms', + 'missing': 0, + 'other': 0, + 'terms': [{'count': 1, 'term': 'protein-coding'}], + 'total': 1 + } + }, + 'hits': [...], + 'max_score': 0.4116186, + 'took': 7, + 'total': 1 + } + """ + + res = self.request( + "/v1/query?q={q}&aggs={aggs}&filter={_filter}".format( + q="cyclin dependent kinase 2", + aggs="type_of_gene", + _filter="taxid:216574", + ) + ).json() + + assert res["total"] == 1 + term = res["facets"]["type_of_gene"]["terms"][0] + assert term["count"] == 1 + assert term["term"] == "protein-coding" + + def test_33_post_filter(self): + """ + apply post_filter won't change the facet result: { 'facets': { 'type_of_gene': { @@ -633,7 +667,7 @@ def test_32_post_filters(self): assert term["count"] == 79 assert term["term"] == "protein-coding" - def test_33_jmespath(self): + def test_34_jmespath(self): """GET /v1/query?q=_id:1017&fields=accession.rna&jmespath=accession.rna|[?contains(@, `NM_`) || contains(@, `XM_`)] { "hits": [ @@ -666,7 +700,7 @@ def test_33_jmespath(self): assert len(transformed_rna) < len_0 assert [x for x in transformed_rna if not (x.startswith("NM_") or x.startswith("XM_"))] == [] - def test_34_jmespath_root(self): + def test_35_jmespath_root(self): """GET /v1/query?q=_id:1017&fields=exons&jmespath=.|{exon_count: length(exons)} { "hits": [ @@ -684,7 +718,7 @@ def test_34_jmespath_root(self): res = self.request("/v1/query?q=_id:1017&fields=exons&jmespath=|{exon_count: length(exons)}").json() assert res["hits"][0]["exon_count"] == 3 - def test_35_jmespath_post(self): + def test_36_jmespath_post(self): """Test jmespath works for POST query as well""" res = self.request( "/v1/query", diff --git a/tests/web/options/test_locator.py b/tests/web/options/test_locator.py index 6990fecdd..f70f89405 100644 --- a/tests/web/options/test_locator.py +++ b/tests/web/options/test_locator.py @@ -52,11 +52,10 @@ def test_03(): def test_04(): - locator = {"keyword": "_source", "alias": ["fields", "field", "filter"]} + locator = {"keyword": "_source", "alias": ["fields", "field"]} assert ReqArgs(query={"q": "cdk2", "_source": "taxid"}).lookup(locator) == "taxid" assert ReqArgs(query={"q": "cdk2", "fields": "taxid"}).lookup(locator) == "taxid" assert ReqArgs(query={"q": "cdk2", "field": "taxid"}).lookup(locator) == "taxid" - assert ReqArgs(query={"q": "cdk2", "filter": "taxid"}).lookup(locator) == "taxid" def test_05(): @@ -69,7 +68,7 @@ def test_05(): ) locator = { "keyword": "_source", - "alias": ["fields", "field", "filter"], + "alias": ["fields", "field"], } assert args.lookup(locator) == "taxid" @@ -86,7 +85,7 @@ def test_06(): ) locator = { "keyword": "_source", - "alias": ["fields", "field", "filter"], + "alias": ["fields", "field"], } assert args.lookup(locator) == "taxid"