Skip to content

Commit

Permalink
test: add test for series endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
m0nhawk committed Jan 13, 2025
1 parent 8fb5cb8 commit e73962d
Showing 1 changed file with 109 additions and 6 deletions.
115 changes: 109 additions & 6 deletions tests/test_agg_mds_tcia_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@respx.mock
def test_get_metadata_tcia():
tcia_response = """
tcia_response_study = """
[
{
"StudyInstanceUID": "study_id_1",
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_get_metadata_tcia():
]
"""

field_mappings = {
field_mappings_study = {
"_unique_id": "path:StudyInstanceUID",
"commons": "TCIA",
"study_title": "path:StudyDescription",
Expand All @@ -48,26 +48,94 @@ def test_get_metadata_tcia():
"tags": [],
}

tcia_response_series = """
[
{
"SeriesInstanceUID": "series_id_1",
"StudyInstanceUID": "study_id_1",
"Modality": "A",
"ProtocolName": "",
"SeriesDate": "1970-01-01 00:00:00.0",
"SeriesDescription": "",
"SeriesNumber": 1,
"Collection": "Collection1",
"PatientID": "",
"Manufacturer": "",
"ManufacturerModelName": "",
"ImageCount": 10,
"TimeStamp": "1970-01-01 00:00:00.0",
"LicenseName": "",
"LicenseURI": "",
"CollectionURI": "",
"FileSize": 100,
"DateReleased": "1970-01-01 00:00:00.0",
"StudyDesc": "",
"StudyDate": "1970-01-01 00:00:00.0",
"ThirdPartyAnalysis": ""
},
{
"SeriesInstanceUID": "series_id_2",
"StudyInstanceUID": "study_id_2",
"Modality": "B",
"ProtocolName": "",
"SeriesDate": "1970-01-01 10:00:00.0",
"SeriesDescription": "",
"BodyPartExamined": "",
"SeriesNumber": 2,
"Collection": "Collection2",
"PatientID": "",
"Manufacturer": "",
"ManufacturerModelName": "",
"SoftwareVersions": "",
"ImageCount": 20,
"TimeStamp": "1970-01-01 10:00:00.0",
"LicenseName": "",
"LicenseURI": "",
"CollectionURI": "",
"FileSize": 200,
"DateReleased": "1970-01-01 10:00:00.0",
"StudyDesc": "",
"StudyDate": "1970-01-01 10:00:00.0",
"ThirdPartyAnalysis": ""
}
]
"""

field_mappings_series = {
"_unique_id": "path:SeriesInstanceUID",
"study_id": "path:StudyInstanceUID",
"commons": "TCIA",
"study_title": "path:SeriesDescription",
"program_name": "path:Collection",
"image_count": "path:ImageCount",
"description": "",
"tags": [],
}

respx.get("http://test/ok").mock(side_effect=httpx.HTTPError)
assert (
get_metadata("tcia", "http://test/ok", filters=None, mappings=field_mappings)
get_metadata(
"tcia", "http://test/ok", filters=None, mappings=field_mappings_study
)
== {}
)

respx.get("http://test/ok").mock(side_effect=Exception)
assert (
get_metadata("tcia", "http://test/ok", filters=None, mappings=field_mappings)
get_metadata(
"tcia", "http://test/ok", filters=None, mappings=field_mappings_study
)
== {}
)

respx.get(
"http://test/ok",
).mock(return_value=httpx.Response(status_code=200, content=tcia_response))
).mock(return_value=httpx.Response(status_code=200, content=tcia_response_study))

filters = {"size": 5}

assert get_metadata(
"tcia", "http://test/ok", filters=filters, mappings=field_mappings
"tcia", "http://test/ok", filters=filters, mappings=field_mappings_study
) == {
"study_id_1": {
"_guid_type": "discovery_metadata",
Expand All @@ -92,3 +160,38 @@ def test_get_metadata_tcia():
},
},
}

respx.get(
"http://test/ok",
).mock(return_value=httpx.Response(status_code=200, content=tcia_response_series))

assert get_metadata(
"tcia", "http://test/ok", filters=filters, mappings=field_mappings_series
) == {
"series_id_1": {
"_guid_type": "discovery_metadata",
"gen3_discovery": {
"_unique_id": "series_id_1",
"study_id": "study_id_1",
"commons": "TCIA",
"study_title": "",
"program_name": "Collection1",
"image_count": "10",
"description": "",
"tags": [{"category": "program_name", "name": "Collection1"}],
},
},
"series_id_2": {
"_guid_type": "discovery_metadata",
"gen3_discovery": {
"_unique_id": "series_id_2",
"study_id": "study_id_2",
"commons": "TCIA",
"study_title": "",
"program_name": "Collection2",
"image_count": "20",
"description": "",
"tags": [{"category": "program_name", "name": "Collection2"}],
},
},
}

0 comments on commit e73962d

Please sign in to comment.