1+ import uuid
2+
13import pytest
24import requests
35
@@ -7,13 +9,23 @@ class ImmunisationApi:
79 def __init__ (self , url , token ):
810 self .url = url
911 self .token = token
12+ self .headers = {
13+ "Authorization" : self .token ,
14+ "Content-Type" : "application/fhir+json" ,
15+ "Accept" : "application/fhir+json" ,
16+ }
1017
1118 def get_event_by_id (self , event_id ):
12- headers = {
13- "Authorization" : self .token
14- }
15- response = requests .get (f"{ self .url } /event/{ event_id } " , headers = headers )
16- return response
19+ return requests .get (f"{ self .url } /event/{ event_id } " , headers = self ._update_headers ())
20+
21+ def _update_headers (self , headers = None ):
22+ if headers is None :
23+ headers = {}
24+ updated = {** self .headers , ** {
25+ "X-Correlation-ID" : str (uuid .uuid4 ()),
26+ "X-Request-ID" : str (uuid .uuid4 ()),
27+ }}
28+ return {** updated , ** headers }
1729
1830
1931@pytest .mark .nhsd_apim_authorization (
@@ -35,7 +47,6 @@ def test_get_event_by_id_not_found_nhs_login(nhsd_apim_proxy_url, nhsd_apim_auth
3547 # Assert
3648 assert result .status_code == 404
3749 assert res_body ["resourceType" ] == "OperationOutcome"
38- assert res_body ["issue" ][0 ]["code" ] == "not-found"
3950
4051
4152@pytest .mark .nhsd_apim_authorization (
@@ -57,7 +68,6 @@ def test_get_event_by_id_invalid_nhs_login(nhsd_apim_proxy_url, nhsd_apim_auth_h
5768 # Assert
5869 assert result .status_code == 400
5970 assert res_body ["resourceType" ] == "OperationOutcome"
60- assert res_body ["issue" ][0 ]["code" ] == "invalid"
6171
6272
6373@pytest .mark .nhsd_apim_authorization (
@@ -73,11 +83,10 @@ def test_get_event_by_id_happy_path_nhs_login(nhsd_apim_proxy_url, nhsd_apim_aut
7383 imms_api = ImmunisationApi (nhsd_apim_proxy_url , token )
7484
7585 # Act
76- id = "e045626e-4dc5-4df3-bc35-da25263f901e"
77- result = imms_api .get_event_by_id (id )
86+ imms_id = "e045626e-4dc5-4df3-bc35-da25263f901e"
87+ result = imms_api .get_event_by_id (imms_id )
7888 json_result = result .json ()
7989
8090 # Assert
81- assert result .headers ["Content-Type" ] == "application/fhir+json"
8291 assert result .status_code == 200
83- assert json_result ["identifier" ][0 ]["value" ] == id
92+ assert json_result ["identifier" ][0 ]["value" ] == imms_id
0 commit comments