-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_sdk.py
120 lines (99 loc) · 3.59 KB
/
test_sdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import asyncio
import logging
from unittest import mock
import pytest
from fhirpathpy import evaluate
import main
@pytest.mark.asyncio
@pytest.mark.parametrize(
("expression", "expected"),
[
(
"CapabilityStatement.rest.operation.where(definition='http://test.com').count()",
1,
),
(
"CapabilityStatement.rest.operation.where(definition='http://test.com').first().name",
"observation-custom-op",
),
(
"CapabilityStatement.rest.resource.where(type='Observation').operation.where(definition='http://test.com').count()",
1,
),
(
"CapabilityStatement.rest.resource.where(type='Observation').operation.where(definition='http://test.com').first().name",
"observation-custom-op",
),
],
)
async def test_operation_with_compliance_params(aidbox_client, expression, expected):
response = await aidbox_client.execute("fhir/metadata", method="GET")
assert evaluate(response, expression, {})[0] == expected
@pytest.mark.asyncio()
async def test_health_check(client):
resp = await client.get("/health")
assert resp.status == 200
json = await resp.json()
assert json == {"status": "OK"}
@pytest.mark.asyncio()
async def test_live_health_check(client):
resp = await client.get("/live")
assert resp.status == 200
json = await resp.json()
assert json == {"status": "OK"}
@pytest.mark.skip()
async def test_signup_reg_op(client, aidbox):
resp = await aidbox.post("signup/register/21.02.19/testvalue")
assert resp.status == 200
json = await resp.json()
assert json == {
"success": "Ok",
"request": {"date": "21.02.19", "test": "testvalue"},
}
@pytest.mark.skip()
async def test_appointment_sub(client, aidbox):
with mock.patch.object(main, "_appointment_sub") as appointment_sub:
f = asyncio.Future()
f.set_result("")
appointment_sub.return_value = f
sdk = client.server.app["sdk"]
was_appointment_sub_triggered = sdk.was_subscription_triggered("Appointment")
resp = await aidbox.post(
"Appointment",
json={
"status": "proposed",
"participant": [{"status": "accepted"}],
"resourceType": "Appointment",
},
)
assert resp.status == 201
await was_appointment_sub_triggered
event = appointment_sub.call_args_list[0][0][0]
logging.debug("event: %s", event)
expected = {
"resource": {
"status": "proposed",
"participant": [{"status": "accepted"}],
"resourceType": "Appointment",
},
"action": "create",
}
assert expected["resource"].items() <= event["resource"].items()
@pytest.mark.asyncio()
async def test_database_isolation__1(aidbox_client, safe_db):
patients = await aidbox_client.resources("Patient").fetch_all()
assert len(patients) == 2
patient = aidbox_client.resource("Patient")
await patient.save()
patients = await aidbox_client.resources("Patient").fetch_all()
assert len(patients) == 3
@pytest.mark.asyncio()
async def test_database_isolation__2(aidbox_client, safe_db):
patients = await aidbox_client.resources("Patient").fetch_all()
assert len(patients) == 2
patient = aidbox_client.resource("Patient")
await patient.save()
patient = aidbox_client.resource("Patient")
await patient.save()
patients = await aidbox_client.resources("Patient").fetch_all()
assert len(patients) == 4