Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
craigrbarnes committed Jan 23, 2025
1 parent bb752a5 commit de4ce79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/mds/agg_mds/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ def getRemoteDataAsJson(self, **kwargs) -> Dict:
except httpx.TimeoutException as exc:
logger.error(f"An timeout error occurred while requesting {mds_url}.")
raise
except httpx.HTTPError as exc:
except httpx.HTTPStatusError as exc:
logger.error(
f"An HTTP error {exc.response.status_code if exc.response is not None else ''} occurred while requesting {exc.request.url}. Returning {len(results['results'])} results"
)
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 @@ -1097,7 +1097,7 @@ def test_get_metadata_clinicaltrials():

respx.get(
"http://test/ok?expr=should+error+timeout&fmt=json&min_rnk=1&max_rnk=1"
).mock(side_effect=httpx.HTTPError("This is a HTTP Error"))
).mock(side_effect=httpx.TimeoutException("This is a HTTP Error"))

assert (
get_metadata(
Expand Down
38 changes: 15 additions & 23 deletions tests/test_agg_mds_pdc_subject_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ def test_get_metadata_pdc_subject():
json_response = r"""
{
"data": {
"getPaginatedUICase": {
"getPaginatedUICase" : { "total": 2 },
"getPaginatedUIClinical": {
"total": 2,
"uiCases": [
"uiClinical": [
{
"aliquot_id": "test_aliquot_id_0",
"sample_id": "test_sample_id_0",
Expand Down Expand Up @@ -260,16 +261,14 @@ def test_get_metadata_pdc_subject():
"getAll": False,
}

respx.post(
"http://test/ok",
json={"query": query, "variables": variables},
).mock(return_value=httpx.Response(status_code=200, content=json_response))
respx.post("http://test/ok").mock(
return_value=httpx.Response(status_code=200, content=json_response)
)

filters = {"size": 5}

assert (
get_metadata("pdcsubject", None, filters=filters, mappings=field_mappings) == {}
)
results = get_metadata("pdcsubject", None, filters=filters, mappings=field_mappings)
assert results == {}

expected_result = {
"test_case_id_0": {
Expand Down Expand Up @@ -386,12 +385,10 @@ def test_get_metadata_pdc_subject():
},
}

assert (
get_metadata(
"pdcsubject", "http://test/ok", filters=filters, mappings=field_mappings
)
== expected_result
results = get_metadata(
"pdcsubject", "http://test/ok", filters=filters, mappings=field_mappings
)
assert results == expected_result

expected_result = {
"test_case_id_0": {
Expand Down Expand Up @@ -523,7 +520,6 @@ def test_get_metadata_pdc_subject():

respx.post(
"http://test/ok",
json={"query": query, "variables": variables},
).mock(side_effect=httpx.TimeoutException)

assert (
Expand All @@ -533,10 +529,9 @@ def test_get_metadata_pdc_subject():
== {}
)

respx.post(
"http://test/ok",
json={"query": query, "variables": variables},
).mock(side_effect=httpx.HTTPError("This is a HTTP Error"))
respx.post("http://test/ok").mock(
side_effect=httpx.HTTPError("This is a HTTP Error")
)

assert (
get_metadata(
Expand All @@ -545,10 +540,7 @@ def test_get_metadata_pdc_subject():
== {}
)

respx.post(
"http://test/ok",
json={"query": query, "variables": variables},
).mock(side_effect=Exception)
respx.post("http://test/ok").mock(side_effect=Exception)

assert (
get_metadata(
Expand Down

0 comments on commit de4ce79

Please sign in to comment.