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 @@ -337,3 +337,16 @@ def create_survey(self, xml_string):
337337 response_json = response .json ()
338338 self .update_project (response_json .get ('projectId' ), status = self .SURVEY_STATUS_DESIGN )
339339 return response_json
340+
341+ def get_survey_simulations (self , survey_id ):
342+ self .check_auth_headers ()
343+ simulations_url = '{}/surveys/{}/simulations' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
344+ simulations_response = requests .get (simulations_url , headers = self ._authentication_headers )
345+ if simulations_response .status_code != 200 :
346+ raise CmixError (
347+ 'CMIX returned a non-200 response code while getting simulations: {} and error {}' .format (
348+ simulations_response .status_code ,
349+ simulations_response .text
350+ )
351+ )
352+ 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/
3131 get_surveys(status, *args, **kwargs)
3232 get_survey_definition(survey_id)
3333 get_survey_xml(survey_id)
34+ get_survey_simulations(survey_id)
3435 get_survey_test_url(survey_id)
3536 get_survey_respondents(survey_id, respondent_type, live)
3637 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):
296296 extra_params_formatted = '&{}&{}' .format (extra_params [0 ], extra_params [1 ])
297297 expected = '{}{}' .format (url , extra_params_formatted )
298298 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