Skip to content

Commit 0b68c72

Browse files
committed
use safe_db appproach when testing cqf_library_ext
1 parent 53ea4e6 commit 0b68c72

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

tests/factories.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from app.sdc.getters import (
2+
CQF_LIBRARY_URL,
23
INITIAL_EXPRESSION_URL,
34
ITEM_POPULATION_CONTEXT_URL,
45
LAUNCH_CONTEXT_URL,
@@ -165,3 +166,10 @@ def make_target_structure_map_ext(structure_map_id):
165166
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
166167
"valueCanonical": structure_map_id,
167168
}
169+
170+
171+
def make_cqf_library_ext(canonical):
172+
return {
173+
"url": CQF_LIBRARY_URL,
174+
"valueCanonical": canonical,
175+
}

tests/sdc/test_assemble.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from unittest.mock import AsyncMock, MagicMock
2-
31
import pytest
42
from fhirpy.base.exceptions import OperationOutcome
53

6-
from app.sdc.assemble import assemble
74
from tests.factories import (
85
create_address_questionnaire,
96
create_questionnaire,
107
make_assemble_context_ext,
118
make_assembled_from_ext,
9+
make_cqf_library_ext,
1210
make_initial_expression_ext,
1311
make_item_population_context_ext,
1412
make_launch_context_ext,
@@ -543,7 +541,7 @@ async def test_assemble_reuse_questionnaire(fhir_client, safe_db):
543541

544542

545543
@pytest.mark.asyncio
546-
async def test_validate_assemble_context(fhir_client):
544+
async def test_validate_assemble_context(fhir_client, safe_db):
547545
address = await create_address_questionnaire(fhir_client)
548546

549547
q = await create_questionnaire(
@@ -748,37 +746,40 @@ async def test_assemble_propagates_contained(fhir_client, safe_db):
748746

749747

750748
@pytest.mark.asyncio
751-
async def test_assemble_propagates_cqf_library():
752-
from app.sdc.getters import CQF_LIBRARY_URL
753-
754-
cqf_ext = {"url": CQF_LIBRARY_URL, "valueCanonical": "http://example.org/Library/MyLib"}
755-
sub_fhir = {
756-
"id": "sub-1",
757-
"resourceType": "Questionnaire",
758-
"status": "active",
759-
"extension": [cqf_ext],
760-
"item": [{"type": "string", "linkId": "q1"}],
761-
}
749+
async def test_assemble_propagates_cqf_library(fhir_client, safe_db):
750+
sub = await create_questionnaire(
751+
fhir_client,
752+
{
753+
"status": "active",
754+
"extension": [make_cqf_library_ext("http://example.org/Library/MyLib")],
755+
"item": [{"type": "string", "linkId": "q1"}],
756+
},
757+
)
762758

763-
mock_client = MagicMock()
764-
mock_client.resources.return_value.search.return_value.fetch_all = AsyncMock(
765-
return_value=[sub_fhir]
759+
q = await create_questionnaire(
760+
fhir_client,
761+
{
762+
"status": "active",
763+
"item": [
764+
{
765+
"type": "display",
766+
"linkId": "sub-placeholder",
767+
"text": "Sub questionnaire is not supported",
768+
"extension": [make_sub_questionnaire_ext(sub.id)],
769+
}
770+
],
771+
},
766772
)
767773

768-
fhir_questionnaire = {
769-
"id": "parent-q",
774+
assembled = await q.execute("$assemble", method="get")
775+
del assembled["meta"]
776+
777+
assert assembled == {
770778
"resourceType": "Questionnaire",
771779
"status": "active",
772-
"item": [
773-
{
774-
"type": "display",
775-
"linkId": "sub-placeholder",
776-
"extension": [make_sub_questionnaire_ext("sub-1")],
777-
}
780+
"extension": [
781+
make_cqf_library_ext("http://example.org/Library/MyLib"),
782+
make_assembled_from_ext(q.id),
778783
],
784+
"item": [{"type": "string", "linkId": "q1"}],
779785
}
780-
781-
result = await assemble(mock_client, fhir_questionnaire)
782-
783-
assert cqf_ext in result.get("extension", [])
784-
assert "id" not in result

0 commit comments

Comments
 (0)