Skip to content

Commit

Permalink
Added missing test resolving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanesoban committed Dec 17, 2024
1 parent 3d2dcf8 commit a891f84
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions swarm_copy_tests/test_resolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,147 @@ async def test_es_resolve(httpx_mock, get_resolve_query_output):
"id": "http://uri.interlex.org/base/ilx_0105169",
},
]


@pytest.mark.asyncio
async def test_resolve_query(httpx_mock, get_resolve_query_output):
url = "http://terribleurl.com"
class_view_url = "http://somewhatokurl.com"
# Mock exact match to fail
httpx_mock.add_response(
url=url,
json={
"head": {"vars": ["subject", "predicate", "object", "context"]},
"results": {"bindings": []},
},
)

# Hit fuzzy match
httpx_mock.add_response(
url=url,
json=get_resolve_query_output[2],
)

# Hit ES match
httpx_mock.add_response(
url=class_view_url,
json=get_resolve_query_output[4],
)
response = await resolve_query(
query="Field",
resource_type="nsg:BrainRegion",
sparql_view_url=url,
es_view_url=class_view_url,
token="greattokenpleasedontexpire",
httpx_client=AsyncClient(),
search_size=3,
)
assert response == [
{
"label": "Field CA1",
"id": "http://api.brain-map.org/api/v2/data/Structure/382",
},
{
"label": "Field CA2",
"id": "http://api.brain-map.org/api/v2/data/Structure/423",
},
{
"label": "Field CA3",
"id": "http://api.brain-map.org/api/v2/data/Structure/463",
},
]
httpx_mock.reset()

httpx_mock.add_response(url=url, json=get_resolve_query_output[0])

# Hit fuzzy match
httpx_mock.add_response(
url=url,
json={
"head": {"vars": ["subject", "predicate", "object", "context"]},
"results": {"bindings": []},
},
)

# Hit ES match
httpx_mock.add_response(url=class_view_url, json={"hits": {"hits": []}})

response = await resolve_query(
query="Thalamus",
resource_type="nsg:BrainRegion",
sparql_view_url=url,
es_view_url=class_view_url,
token="greattokenpleasedontexpire",
httpx_client=AsyncClient(),
search_size=3,
)
assert response == [
{
"label": "Thalamus",
"id": "http://api.brain-map.org/api/v2/data/Structure/549",
}
]
httpx_mock.reset()
httpx_mock.add_response(
url=url,
json={
"head": {"vars": ["subject", "predicate", "object", "context"]},
"results": {"bindings": []},
},
)

# Hit fuzzy match
httpx_mock.add_response(
url=url,
json={
"head": {"vars": ["subject", "predicate", "object", "context"]},
"results": {"bindings": []},
},
)

# Hit ES match
httpx_mock.add_response(
url=class_view_url,
json=get_resolve_query_output[4],
)
response = await resolve_query(
query="Auditory Cortex",
resource_type="nsg:BrainRegion",
sparql_view_url=url,
es_view_url=class_view_url,
token="greattokenpleasedontexpire",
httpx_client=AsyncClient(),
search_size=3,
)
assert response == [
{
"label": "Cerebral cortex",
"id": "http://api.brain-map.org/api/v2/data/Structure/688",
},
{
"label": "Cerebellar cortex",
"id": "http://api.brain-map.org/api/v2/data/Structure/528",
},
{
"label": "Frontal pole, cerebral cortex",
"id": "http://api.brain-map.org/api/v2/data/Structure/184",
},
]


@pytest.mark.parametrize(
"before,after",
[
("this is a text", "this is a text"),
("this is text with punctuation!", "this is text with punctuation\\\\!"),
],
)
def test_escape_punctuation(before, after):
assert after == escape_punctuation(before)


def test_failing_escape_punctuation():
text = 15 # this is not a string
with pytest.raises(TypeError) as e:
escape_punctuation(text)
assert e.value.args[0] == "Only accepting strings."

0 comments on commit a891f84

Please sign in to comment.