File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -348,3 +348,16 @@ def create_survey(self, xml_string):
348
348
response_json = response .json ()
349
349
self .update_project (response_json .get ('projectId' ), status = self .SURVEY_STATUS_DESIGN )
350
350
return response_json
351
+
352
+ def get_survey_simulations (self , survey_id ):
353
+ self .check_auth_headers ()
354
+ simulations_url = '{}/surveys/{}/simulations' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
355
+ simulations_response = requests .get (simulations_url , headers = self ._authentication_headers )
356
+ if simulations_response .status_code != 200 :
357
+ raise CmixError (
358
+ 'CMIX returned a non-200 response code while getting simulations: {} and error {}' .format (
359
+ simulations_response .status_code ,
360
+ simulations_response .text
361
+ )
362
+ )
363
+ return simulations_response .json ()
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
31
31
get_surveys(status, *args, **kwargs)
32
32
get_survey_definition(survey_id)
33
33
get_survey_xml(survey_id)
34
+ get_survey_simulations(survey_id)
34
35
get_survey_test_url(survey_id)
35
36
get_survey_respondents(survey_id, respondent_type, live)
36
37
get_survey_status(survey_id)
Original file line number Diff line number Diff line change @@ -296,3 +296,29 @@ def test_add_extra_url_params(self):
296
296
extra_params_formatted = '&{}&{}' .format (extra_params [0 ], extra_params [1 ])
297
297
expected = '{}{}' .format (url , extra_params_formatted )
298
298
self .assertEqual (result , expected )
299
+
300
+ def test_get_survey_simulations (self ):
301
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
302
+
303
+ # success case
304
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
305
+ mock_get = mock .Mock ()
306
+ mock_get .status_code = 200
307
+ mock_get .json .return_value = {}
308
+ mock_request .get .return_value = mock_get
309
+
310
+ self .cmix_api .get_survey_simulations (self .survey_id )
311
+
312
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
313
+ surveys_url = '{}/surveys/{}/simulations' .format (base_url , self .survey_id )
314
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
315
+
316
+ # error case (survey not found)
317
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
318
+ mock_get = mock .Mock ()
319
+ mock_get .status_code = 404
320
+ mock_get .json .return_value = {}
321
+ mock_request .get .return_value = mock_get
322
+
323
+ with self .assertRaises (CmixError ):
324
+ self .cmix_api .get_survey_simulations (self .survey_id )
You can’t perform that action at this time.
0 commit comments