|
1 | | -from unittest.mock import AsyncMock, MagicMock |
2 | | - |
3 | 1 | import pytest |
4 | 2 | from fhirpy.base.exceptions import OperationOutcome |
5 | 3 |
|
6 | | -from app.sdc.assemble import assemble |
7 | 4 | from tests.factories import ( |
8 | 5 | create_address_questionnaire, |
9 | 6 | create_questionnaire, |
10 | 7 | make_assemble_context_ext, |
11 | 8 | make_assembled_from_ext, |
| 9 | + make_cqf_library_ext, |
12 | 10 | make_initial_expression_ext, |
13 | 11 | make_item_population_context_ext, |
14 | 12 | make_launch_context_ext, |
@@ -543,7 +541,7 @@ async def test_assemble_reuse_questionnaire(fhir_client, safe_db): |
543 | 541 |
|
544 | 542 |
|
545 | 543 | @pytest.mark.asyncio |
546 | | -async def test_validate_assemble_context(fhir_client): |
| 544 | +async def test_validate_assemble_context(fhir_client, safe_db): |
547 | 545 | address = await create_address_questionnaire(fhir_client) |
548 | 546 |
|
549 | 547 | q = await create_questionnaire( |
@@ -748,37 +746,40 @@ async def test_assemble_propagates_contained(fhir_client, safe_db): |
748 | 746 |
|
749 | 747 |
|
750 | 748 | @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 | + ) |
762 | 758 |
|
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 | + }, |
766 | 772 | ) |
767 | 773 |
|
768 | | - fhir_questionnaire = { |
769 | | - "id": "parent-q", |
| 774 | + assembled = await q.execute("$assemble", method="get") |
| 775 | + del assembled["meta"] |
| 776 | + |
| 777 | + assert assembled == { |
770 | 778 | "resourceType": "Questionnaire", |
771 | 779 | "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), |
778 | 783 | ], |
| 784 | + "item": [{"type": "string", "linkId": "q1"}], |
779 | 785 | } |
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