Skip to content

Commit

Permalink
fix tests failed
Browse files Browse the repository at this point in the history
  • Loading branch information
thanh-nguyen-dang committed Sep 6, 2023
1 parent c72c66a commit bbe58d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
15 changes: 14 additions & 1 deletion src/mds/agg_mds/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ def getRemoteDataAsJson(self, **kwargs) -> Dict:
logger.error(
f"An error occurred while requesting {mds_url} {exc}. Skipping {id}"
)
print("Results: ")
print(results)

return results

Expand Down Expand Up @@ -507,14 +509,20 @@ def getRemoteDataAsJson(self, **kwargs) -> Dict:

mds_url = kwargs.get("mds_url", None)
if mds_url is None:
print("Clinical result with mds_url is None: ")
print(results)
return results

if "filters" not in kwargs or kwargs["filters"] is None:
print("Clinical result with filters is None: ")
print(results)
return results

term = kwargs["filters"].get("term", None)

if term == None:
print("Clinical result with term is None: ")
print(results)
return results

term = term.replace(" ", "+")
Expand Down Expand Up @@ -552,6 +560,8 @@ def getRemoteDataAsJson(self, **kwargs) -> Dict:
numReturned = data["FullStudiesResponse"]["NStudiesReturned"]
results["results"].extend(data["FullStudiesResponse"]["FullStudies"])
if maxItems is not None and len(results["results"]) >= maxItems:
print("Clinical result with maxItems is not None and result more than maxItems: ")
print(results)
return results
remaining = remaining - numReturned
offset += numReturned
Expand All @@ -575,7 +585,8 @@ def getRemoteDataAsJson(self, **kwargs) -> Dict:
f"An error occurred while requesting {mds_url} {exc}. Returning {len(results['results'])} results."
)
break

print("Clinical result: ")
print(results)
return results

@staticmethod
Expand Down Expand Up @@ -1592,6 +1603,8 @@ def gather_metadata(
globalFieldFilters=globalFieldFilters,
schema=schema,
)
print("Result after normalizing: ")
print(results)
return results
except ValueError as exc:
logger.error(f"Exception occurred: {exc}. Returning no results")
Expand Down
7 changes: 1 addition & 6 deletions src/mds/agg_mds/datastore/elasticsearch_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ async def update_metadata(
index_to_update = AGG_MDS_INFO_INDEX_TEMP if use_temp_index else AGG_MDS_INFO_INDEX
elastic_search_client.index(
index=index_to_update,
doc_type=AGG_MDS_INFO_TYPE,
id=name,
body=info,
)
Expand All @@ -223,9 +222,7 @@ async def update_metadata(

async def update_global_info(key, doc, use_temp_index: bool = False) -> None:
index_to_update = AGG_MDS_INFO_INDEX_TEMP if use_temp_index else AGG_MDS_INFO_INDEX
elastic_search_client.index(
index=index_to_update, doc_type=AGG_MDS_INFO_TYPE, id=key, body=doc
)
elastic_search_client.index(index=index_to_update, id=key, body=doc)


async def update_config_info(doc, use_temp_index: bool = False) -> None:
Expand All @@ -234,7 +231,6 @@ async def update_config_info(doc, use_temp_index: bool = False) -> None:
)
elastic_search_client.index(
index=index_to_update,
doc_type="_doc",
id=AGG_MDS_INDEX,
body=doc,
)
Expand Down Expand Up @@ -517,7 +513,6 @@ async def get_by_guid(guid):
try:
data = elastic_search_client.get(
index=AGG_MDS_INDEX,
doc_type=AGG_MDS_TYPE,
id=guid,
)
return data["_source"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agg_mds_clinicaltrials_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def test_get_metadata_clinicaltrials():
).mock(
return_value=httpx.Response(
status_code=404,
content={},
content="{}",
)
)

Expand Down
15 changes: 4 additions & 11 deletions tests/test_agg_mds_elasticsearch_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ async def test_update_metadata():
[
call(
body={},
doc_type="commons-info",
id="my_commons",
index=AGG_MDS_INFO_INDEX,
),
Expand All @@ -237,7 +236,6 @@ async def test_update_metadata():
"sites": "",
}
},
doc_type="commons",
id="my_id",
index=AGG_MDS_INDEX,
),
Expand Down Expand Up @@ -274,7 +272,6 @@ async def test_update_metadata_to_temp_index():
[
call(
body={},
doc_type="commons-info",
id="my_commons",
index=AGG_MDS_INFO_INDEX_TEMP,
),
Expand All @@ -286,7 +283,6 @@ async def test_update_metadata_to_temp_index():
"sites": "",
}
},
doc_type="commons",
id="my_id",
index=AGG_MDS_INDEX_TEMP,
),
Expand All @@ -303,9 +299,7 @@ async def test_update_global_info():
) as mock_client:
await elasticsearch_dao.update_global_info(key="123", doc={})

mock_client.index.assert_called_with(
index=AGG_MDS_INFO_INDEX, doc_type=AGG_MDS_INFO_TYPE, id="123", body={}
)
mock_client.index.assert_called_with(index=AGG_MDS_INFO_INDEX, id="123", body={})


@pytest.mark.asyncio
Expand All @@ -319,7 +313,7 @@ async def test_update_global_info_to_temp_index():
)

mock_client.index.assert_called_with(
index=AGG_MDS_INFO_INDEX_TEMP, doc_type=AGG_MDS_INFO_TYPE, id="123", body={}
index=AGG_MDS_INFO_INDEX_TEMP, id="123", body={}
)


Expand All @@ -332,7 +326,7 @@ async def test_update_config_info():
await elasticsearch_dao.update_config_info(doc={})

mock_client.index.assert_called_with(
index=AGG_MDS_CONFIG_INDEX, doc_type="_doc", id=AGG_MDS_INDEX, body={}
index=AGG_MDS_CONFIG_INDEX, id=AGG_MDS_INDEX, body={}
)


Expand All @@ -345,7 +339,7 @@ async def test_update_config_info_to_temp_index():
await elasticsearch_dao.update_config_info(doc={}, use_temp_index=True)

mock_client.index.assert_called_with(
index=AGG_MDS_CONFIG_INDEX_TEMP, doc_type="_doc", id=AGG_MDS_INDEX, body={}
index=AGG_MDS_CONFIG_INDEX_TEMP, id=AGG_MDS_INDEX, body={}
)


Expand Down Expand Up @@ -585,7 +579,6 @@ async def test_get_by_guid():
await elasticsearch_dao.get_by_guid("my-commons")
mock_client.get.assert_called_with(
index=AGG_MDS_INDEX,
doc_type="commons",
id="my-commons",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_agg_mds_icpsr_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_get_metadata_icpsr():
respx.get("http://test/ok?verb=GetRecord&metadataPrefix=oai_dc&identifier=64").mock(
return_value=httpx.Response(
status_code=404,
content={},
content="{}",
)
)

Expand Down

0 comments on commit bbe58d9

Please sign in to comment.