File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -335,3 +335,16 @@ def create_survey(self, xml_string):
335
335
response_json = response .json ()
336
336
self .update_project (response_json .get ('projectId' ), status = self .SURVEY_STATUS_DESIGN )
337
337
return response_json
338
+
339
+ def get_survey_simulations (self , survey_id ):
340
+ self .check_auth_headers ()
341
+ simulations_url = '{}/surveys/{}/simulations' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
342
+ simulations_response = requests .get (simulations_url , headers = self ._authentication_headers )
343
+ if simulations_response .status_code != 200 :
344
+ raise CmixError (
345
+ 'CMIX returned a non-200 response code while getting simulations: {} and error {}' .format (
346
+ simulations_response .status_code ,
347
+ simulations_response .text
348
+ )
349
+ )
350
+ return simulations_response .json ()
Original file line number Diff line number Diff line change @@ -270,3 +270,29 @@ def test_add_extra_url_params(self):
270
270
extra_params_formatted = '&{}&{}' .format (extra_params [0 ], extra_params [1 ])
271
271
expected = '{}{}' .format (url , extra_params_formatted )
272
272
self .assertEqual (result , expected )
273
+
274
+ def test_get_survey_simulations (self ):
275
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
276
+
277
+ # success case
278
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
279
+ mock_get = mock .Mock ()
280
+ mock_get .status_code = 200
281
+ mock_get .json .return_value = {}
282
+ mock_request .get .return_value = mock_get
283
+
284
+ self .cmix_api .get_survey_simulations (self .survey_id )
285
+
286
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
287
+ surveys_url = '{}/surveys/{}/simulations' .format (base_url , self .survey_id )
288
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
289
+
290
+ # error case (survey not found)
291
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
292
+ mock_get = mock .Mock ()
293
+ mock_get .status_code = 404
294
+ mock_get .json .return_value = {}
295
+ mock_request .get .return_value = mock_get
296
+
297
+ with self .assertRaises (CmixError ):
298
+ self .cmix_api .get_survey_simulations (self .survey_id )
You can’t perform that action at this time.
0 commit comments