File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -235,6 +235,19 @@ def get_survey_sections(self, survey_id):
235
235
)
236
236
return sections_response .json ()
237
237
238
+ def get_survey_sources (self , survey_id ):
239
+ self .check_auth_headers ()
240
+ sources_url = '{}/surveys/{}/sources' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
241
+ sources_response = requests .get (sources_url , headers = self ._authentication_headers )
242
+ if sources_response .status_code != 200 :
243
+ raise CmixError (
244
+ 'CMIX returned a non-200 response code while getting sources: {} and error {}' .format (
245
+ sources_response .status_code ,
246
+ sources_response .text
247
+ )
248
+ )
249
+ return sources_response .json ()
250
+
238
251
def get_survey_completes (self , survey_id ):
239
252
return self .get_survey_respondents (survey_id , "COMPLETE" , True )
240
253
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
34
34
get_survey_xml(survey_id)
35
35
get_survey_sections(survey_id)
36
36
get_survey_simulations(survey_id)
37
+ get_survey_sources(survey_id)
37
38
get_survey_test_url(survey_id)
38
39
get_survey_respondents(survey_id, respondent_type, live)
39
40
get_survey_status(survey_id)
Original file line number Diff line number Diff line change @@ -195,6 +195,31 @@ def test_get_survey_sections(self):
195
195
with self .assertRaises (CmixError ):
196
196
self .cmix_api .get_survey_sections (self .survey_id )
197
197
198
+ def test_get_survey_sources (self ):
199
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
200
+
201
+ # success case
202
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
203
+ mock_get = mock .Mock ()
204
+ mock_get .status_code = 200
205
+ mock_get .json .return_value = {}
206
+ mock_request .get .return_value = mock_get
207
+ self .cmix_api .get_survey_sources (self .survey_id )
208
+
209
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
210
+ surveys_url = '{}/surveys/{}/sources' .format (base_url , self .survey_id )
211
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
212
+
213
+ # error case (survey not found)
214
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
215
+ mock_get = mock .Mock ()
216
+ mock_get .status_code = 404
217
+ mock_get .json .return_value = {}
218
+ mock_request .get .return_value = mock_get
219
+
220
+ with self .assertRaises (CmixError ):
221
+ self .cmix_api .get_survey_sources (self .survey_id )
222
+
198
223
def test_get_survey_test_url (self ):
199
224
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
200
225
correct_test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
You can’t perform that action at this time.
0 commit comments