Skip to content

Commit adbaa65

Browse files
committed
Add tests for CapabilityStatement
Ref: #69
1 parent 7467221 commit adbaa65

File tree

4 files changed

+71
-30
lines changed

4 files changed

+71
-30
lines changed

Pipfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aiohttp = "~=3.10.2"
88
sqlalchemy = "~=2.0.5"
99
fhirpy = "~=1.3.0"
1010
jsonschema = "~=4.17.3"
11+
fhirpathpy = "==2.0.0"
1112

1213
[dev-packages]
1314
pytest-aiohttp = "~=1.0.4"
@@ -20,8 +21,6 @@ autohooks-plugin-ruff = "~=23.11.0"
2021
autohooks-plugin-black = "~=23.7.0"
2122
coloredlogs = "*"
2223
ruff = "*"
23-
24-
# dependencies for python 3.8
2524
exceptiongroup = "~=1.2.1"
2625
tomli = "~=2.0.1"
2726
async-timeout = "~=4.0.3"

Pipfile.lock

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,15 @@ async def db_tests(request):
160160
result = await db.alchemy(statement)
161161
logging.debug("Result:\n%s", result)
162162
return web.json_response({})
163+
164+
165+
@sdk.operation(
166+
["POST"],
167+
["Observation", "observation-custom-op"],
168+
compliance={
169+
"fhirCode": "observation-custom-op",
170+
"fhirUrl": "http://test.com",
171+
"fhirResource": ["Observation"],
172+
})
173+
async def observation_custom_op(operation, request):
174+
return {"message": "Observation custom operation response"}

tests/test_sdk.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,36 @@
33
from unittest import mock
44

55
import pytest
6+
from fhirpathpy import evaluate
67

78
import main
89

910

1011
@pytest.mark.asyncio
11-
async def test_operation_with_compliance_params(client):
12-
sdk = client.server.app["sdk"]
13-
14-
compliance = {
15-
"fhirCode": "observation-custom-op",
16-
"fhirUrl": "http://test.com",
17-
"fhirResource": ["Observation"],
18-
}
19-
20-
@sdk.operation(["POST"], ["Observation", "observation-custom-op"], compliance=compliance)
21-
async def observation_custom_op(operation, request):
22-
return {"message": "Observation custom operation response"}
23-
24-
25-
operation_id = "POST.tests.test_sdk.observation_custom_op.Observation_observation-custom-op"
26-
27-
assert operation_id in sdk._operations
28-
29-
assert sdk._operations[operation_id]["fhirCode"] == "observation-custom-op"
30-
assert sdk._operations[operation_id]["fhirUrl"] == "http://test.com"
31-
assert sdk._operations[operation_id]["fhirResource"] == ["Observation"]
32-
33-
handler = sdk.get_operation_handler(operation_id)
34-
assert handler is not None
35-
36-
response = await handler({}, {})
37-
assert response == {"message": "Observation custom operation response"}
12+
@pytest.mark.parametrize(
13+
("expression", "expected"),
14+
[
15+
(
16+
"CapabilityStatement.rest.operation.where(definition='http://test.com').count()",
17+
1,
18+
),
19+
(
20+
"CapabilityStatement.rest.operation.where(definition='http://test.com').first().name",
21+
"observation-custom-op",
22+
),
23+
(
24+
"CapabilityStatement.rest.resource.where(type='Observation').operation.where(definition='http://test.com').count()",
25+
1,
26+
),
27+
(
28+
"CapabilityStatement.rest.resource.where(type='Observation').operation.where(definition='http://test.com').first().name",
29+
"observation-custom-op",
30+
),
31+
],
32+
)
33+
async def test_operation_with_compliance_params(aidbox_client, expression, expected):
34+
response = await aidbox_client.execute("fhir/metadata", method="GET")
35+
assert evaluate(response, expression, {})[0] == expected
3836

3937

4038
@pytest.mark.asyncio()

0 commit comments

Comments
 (0)