From bce3bf15427f9fe4f2323e8f18c0d399d4114c1a Mon Sep 17 00:00:00 2001 From: Aleksei Zakharov Date: Mon, 17 Nov 2025 22:05:47 -0300 Subject: [PATCH 1/2] Fix drop_before_all --- aidbox_python_sdk/db_migrations.py | 2 +- tests/test_sdk.py | 60 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/aidbox_python_sdk/db_migrations.py b/aidbox_python_sdk/db_migrations.py index 6c389bf..fbb47be 100644 --- a/aidbox_python_sdk/db_migrations.py +++ b/aidbox_python_sdk/db_migrations.py @@ -27,7 +27,7 @@ FOR e IN ( SELECT table_name FROM information_schema.columns - WHERE column_name = 'txid' AND table_schema = 'public' AND table_name NOT LIKE '%_history' + WHERE column_name = 'txid' AND table_schema = 'public' AND table_name NOT LIKE '%\\_history' ESCAPE '\\' ) LOOP EXECUTE 'DELETE FROM "' || e.table_name || '" WHERE txid > ' || $1 ; END LOOP; diff --git a/tests/test_sdk.py b/tests/test_sdk.py index 88ab8f1..8da42a3 100644 --- a/tests/test_sdk.py +++ b/tests/test_sdk.py @@ -118,3 +118,63 @@ async def test_database_isolation__2(aidbox_client, safe_db): patients = await aidbox_client.resources("Patient").fetch_all() assert len(patients) == 4 + + +@pytest.mark.asyncio() +async def test_database_isolation_with_history_in_name__1(aidbox_client, safe_db): + resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all() + assert len(resources) == 0 + + resource = aidbox_client.resource( + "FamilyMemberHistory", + status="completed", + patient={ + "identifier": {"system": "http://example.org/test-patients", "value": "test-patient-1"} + }, + relationship={ + "coding": [ + {"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "FTH"} + ] + }, + ) + await resource.save() + + resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all() + assert len(resources) == 1 + + +@pytest.mark.asyncio() +async def test_database_isolation_with_history_in_name__2(aidbox_client, safe_db): + resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all() + assert len(resources) == 0 + + resource1 = aidbox_client.resource( + "FamilyMemberHistory", + status="completed", + patient={ + "identifier": {"system": "http://example.org/test-patients", "value": "test-patient-1"} + }, + relationship={ + "coding": [ + {"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "FTH"} + ] + }, + ) + await resource1.save() + + resource2 = aidbox_client.resource( + "FamilyMemberHistory", + status="completed", + patient={ + "identifier": {"system": "http://example.org/test-patients", "value": "test-patient-2"} + }, + relationship={ + "coding": [ + {"system": "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "code": "MTH"} + ] + }, + ) + await resource2.save() + + resources = await aidbox_client.resources("FamilyMemberHistory").fetch_all() + assert len(resources) == 2 From be572528d0dc06796950cf246c3afa419cc610a9 Mon Sep 17 00:00:00 2001 From: Aleksei Zakharov Date: Mon, 17 Nov 2025 22:06:11 -0300 Subject: [PATCH 2/2] update run_test.sh --- run_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_test.sh b/run_test.sh index e55cf59..91e77a6 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1,7 +1,7 @@ #!/bin/sh -if [ -f "envs/aidbox" ]; then - export `cat envs/aidbox` +if [ -f ".env" ]; then + export `cat .env` fi if [ -z "${AIDBOX_LICENSE}" ]; then