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 @@ -209,6 +209,19 @@ def get_survey_status(self, survey_id):
209
209
raise CmixError ('Get Survey Status returned without a status. Response: {}' .format (status_response .json ()))
210
210
return status .lower ()
211
211
212
+ def get_survey_sources (self , survey_id ):
213
+ self .check_auth_headers ()
214
+ sources_url = '{}/surveys/{}/sources' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
215
+ sources_response = requests .get (sources_url , headers = self ._authentication_headers )
216
+ if sources_response .status_code != 200 :
217
+ raise CmixError (
218
+ 'CMIX returned a non-200 response code while getting sources: {} and error {}' .format (
219
+ sources_response .status_code ,
220
+ sources_response .text
221
+ )
222
+ )
223
+ return sources_response .json ()
224
+
212
225
def get_survey_completes (self , survey_id ):
213
226
return self .get_survey_respondents (survey_id , "COMPLETE" , True )
214
227
Original file line number Diff line number Diff line change @@ -143,6 +143,32 @@ def test_get_survey_status_error_handled(self):
143
143
with self .assertRaises (CmixError ):
144
144
self .cmix_api .get_survey_status (self .survey_id )
145
145
146
+ def test_get_survey_sources (self ):
147
+ self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
148
+
149
+ # success case
150
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
151
+ mock_get = mock .Mock ()
152
+ mock_get .status_code = 200
153
+ mock_get .json .return_value = {}
154
+ mock_request .get .return_value = mock_get
155
+
156
+ self .cmix_api .get_survey_sources (self .survey_id )
157
+
158
+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
159
+ surveys_url = '{}/surveys/{}/sources' .format (base_url , self .survey_id )
160
+ mock_request .get .assert_any_call (surveys_url , headers = self .cmix_api ._authentication_headers )
161
+
162
+ # error case (survey not found)
163
+ with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
164
+ mock_get = mock .Mock ()
165
+ mock_get .status_code = 404
166
+ mock_get .json .return_value = {}
167
+ mock_request .get .return_value = mock_get
168
+
169
+ with self .assertRaises (CmixError ):
170
+ self .cmix_api .get_survey_sources (self .survey_id )
171
+
146
172
def test_get_survey_test_url (self ):
147
173
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
148
174
correct_test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
You can’t perform that action at this time.
0 commit comments