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 @@ -222,6 +222,19 @@ def get_survey_status(self, survey_id):
222
222
raise CmixError ('Get Survey Status returned without a status. Response: {}' .format (status_response .json ()))
223
223
return status .lower ()
224
224
225
+ def get_survey_sources (self , survey_id ):
226
+ self .check_auth_headers ()
227
+ sources_url = '{}/surveys/{}/sources' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
228
+ sources_response = requests .get (sources_url , headers = self ._authentication_headers )
229
+ if sources_response .status_code != 200 :
230
+ raise CmixError (
231
+ 'CMIX returned a non-200 response code while getting sources: {} and error {}' .format (
232
+ sources_response .status_code ,
233
+ sources_response .text
234
+ )
235
+ )
236
+ return sources_response .json ()
237
+
225
238
def get_survey_completes (self , survey_id ):
226
239
return self .get_survey_respondents (survey_id , "COMPLETE" , True )
227
240
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
33
33
get_survey_definition(survey_id)
34
34
get_survey_xml(survey_id)
35
35
get_survey_simulations(survey_id)
36
+ get_survey_sources(survey_id)
36
37
get_survey_test_url(survey_id)
37
38
get_survey_respondents(survey_id, respondent_type, live)
38
39
get_survey_status(survey_id)
Original file line number Diff line number Diff line change @@ -169,6 +169,32 @@ def test_get_survey_status_error_handled(self):
169
169
with self .assertRaises (CmixError ):
170
170
self .cmix_api .get_survey_status (self .survey_id )
171
171
172
+ def test_get_survey_sources (self ):
173
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
174
+
175
+ # success case
176
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
177
+ mock_get = mock .Mock ()
178
+ mock_get .status_code = 200
179
+ mock_get .json .return_value = {}
180
+ mock_request .get .return_value = mock_get
181
+
182
+ self .cmix_api .get_survey_sources (self .survey_id )
183
+
184
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
185
+ surveys_url = '{}/surveys/{}/sources' .format (base_url , self .survey_id )
186
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
187
+
188
+ # error case (survey not found)
189
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
190
+ mock_get = mock .Mock ()
191
+ mock_get .status_code = 404
192
+ mock_get .json .return_value = {}
193
+ mock_request .get .return_value = mock_get
194
+
195
+ with self .assertRaises (CmixError ):
196
+ self .cmix_api .get_survey_sources (self .survey_id )
197
+
172
198
def test_get_survey_test_url (self ):
173
199
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
174
200
correct_test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
You can’t perform that action at this time.
0 commit comments