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 @@ -264,6 +264,19 @@ def get_survey_sources(self, survey_id):
264264 def get_survey_completes (self , survey_id ):
265265 return self .get_survey_respondents (survey_id , "COMPLETE" , True )
266266
267+ def get_survey_termination_codes (self , survey_id ):
268+ self .check_auth_headers ()
269+ termination_codes_url = '{}/surveys/{}/termination-codes' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
270+ termination_codes_response = requests .get (termination_codes_url , headers = self ._authentication_headers )
271+ if termination_codes_response .status_code != 200 :
272+ raise CmixError (
273+ 'CMIX returned a non-200 response code while getting termination_codes: {} and error {}' .format (
274+ termination_codes_response .status_code ,
275+ termination_codes_response .text
276+ )
277+ )
278+ return termination_codes_response .json ()
279+
267280 def create_export_archive (self , survey_id , export_type ):
268281 self .check_auth_headers ()
269282 archive_url = '{}/surveys/{}/archives' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
3535 get_survey_xml(survey_id)
3636 get_survey_sections(survey_id)
3737 get_survey_simulations(survey_id)
38+ get_survey_termination_codes(survey_id)
3839 get_survey_sources(survey_id)
3940 get_survey_test_url(survey_id)
4041 get_survey_respondents(survey_id, respondent_type, live)
Original file line number Diff line number Diff line change @@ -285,6 +285,32 @@ def test_get_survey_completes(self):
285285 ]
286286 self .assertEqual (self .cmix_api .get_survey_completes (self .survey_id ), mock_respondents )
287287
288+ def test_get_survey_termination_codes (self ):
289+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
290+
291+ # success case
292+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
293+ mock_get = mock .Mock ()
294+ mock_get .status_code = 200
295+ mock_get .json .return_value = {}
296+ mock_request .get .return_value = mock_get
297+
298+ self .cmix_api .get_survey_termination_codes (self .survey_id )
299+
300+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
301+ surveys_url = '{}/surveys/{}/termination-codes' .format (base_url , self .survey_id )
302+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
303+
304+ # error case (survey not found)
305+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
306+ mock_get = mock .Mock ()
307+ mock_get .status_code = 404
308+ mock_get .json .return_value = {}
309+ mock_request .get .return_value = mock_get
310+
311+ with self .assertRaises (CmixError ):
312+ self .cmix_api .get_survey_termination_codes (self .survey_id )
313+
288314 def test_get_surveys (self ):
289315 with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
290316 mock_post = mock .Mock ()
You can’t perform that action at this time.
0 commit comments