Skip to content

Commit

Permalink
Merge pull request #330 from canvas-medical/csande/example-proxy-unit…
Browse files Browse the repository at this point in the history
…-tests

Added unit test for proxy endpoint error check
csande authored Jan 27, 2025
2 parents b99e75c + 0d945f0 commit ea11468
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fhirstarter/fhirstarter.py
Original file line number Diff line number Diff line change
@@ -463,7 +463,7 @@ async def example(value: str) -> Dict[str, Any]:
)(example)

@cachedmethod(
lambda self: self._external_examples_cache,
lambda app: app._external_examples_cache,
key=lambda app, url, allowed_urls: url,
)
async def _example(self, url: str, allowed_urls: Collection[str]) -> Dict[str, Any]:
14 changes: 14 additions & 0 deletions fhirstarter/tests/test_openapi.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
from .. import FHIRProvider, FHIRStarter, InteractionContext
from ..fhir_specification import FHIR_SEQUENCE
from ..fhirstarter import status
from ..testclient import TestClient
from .config import create_test_client_async
from .resources import Appointment, Bundle, Id, Practitioner

@@ -428,3 +429,16 @@ def test_error_examples(
responses[status_code]["content"]["application/fhir+json"]["example"]
== _OPERATION_OUTCOMES[status_code]
)


@pytest.mark.parametrize(
argnames="url",
argvalues=[
"http://hl7.org/fhir/DSTU2/patient-example.json",
"https://hl7.org/fhir/DSTU2/patient-example.json",
],
ids=["no https", "not in allowlist"],
)
def test_example_proxy_error(client_all: TestClient, url: str) -> None:
response = client_all.get(f"/_example?value={url}")
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR

0 comments on commit ea11468

Please sign in to comment.