Skip to content

Commit 367d573

Browse files
[CDAPI-100]: Fixes to allow schema, accpetance and status endpoints to work remotely
1 parent d61c078 commit 367d573

5 files changed

Lines changed: 42 additions & 10 deletions

File tree

pathology-api/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ paths:
3232
enum:
3333
- Bundle
3434
description: FHIR resource type
35+
meta:
36+
$ref: "#/components/schemas/meta"
3537
type:
3638
type: string
3739
enum:
@@ -75,6 +77,8 @@ paths:
7577
- PractitionerRole
7678
- Organization
7779
example: Patient
80+
meta:
81+
$ref: "#/components/schemas/meta"
7882
responses:
7983
'200':
8084
description: Successful response
@@ -147,6 +151,15 @@ components:
147151
app-level3:
148152
$ref: https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level3
149153
schemas:
154+
meta:
155+
type: object
156+
properties:
157+
profile:
158+
type: array
159+
items:
160+
type: string
161+
versionId:
162+
type: string
150163
CompositionResource:
151164
type: object
152165
required:
@@ -159,6 +172,8 @@ components:
159172
enum:
160173
- Composition
161174
example: Composition
175+
meta:
176+
$ref: "#/components/schemas/meta"
162177
subject:
163178
type: object
164179
required:

pathology-api/tests/acceptance/features/bundle_endpoint.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@status_merged_auth_headers
12
Feature: pathology Bundle API
23
As an API consumer
34
I want to interact with the pathology API

pathology-api/tests/acceptance/steps/bundle_endpoint_steps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ def step_api_is_running(client: Client) -> None:
1717
client: Test client from conftest.py
1818
"""
1919
response = client.send_without_payload(path="_status", request_method="GET")
20-
assert response.text == "OK"
20+
2121
assert response.status_code == 200
22+
assert response.text.__contains__('"outcome":"OK"')
2223

2324

2425
@when("I send a valid Bundle to the Pathology API")

pathology-api/tests/conftest.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _send(
161161
)
162162

163163

164-
@pytest.fixture
164+
@pytest.fixture(scope="module")
165165
def base_url() -> str:
166166
"""Retrieves the base URL of the currently deployed application."""
167167
return _fetch_env_variable("BASE_URL", str)
@@ -180,16 +180,30 @@ def client(request: pytest.FixtureRequest, base_url: str) -> Client:
180180
if env == "local":
181181
return LocalClient(lambda_url=base_url)
182182
elif env == "remote":
183-
auth_headers = request.getfixturevalue("nhsd_apim_auth_headers")
184-
proxy_url = request.getfixturevalue("nhsd_apim_proxy_url")
185-
return RemoteClient(
186-
api_url=proxy_url,
187-
auth_headers=auth_headers,
188-
)
183+
return _create_remote_client(request)
189184
else:
190185
raise ValueError(f"Unknown env: {env}")
191186

192187

188+
def _create_remote_client(request: pytest.FixtureRequest) -> RemoteClient:
189+
"""Create a RemoteClient with appropriate auth headers based on test markers."""
190+
proxy_url = request.getfixturevalue("nhsd_apim_proxy_url")
191+
default_auth_headers = request.getfixturevalue("nhsd_apim_auth_headers")
192+
193+
has_status_marker = request.node.get_closest_marker("status_auth_headers")
194+
has_merged_marker = request.node.get_closest_marker("status_merged_auth_headers")
195+
196+
if has_merged_marker:
197+
status_headers = request.getfixturevalue("status_endpoint_auth_headers")
198+
auth_headers = default_auth_headers | status_headers
199+
elif has_status_marker:
200+
auth_headers = request.getfixturevalue("status_endpoint_auth_headers")
201+
else:
202+
auth_headers = default_auth_headers
203+
204+
return RemoteClient(api_url=proxy_url, auth_headers=auth_headers)
205+
206+
193207
def _fetch_env_variable[T](name: str, _: type[T]) -> T:
194208
value = os.getenv(name)
195209
if not value:

pathology-api/tests/integration/test_endpoints.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ def test_invalid_payload_returns_error(
246246

247247

248248
class TestStatusEndpoint:
249+
@pytest.mark.status_auth_headers
249250
def test_status_returns_200(self, client: Client) -> None:
250251
response = client.send_without_payload(request_method="GET", path="_status")
251252
assert response.status_code == 200
252-
assert response.headers["Content-Type"] == "text/plain"
253+
assert response.headers["Content-Type"] == "application/json"
253254

254255
response_data = response.text
255-
assert response_data == "OK"
256+
assert response_data.__contains__('"outcome":"OK"')

0 commit comments

Comments
 (0)