|
3 | 3 | from unittest import mock
|
4 | 4 |
|
5 | 5 | import pytest
|
| 6 | +from fhirpathpy import evaluate |
6 | 7 |
|
7 | 8 | import main
|
8 | 9 |
|
9 | 10 |
|
10 | 11 | @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 |
38 | 36 |
|
39 | 37 |
|
40 | 38 | @pytest.mark.asyncio()
|
|
0 commit comments