Skip to content

Commit e0711ab

Browse files
author
alex-omophub
committed
Integration tests
1 parent e8cb1d6 commit e0711ab

15 files changed

Lines changed: 80 additions & 123 deletions

src/omophub/resources/mappings.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def get(
4141
if vocab_release:
4242
params["vocab_release"] = vocab_release
4343

44-
return self._request.get(f"/concepts/{concept_id}/mappings", params=params or None)
44+
return self._request.get(
45+
f"/concepts/{concept_id}/mappings", params=params or None
46+
)
4547

4648
def map(
4749
self,
@@ -77,7 +79,9 @@ def map(
7779
if vocab_release:
7880
params["vocab_release"] = vocab_release
7981

80-
return self._request.post("/concepts/map", json_data=body, params=params or None)
82+
return self._request.post(
83+
"/concepts/map", json_data=body, params=params or None
84+
)
8185

8286

8387
class AsyncMappings:
@@ -151,4 +155,6 @@ async def map(
151155
if vocab_release:
152156
params["vocab_release"] = vocab_release
153157

154-
return await self._request.post("/concepts/map", json_data=body, params=params or None)
158+
return await self._request.post(
159+
"/concepts/map", json_data=body, params=params or None
160+
)

tests/integration/test_concepts.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_batch_concepts(self, integration_client: OMOPHub) -> None:
6161

6262
def test_suggest_concepts(self, integration_client: OMOPHub) -> None:
6363
"""Get concept suggestions."""
64-
result = integration_client.concepts.suggest("diabetes", limit=5)
64+
result = integration_client.concepts.suggest("diabetes", page_size=5)
6565

6666
# Result is a list of concept objects with concept_name field
6767
suggestions = extract_data(result, "suggestions")
@@ -81,9 +81,9 @@ def test_suggest_concepts_with_filters(self, integration_client: OMOPHub) -> Non
8181
"""Get concept suggestions with vocabulary filter."""
8282
result = integration_client.concepts.suggest(
8383
"aspirin",
84-
vocabulary="RxNorm",
85-
domain="Drug",
86-
limit=10,
84+
vocabulary_ids=["RxNorm"],
85+
domain_ids=["Drug"],
86+
page_size=10,
8787
)
8888

8989
# Should get at least one result or empty list
@@ -94,7 +94,7 @@ def test_get_related_concepts(self, integration_client: OMOPHub) -> None:
9494
"""Get related concepts."""
9595
result = integration_client.concepts.related(
9696
DIABETES_CONCEPT_ID,
97-
max_results=10,
97+
page_size=10,
9898
)
9999

100100
# Should have related_concepts key
@@ -105,7 +105,6 @@ def test_get_concept_relationships(self, integration_client: OMOPHub) -> None:
105105
"""Get concept relationships."""
106106
result = integration_client.concepts.relationships(
107107
DIABETES_CONCEPT_ID,
108-
page_size=20,
109108
)
110109

111110
# Should have relationships

tests/integration/test_mappings.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,17 @@ def test_get_mappings_to_icd10(self, integration_client: OMOPHub) -> None:
2727
"""Get ICD-10 mappings for SNOMED concept."""
2828
result = integration_client.mappings.get(
2929
DIABETES_CONCEPT_ID,
30-
target_vocabularies=["ICD10CM"],
31-
direction="outgoing",
30+
target_vocabulary="ICD10CM",
3231
)
3332

3433
mappings = extract_data(result, "mappings")
3534
assert isinstance(mappings, list)
3635

3736
def test_get_mappings_with_options(self, integration_client: OMOPHub) -> None:
38-
"""Get mappings with quality and context options."""
37+
"""Get mappings with include_invalid option."""
3938
result = integration_client.mappings.get(
4039
DIABETES_CONCEPT_ID,
41-
include_mapping_quality=True,
42-
include_context=True,
43-
page_size=50,
40+
include_invalid=True,
4441
)
4542

4643
mappings = extract_data(result, "mappings")

tests/integration/test_relationships.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_get_relationships_with_type_filter(
2929
"""Get relationships filtered by type."""
3030
result = integration_client.relationships.get(
3131
DIABETES_CONCEPT_ID,
32-
relationship_type="Is a",
32+
relationship_ids=["Is a"],
3333
page_size=50,
3434
)
3535

@@ -42,7 +42,7 @@ def test_get_relationships_with_vocabulary_filter(
4242
"""Get relationships filtered by target vocabulary."""
4343
result = integration_client.relationships.get(
4444
DIABETES_CONCEPT_ID,
45-
target_vocabulary="SNOMED",
45+
vocabulary_ids=["SNOMED"],
4646
page_size=100,
4747
)
4848

@@ -60,25 +60,17 @@ def test_get_relationship_types(self, integration_client: OMOPHub) -> None:
6060
def test_get_relationship_types_with_filters(
6161
self, integration_client: OMOPHub
6262
) -> None:
63-
"""Get relationship types with filters."""
63+
"""Get relationship types with pagination."""
6464
result = integration_client.relationships.types(
65-
vocabulary_ids=["SNOMED"],
66-
include_reverse=True,
67-
include_usage_stats=True,
6865
page_size=50,
6966
)
7067

7168
types = result.get("relationship_types", result)
7269
assert isinstance(types, list)
7370

74-
def test_get_relationship_types_by_category(
75-
self, integration_client: OMOPHub
76-
) -> None:
77-
"""Get relationship types by category."""
78-
result = integration_client.relationships.types(
79-
category="hierarchy",
80-
standard_only=True,
81-
)
71+
def test_get_relationship_types_basic(self, integration_client: OMOPHub) -> None:
72+
"""Get relationship types with default settings."""
73+
result = integration_client.relationships.types()
8274

8375
types = result.get("relationship_types", result)
8476
assert isinstance(types, list)

tests/integration/test_vocabularies.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ def test_get_vocabulary(self, integration_client: OMOPHub) -> None:
4848
assert vocab["vocabulary_id"] == "SNOMED"
4949
assert "vocabulary_name" in vocab
5050

51-
def test_get_vocabulary_with_options(self, integration_client: OMOPHub) -> None:
52-
"""Get vocabulary with stats and domains."""
53-
vocab = integration_client.vocabularies.get(
54-
"SNOMED",
55-
include_stats=True,
56-
include_domains=True,
57-
)
51+
def test_get_vocabulary_basic(self, integration_client: OMOPHub) -> None:
52+
"""Get vocabulary (use stats() method for statistics)."""
53+
vocab = integration_client.vocabularies.get("SNOMED")
5854

5955
assert vocab["vocabulary_id"] == "SNOMED"
6056
assert "vocabulary_name" in vocab

tests/unit/resources/test_concepts.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ def test_batch_concepts_with_options(
8787
) -> None:
8888
"""Test batch concepts with all options."""
8989
route = respx.post(f"{base_url}/concepts/batch").mock(
90-
return_value=Response(
91-
200, json={"success": True, "data": {"concepts": []}}
92-
)
90+
return_value=Response(200, json={"success": True, "data": {"concepts": []}})
9391
)
9492

9593
sync_client.concepts.batch(
@@ -312,9 +310,7 @@ async def test_async_batch_concepts_with_options(
312310
) -> None:
313311
"""Test async batch with options."""
314312
route = respx.post(f"{base_url}/concepts/batch").mock(
315-
return_value=Response(
316-
200, json={"success": True, "data": {"concepts": []}}
317-
)
313+
return_value=Response(200, json={"success": True, "data": {"concepts": []}})
318314
)
319315

320316
await async_client.concepts.batch(

tests/unit/resources/test_domains.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def test_list_domains(self, sync_client: OMOPHub, base_url: str) -> None:
3737
assert "domains" in result
3838

3939
@respx.mock
40-
def test_list_domains_with_stats(
41-
self, sync_client: OMOPHub, base_url: str
42-
) -> None:
40+
def test_list_domains_with_stats(self, sync_client: OMOPHub, base_url: str) -> None:
4341
"""Test listing domains with include_stats option."""
4442
route = respx.get(f"{base_url}/domains").mock(
4543
return_value=Response(
@@ -72,9 +70,7 @@ def test_list_domains_without_stats(
7270
) -> None:
7371
"""Test listing domains without stats (default)."""
7472
route = respx.get(f"{base_url}/domains").mock(
75-
return_value=Response(
76-
200, json={"success": True, "data": {"domains": []}}
77-
)
73+
return_value=Response(200, json={"success": True, "data": {"domains": []}})
7874
)
7975

8076
sync_client.domains.list()
@@ -128,9 +124,7 @@ async def test_async_list_domains(
128124
) -> None:
129125
"""Test async listing domains."""
130126
respx.get(f"{base_url}/domains").mock(
131-
return_value=Response(
132-
200, json={"success": True, "data": {"domains": []}}
133-
)
127+
return_value=Response(200, json={"success": True, "data": {"domains": []}})
134128
)
135129

136130
result = await async_client.domains.list()
@@ -143,9 +137,7 @@ async def test_async_list_domains_with_stats(
143137
) -> None:
144138
"""Test async listing domains with include_stats."""
145139
route = respx.get(f"{base_url}/domains").mock(
146-
return_value=Response(
147-
200, json={"success": True, "data": {"domains": []}}
148-
)
140+
return_value=Response(200, json={"success": True, "data": {"domains": []}})
149141
)
150142

151143
await async_client.domains.list(include_stats=True)
@@ -160,9 +152,7 @@ async def test_async_get_domain_concepts(
160152
) -> None:
161153
"""Test async getting domain concepts."""
162154
route = respx.get(f"{base_url}/domains/Condition/concepts").mock(
163-
return_value=Response(
164-
200, json={"success": True, "data": {"concepts": []}}
165-
)
155+
return_value=Response(200, json={"success": True, "data": {"concepts": []}})
166156
)
167157

168158
await async_client.domains.concepts(

tests/unit/resources/test_hierarchy.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ def test_get_ancestors(self, sync_client: OMOPHub, base_url: str) -> None:
2323
"success": True,
2424
"data": {
2525
"ancestors": [
26-
{"concept_id": 201820, "concept_name": "Diabetes mellitus", "level": 1},
27-
{"concept_id": 4000, "concept_name": "Endocrine disorder", "level": 2},
26+
{
27+
"concept_id": 201820,
28+
"concept_name": "Diabetes mellitus",
29+
"level": 1,
30+
},
31+
{
32+
"concept_id": 4000,
33+
"concept_name": "Endocrine disorder",
34+
"level": 2,
35+
},
2836
],
2937
"summary": {"total_ancestors": 2, "max_level": 2},
3038
},
@@ -37,7 +45,9 @@ def test_get_ancestors(self, sync_client: OMOPHub, base_url: str) -> None:
3745
assert "ancestors" in result
3846

3947
@respx.mock
40-
def test_get_ancestors_with_options(self, sync_client: OMOPHub, base_url: str) -> None:
48+
def test_get_ancestors_with_options(
49+
self, sync_client: OMOPHub, base_url: str
50+
) -> None:
4151
"""Test getting ancestors with all options."""
4252
route = respx.get(f"{base_url}/concepts/201826/ancestors").mock(
4353
return_value=Response(
@@ -139,7 +149,6 @@ def test_get_descendants_max_levels_capped(
139149
assert "max_levels=20" in url_str
140150

141151

142-
143152
class TestAsyncHierarchyResource:
144153
"""Tests for the asynchronous AsyncHierarchy resource."""
145154

@@ -228,4 +237,3 @@ async def test_async_get_descendants_with_filters(
228237
assert "include_invalid=true" in url_str
229238
assert "max_levels=5" in url_str
230239
assert "include_paths=true" in url_str
231-

tests/unit/resources/test_mappings.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def test_get_mappings_with_filters(
4646
) -> None:
4747
"""Test getting mappings with filter options."""
4848
route = respx.get(f"{base_url}/concepts/201826/mappings").mock(
49-
return_value=Response(
50-
200, json={"success": True, "data": {"mappings": []}}
51-
)
49+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
5250
)
5351

5452
sync_client.mappings.get(
@@ -95,9 +93,7 @@ def test_map_concepts_with_options(
9593
) -> None:
9694
"""Test mapping concepts with additional options."""
9795
route = respx.post(f"{base_url}/concepts/map").mock(
98-
return_value=Response(
99-
200, json={"success": True, "data": {"mappings": []}}
100-
)
96+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
10197
)
10298

10399
sync_client.mappings.map(
@@ -114,7 +110,6 @@ def test_map_concepts_with_options(
114110
assert route.calls[0].request.content
115111

116112

117-
118113
class TestAsyncMappingsResource:
119114
"""Tests for the asynchronous AsyncMappings resource."""
120115

@@ -125,9 +120,7 @@ async def test_async_get_mappings(
125120
) -> None:
126121
"""Test async getting mappings."""
127122
respx.get(f"{base_url}/concepts/201826/mappings").mock(
128-
return_value=Response(
129-
200, json={"success": True, "data": {"mappings": []}}
130-
)
123+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
131124
)
132125

133126
result = await async_client.mappings.get(201826)
@@ -140,9 +133,7 @@ async def test_async_get_mappings_with_filters(
140133
) -> None:
141134
"""Test async mappings with filters."""
142135
route = respx.get(f"{base_url}/concepts/201826/mappings").mock(
143-
return_value=Response(
144-
200, json={"success": True, "data": {"mappings": []}}
145-
)
136+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
146137
)
147138

148139
await async_client.mappings.get(
@@ -162,9 +153,7 @@ async def test_async_map_concepts(
162153
) -> None:
163154
"""Test async mapping concepts."""
164155
respx.post(f"{base_url}/concepts/map").mock(
165-
return_value=Response(
166-
200, json={"success": True, "data": {"mappings": []}}
167-
)
156+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
168157
)
169158

170159
result = await async_client.mappings.map(
@@ -181,9 +170,7 @@ async def test_async_map_concepts_with_options(
181170
) -> None:
182171
"""Test async mapping with options."""
183172
route = respx.post(f"{base_url}/concepts/map").mock(
184-
return_value=Response(
185-
200, json={"success": True, "data": {"mappings": []}}
186-
)
173+
return_value=Response(200, json={"success": True, "data": {"mappings": []}})
187174
)
188175

189176
await async_client.mappings.map(
@@ -194,4 +181,3 @@ async def test_async_map_concepts_with_options(
194181
)
195182

196183
assert route.calls[0].request.content
197-

0 commit comments

Comments
 (0)