Skip to content

Commit 1653b0e

Browse files
authored
Merge pull request #83 from zakharych/fix-drop-before-all
Fix: Test isolation for resources with "history" in name
2 parents b0166be + be57252 commit 1653b0e

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

aidbox_python_sdk/db_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
FOR e IN (
2828
SELECT table_name
2929
FROM information_schema.columns
30-
WHERE column_name = 'txid' AND table_schema = 'public' AND table_name NOT LIKE '%_history'
30+
WHERE column_name = 'txid' AND table_schema = 'public' AND table_name NOT LIKE '%\\_history' ESCAPE '\\'
3131
) LOOP
3232
EXECUTE 'DELETE FROM "' || e.table_name || '" WHERE txid > ' || $1 ;
3333
END LOOP;

run_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
if [ -f "envs/aidbox" ]; then
4-
export `cat envs/aidbox`
3+
if [ -f ".env" ]; then
4+
export `cat .env`
55
fi
66

77
if [ -z "${AIDBOX_LICENSE}" ]; then

tests/test_sdk.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,63 @@ async def test_database_isolation__2(aidbox_client, safe_db):
118118

119119
patients = await aidbox_client.resources("Patient").fetch_all()
120120
assert len(patients) == 4
121+
122+
123+
@pytest.mark.asyncio()
124+
async def test_database_isolation_with_history_in_name__1(aidbox_client, safe_db):
125+
resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all()
126+
assert len(resources) == 0
127+
128+
resource = aidbox_client.resource(
129+
"FamilyMemberHistory",
130+
status="completed",
131+
patient={
132+
"identifier": {"system": "http://example.org/test-patients", "value": "test-patient-1"}
133+
},
134+
relationship={
135+
"coding": [
136+
{"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "FTH"}
137+
]
138+
},
139+
)
140+
await resource.save()
141+
142+
resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all()
143+
assert len(resources) == 1
144+
145+
146+
@pytest.mark.asyncio()
147+
async def test_database_isolation_with_history_in_name__2(aidbox_client, safe_db):
148+
resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all()
149+
assert len(resources) == 0
150+
151+
resource1 = aidbox_client.resource(
152+
"FamilyMemberHistory",
153+
status="completed",
154+
patient={
155+
"identifier": {"system": "http://example.org/test-patients", "value": "test-patient-1"}
156+
},
157+
relationship={
158+
"coding": [
159+
{"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "FTH"}
160+
]
161+
},
162+
)
163+
await resource1.save()
164+
165+
resource2 = aidbox_client.resource(
166+
"FamilyMemberHistory",
167+
status="completed",
168+
patient={
169+
"identifier": {"system": "http://example.org/test-patients", "value": "test-patient-2"}
170+
},
171+
relationship={
172+
"coding": [
173+
{"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "MTH"}
174+
]
175+
},
176+
)
177+
await resource2.save()
178+
179+
resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all()
180+
assert len(resources) == 2

0 commit comments

Comments
 (0)