@@ -32,102 +32,111 @@ def test_health_check(client: object, endpoint: str) -> None:
3232 [
3333 (
3434 "identifier=9000000033" ,
35- "./api/responses /GET_RelatedPerson/empty_response_9000000033.json " ,
35+ "./api/examples /GET_RelatedPerson/empty_response_9000000033.yaml " ,
3636 200 ,
3737 ),
3838 (
3939 "identifier=9000000017" ,
40- "./api/responses /GET_RelatedPerson/list_relationship_9000000017.json " ,
40+ "./api/examples /GET_RelatedPerson/list_relationship_9000000017.yaml " ,
4141 200 ,
4242 ),
4343 (
4444 "identifier=9000000017&_include=RelatedPerson:patient" ,
45- "./api/responses /GET_RelatedPerson/list_relationship_include_9000000017.json " ,
45+ "./api/examples /GET_RelatedPerson/list_relationship_9000000017_include.yaml " ,
4646 200 ,
4747 ),
4848 (
4949 "identifier=9000000017&_include=any" ,
50- "./api/responses /GET_RelatedPerson/list_relationship_9000000017.json " ,
50+ "./api/examples /GET_RelatedPerson/list_relationship_9000000017.yaml " ,
5151 200 ,
5252 ),
5353 (
5454 "identifier=9000000017&patient:identifier=9000000009" ,
55- "./api/responses /GET_RelatedPerson/verify_relationship_9000000009.json " ,
55+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000009.yaml " ,
5656 200 ,
5757 ),
5858 (
5959 "identifier=9000000017&patient:identifier=9000000009&_include=RelatedPerson:patient" ,
60- "./api/responses /GET_RelatedPerson/verify_relationship_include_9000000009.json " ,
60+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000009_include.yaml " ,
6161 200 ,
6262 ),
6363 (
6464 "identifier=9000000017&patient:identifier=9000000009&_include=any" ,
65- "./api/responses /GET_RelatedPerson/verify_relationship_9000000009.json " ,
65+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000009.yaml " ,
6666 200 ,
6767 ),
6868 (
6969 "identifier=9000000017&patient:identifier=9000000025" ,
70- "./api/responses /GET_RelatedPerson/verify_relationship_9000000025.json " ,
70+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000025.yaml " ,
7171 200 ,
7272 ),
7373 (
7474 "identifier=9000000017&patient:identifier=9000000025&_include=RelatedPerson:patient" ,
75- "./api/responses /GET_RelatedPerson/verify_relationship_include_9000000025.json " ,
75+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000025_include.yaml " ,
7676 200 ,
7777 ),
7878 (
7979 "identifier=9000000017&patient:identifier=9000000025&_include=any" ,
80- "./api/responses /GET_RelatedPerson/verify_relationship_9000000025.json " ,
80+ "./api/examples /GET_RelatedPerson/verify_relationship_9000000025.yaml " ,
8181 200 ,
8282 ),
8383 ],
8484)
85- @patch (f" { UTILS_FILE_PATH } .load_json_file " )
85+ @patch ("sandbox.api.utils.generate_response_from_example " )
8686def test_related_person (
87- mock_load_json_file : MagicMock ,
87+ mock_generate_response_from_example : MagicMock ,
8888 request_args : str ,
8989 response_file_name : str ,
90- client : object ,
9190 status_code : int ,
91+ client : object ,
9292) -> None :
9393 """Test related_persons endpoint."""
94+
9495 # Arrange
95- mock_load_json_file .return_value = expected_body = {"data" : "mocked" }
96+ mock_generate_response_from_example .return_value = mocked_response = Response (
97+ dumps ({"data" : "mocked" }), status = status_code , content_type = "application/json"
98+ )
9699 # Act
97100 response = client .get (f"{ RELATED_PERSON_API_ENDPOINT } ?{ request_args } " )
98101 # Assert
99- mock_load_json_file .assert_called_once_with (response_file_name )
102+ mock_generate_response_from_example .assert_called_once_with (
103+ response_file_name , status_code
104+ )
100105 assert response .status_code == status_code
101- assert response .json == expected_body
106+ assert response .json == loads ( mocked_response . get_data ( as_text = True ))
102107
103108
104109@pytest .mark .parametrize (
105110 "url_path,response_file_name,status_code" ,
106111 [
107112 (
108113 QUESTIONNAIRE_RESPONSE_API_ENDPOINT ,
109- "./api/responses /POST_QuestionnaireResponse/questionnaire_response_success.json " ,
114+ "./api/examples /POST_QuestionnaireResponse/success.yaml " ,
110115 200 ,
111116 ),
112117 ],
113118)
114- @patch (f"{ APP_FILE_PATH } .load_json_file " )
119+ @patch (f"{ APP_FILE_PATH } .generate_response_from_example " )
115120def test_questionnaire_response (
116- mock_load_json_file : MagicMock ,
121+ mock_generate_response_from_example : MagicMock ,
117122 url_path : str ,
118123 response_file_name : str ,
119124 client : object ,
120125 status_code : int ,
121126) -> None :
122127 """Test related_persons endpoint with identifier only."""
123128 # Arrange
124- mock_load_json_file .return_value = expected_body = {"data" : "mocked" }
129+ mock_generate_response_from_example .return_value = mocked_response = Response (
130+ dumps ({"data" : "mocked" }), status = status_code , content_type = "application/json"
131+ )
125132 # Act
126133 response = client .post (url_path , json = {"data" : "mocked" })
127134 # Assert
128- mock_load_json_file .assert_called_once_with (response_file_name )
135+ mock_generate_response_from_example .assert_called_once_with (
136+ response_file_name , status_code
137+ )
129138 assert response .status_code == status_code
130- assert response .json == expected_body
139+ assert response .json == loads ( mocked_response . get_data ( as_text = True ))
131140
132141
133142@pytest .mark .parametrize (
0 commit comments