Skip to content

Commit

Permalink
update fixtures, add mapping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Nov 8, 2023
1 parent 9f55969 commit 59d7183
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backend/src/monarch_py/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async def initialize_app():
CurieService()


app.include_router(entity.router, prefix=f"{PREFIX}/entity")
app.include_router(association.router, prefix=f"{PREFIX}/association")
app.include_router(search.router, prefix=PREFIX)
app.include_router(entity.router, prefix=f"{PREFIX}/entity")
app.include_router(histopheno.router, prefix=f"{PREFIX}/histopheno")
app.include_router(search.router, prefix=PREFIX)
app.include_router(semsim.router, prefix=f"{PREFIX}/semsim")

# Allow CORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def parse_autocomplete(query_result: SolrQueryResult) -> SearchResults:
return SearchResults(limit=10, offset=0, total=total, items=items)


def parse_mappings(query_result: SolrQueryResult, offset: int, limit: int) -> MappingResults:
def parse_mappings(query_result: SolrQueryResult, offset: int = 0, limit: int = 20) -> MappingResults:
total = query_result.response.num_found
items = []
for doc in query_result.response.docs:
Expand Down
18 changes: 18 additions & 0 deletions backend/tests/api/test_mapping_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest.mock import MagicMock, patch

from fastapi.testclient import TestClient
from httpx import Response
from monarch_py.api.search import router

client = TestClient(router)


def test_mappings(search):
with patch.object(
client, "get", MagicMock(return_value=Response(200, json=search, headers={"content-type": "application/json"}))
):
response = client.get("/mappings?entity_id=MONDO:0000015")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
assert response.json() == search

2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_counts_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_counts_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"facet.query": [
'(category:"biolink:DiseaseToPhenotypicFeatureAssociation") AND (subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121")',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/histopheno_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def histopheno_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 2,
"params": {
"facet.query": [
'object_closure:"HP:0000924"',
Expand Down
21 changes: 21 additions & 0 deletions backend/tests/fixtures/mapping_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


@pytest.fixture
def mapping_query():
return {
"q": "*:*",
"rows": 20,
"start": 0,
"facet": True,
"facet_fields": [],
"facet_queries": [],
"filter_queries": ['subject_id:"MONDO\\:0020121" OR object_id:"MONDO\\:0020121"'],
"query_fields": None,
"def_type": "edismax",
"q_op": "AND",
"mm": "100%",
"boost": None,
"sort": None,
"facet_min_count": 1,
}
87 changes: 87 additions & 0 deletions backend/tests/fixtures/mapping_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import pytest


@pytest.fixture
def mapping_response():
return {
"responseHeader": {
"QTime": 0,
"params": {
"mm": "100%",
"q": "*:*",
"defType": "edismax",
"facet_min_count": "1",
"start": "0",
"q.op": "AND",
"fq": 'subject_id:"MONDO\\:0020121" OR object_id:"MONDO\\:0020121"',
"rows": "20",
"facet": "true",
},
},
"response": {
"num_found": 7,
"start": 0,
"docs": [
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "DOID:9884",
"object_label": "muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "cda26856-16a7-499c-956f-119cbaac5b96",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "ICD10CM:G71.0",
"object_label": "Muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "25777569-b997-4c8f-a1f3-5af352a16ee1",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "MESH:D009136",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "819ab197-2ab1-4b73-8d0f-d7d4ec14d8a7",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "NCIT:C84910",
"object_label": "Muscular Dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "adb4b8ed-c4dc-4353-a08e-a4cb02b1826e",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "SCTID:73297009",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "f6417283-c9d1-4289-aee6-16d30a4445b1",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "UMLS:C0026850",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "93968631-eedb-448b-b58a-e31e3e411dde",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "Orphanet:98473",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "e39e8ba9-8d7e-4b33-9f46-3867b652bdb5",
},
],
},
"facet_counts": {"facet_fields": {}, "facet_queries": {}},
}
75 changes: 75 additions & 0 deletions backend/tests/fixtures/mappings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pytest


@pytest.fixture
def mappings():
return {
"limit": 20,
"offset": 0,
"total": 7,
"items": [
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "DOID:9884",
"object_label": "muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "cda26856-16a7-499c-956f-119cbaac5b96",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "ICD10CM:G71.0",
"object_label": "Muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "25777569-b997-4c8f-a1f3-5af352a16ee1",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "MESH:D009136",
"object_label": None,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "819ab197-2ab1-4b73-8d0f-d7d4ec14d8a7",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "NCIT:C84910",
"object_label": "Muscular Dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "adb4b8ed-c4dc-4353-a08e-a4cb02b1826e",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "SCTID:73297009",
"object_label": None,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "f6417283-c9d1-4289-aee6-16d30a4445b1",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "UMLS:C0026850",
"object_label": None,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "93968631-eedb-448b-b58a-e31e3e411dde",
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "Orphanet:98473",
"object_label": None,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "e39e8ba9-8d7e-4b33-9f46-3867b652bdb5",
},
],
}
2 changes: 1 addition & 1 deletion backend/tests/fixtures/search_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def search_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "fanconi",
Expand Down
10 changes: 10 additions & 0 deletions backend/tests/unit/test_solr_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
parse_autocomplete,
parse_entity,
parse_histopheno,
parse_mappings,
parse_search,
)
from monarch_py.utils.utils import dict_diff
Expand Down Expand Up @@ -65,3 +66,12 @@ def test_parse_autocomplete(autocomplete_response, autocomplete):
assert (
parsed == autocomplete
), f"Parsed result is not as expected. Difference: {dict_diff(parsed.dict(), autocomplete)}"


def test_parse_mappings(mapping_response, mappings):
mapping_response["response"]["numFound"] = mapping_response["response"].pop("num_found")
solr_response = SolrQueryResult(**mapping_response)
parsed = parse_mappings(solr_response)
assert (
parsed == mappings
), f"Parsed result is not as expected. Difference: {dict_diff(parsed.dict(), mappings)}"
7 changes: 7 additions & 0 deletions backend/tests/unit/test_solr_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
build_association_query,
build_autocomplete_query,
build_histopheno_query,
build_mapping_query,
build_search_query,
)
from monarch_py.utils.utils import compare_dicts, dict_diff
Expand Down Expand Up @@ -111,3 +112,9 @@ def test_build_autocomplete_query(autocomplete_query):
query = build_autocomplete_query(q="fanc").dict()
expected = autocomplete_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"


def test_build_mappings_query(mapping_query):
query = build_mapping_query(entity_id=["MONDO:0020121"]).dict()
expected = mapping_query
assert compare_dicts(query, expected), f"Query is not as expected. Difference: {dict_diff(query, expected)}"
70 changes: 70 additions & 0 deletions frontend/fixtures/mappings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"limit": 20,
"offset": 0,
"total": 7,
"items": [
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "DOID:9884",
"object_label": "muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "cda26856-16a7-499c-956f-119cbaac5b96"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "ICD10CM:G71.0",
"object_label": "Muscular dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "25777569-b997-4c8f-a1f3-5af352a16ee1"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "MESH:D009136",
"object_label": null,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "819ab197-2ab1-4b73-8d0f-d7d4ec14d8a7"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "NCIT:C84910",
"object_label": "Muscular Dystrophy",
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "adb4b8ed-c4dc-4353-a08e-a4cb02b1826e"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "SCTID:73297009",
"object_label": null,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "f6417283-c9d1-4289-aee6-16d30a4445b1"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "UMLS:C0026850",
"object_label": null,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "93968631-eedb-448b-b58a-e31e3e411dde"
},
{
"subject_id": "MONDO:0020121",
"subject_label": "muscular dystrophy",
"predicate_id": "skos:exactMatch",
"object_id": "Orphanet:98473",
"object_label": null,
"mapping_justification": "semapv:UnspecifiedMatching",
"id": "e39e8ba9-8d7e-4b33-9f46-3867b652bdb5"
}
]
}
Loading

0 comments on commit 59d7183

Please sign in to comment.