Skip to content

Commit

Permalink
test(web): 🧪 add/update tests related to new filter param
Browse files Browse the repository at this point in the history
RE: #296
  • Loading branch information
newgene committed Oct 20, 2023
1 parent 161e055 commit 665c6ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
42 changes: 38 additions & 4 deletions tests/web/handlers/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,42 @@ def test_31_scroll_stale(self):
res = self.request("/v1/query?scroll_id=<invalid>", 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': {
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand All @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions tests/web/options/test_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -69,7 +68,7 @@ def test_05():
)
locator = {
"keyword": "_source",
"alias": ["fields", "field", "filter"],
"alias": ["fields", "field"],
}

assert args.lookup(locator) == "taxid"
Expand All @@ -86,7 +85,7 @@ def test_06():
)
locator = {
"keyword": "_source",
"alias": ["fields", "field", "filter"],
"alias": ["fields", "field"],
}

assert args.lookup(locator) == "taxid"
Expand Down

0 comments on commit 665c6ee

Please sign in to comment.