1010 INTERNAL_SERVER_ERROR_EXAMPLE ,
1111)
1212
13+ SANDBOX_API_URL = "https://sandbox.api.service.nhs.uk/validated-relationships"
1314QUESTIONNAIRE_RESPONSE_API_ENDPOINT = "/FHIR/R4/QuestionnaireResponse"
1415
1516
1617@pytest .mark .parametrize (
17- ("nhs_num" , "response_file_name" , "status_code" ),
18+ ("nhs_num" , "response_file_name" , "status_code" , "id" ),
1819 [
1920 (
2021 "9000000009" ,
2122 POST_QUESTIONNAIRE_RESPONSE__SUCCESS ,
2223 200 ,
24+ "156e1560-e532-4e2a-85ad-5aeff03dc43e" ,
2325 ),
2426 (
2527 "9000000017" ,
2628 POST_QUESTIONNAIRE_RESPONSE__SUCCESS ,
2729 200 ,
30+ "156e1560-e532-4e2a-85ad-5aeff03dc43e" ,
2831 ),
2932 (
3033 "9000000049" ,
3134 POST_QUESTIONNAIRE_RESPONSE__DUPLICATE_RELATIONSHIP_ERROR ,
3235 409 ,
36+ None ,
3337 ),
3438 (
3539 "INVALID_NHS_NUMBER" ,
3640 INTERNAL_SERVER_ERROR_EXAMPLE ,
3741 500 ,
42+ None ,
3843 ),
3944 ],
4045)
4146@patch ("sandbox.api.post_questionnaire_response.generate_response_from_example" )
4247def test_post_questionnaire_response (
4348 mock_generate_response_from_example : MagicMock ,
4449 nhs_num : str ,
50+ id : str ,
4551 response_file_name : str ,
4652 status_code : int ,
4753 client : object ,
@@ -57,6 +63,13 @@ def test_post_questionnaire_response(
5763 # Act
5864 response = client .post (QUESTIONNAIRE_RESPONSE_API_ENDPOINT , json = json )
5965 # Assert
60- mock_generate_response_from_example .assert_called_once_with (response_file_name , status_code )
66+ if id is not None :
67+ mock_generate_response_from_example .assert_called_once_with (
68+ response_file_name ,
69+ status_code ,
70+ headers = {"location" : f"{ SANDBOX_API_URL } { QUESTIONNAIRE_RESPONSE_API_ENDPOINT } ?ID={ id } " },
71+ )
72+ else :
73+ mock_generate_response_from_example .assert_called_once_with (response_file_name , status_code )
6174 assert response .status_code == status_code
6275 assert response .json == loads (mocked_response .get_data (as_text = True ))
0 commit comments