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 @@ -212,6 +212,19 @@ def get_survey_status(self, survey_id):
212
212
def get_survey_completes (self , survey_id ):
213
213
return self .get_survey_respondents (survey_id , "COMPLETE" , True )
214
214
215
+ def get_survey_termination_codes (self , survey_id ):
216
+ self .check_auth_headers ()
217
+ termination_codes_url = '{}/surveys/{}/termination-codes' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
218
+ termination_codes_response = requests .get (termination_codes_url , headers = self ._authentication_headers )
219
+ if termination_codes_response .status_code != 200 :
220
+ raise CmixError (
221
+ 'CMIX returned a non-200 response code while getting termination_codes: {} and error {}' .format (
222
+ termination_codes_response .status_code ,
223
+ termination_codes_response .text
224
+ )
225
+ )
226
+ return termination_codes_response .json ()
227
+
215
228
def create_export_archive (self , survey_id , export_type ):
216
229
self .check_auth_headers ()
217
230
archive_url = '{}/surveys/{}/archives' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
Original file line number Diff line number Diff line change @@ -183,6 +183,32 @@ def test_get_survey_completes(self):
183
183
]
184
184
self .assertEqual (self .cmix_api .get_survey_completes (self .survey_id ), mock_respondents )
185
185
186
+ def test_get_survey_termination_codes (self ):
187
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
188
+
189
+ # success case
190
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
191
+ mock_get = mock .Mock ()
192
+ mock_get .status_code = 200
193
+ mock_get .json .return_value = {}
194
+ mock_request .get .return_value = mock_get
195
+
196
+ self .cmix_api .get_survey_termination_codes (self .survey_id )
197
+
198
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
199
+ surveys_url = '{}/surveys/{}/termination-codes' .format (base_url , self .survey_id )
200
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
201
+
202
+ # error case (survey not found)
203
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
204
+ mock_get = mock .Mock ()
205
+ mock_get .status_code = 404
206
+ mock_get .json .return_value = {}
207
+ mock_request .get .return_value = mock_get
208
+
209
+ with self .assertRaises (CmixError ):
210
+ self .cmix_api .get_survey_termination_codes (self .survey_id )
211
+
186
212
def test_get_surveys (self ):
187
213
with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
188
214
mock_post = mock .Mock ()
You can’t perform that action at this time.
0 commit comments