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):
209209 raise CmixError ('Get Survey Status returned without a status. Response: {}' .format (status_response .json ()))
210210 return status .lower ()
211211
212+ def get_survey_sections (self , survey_id ):
213+ self .check_auth_headers ()
214+ sections_url = '{}/surveys/{}/sections' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
215+ sections_response = requests .get (sections_url , headers = self ._authentication_headers )
216+ if sections_response .status_code != 200 :
217+ raise CmixError (
218+ 'CMIX returned a non-200 response code while getting sections: {} and error {}' .format (
219+ sections_response .status_code ,
220+ sections_response .text
221+ )
222+ )
223+ return sections_response .json ()
224+
212225 def get_survey_completes (self , survey_id ):
213226 return self .get_survey_respondents (survey_id , "COMPLETE" , True )
214227
Original file line number Diff line number Diff line change @@ -143,6 +143,32 @@ def test_get_survey_status_error_handled(self):
143143 with self .assertRaises (CmixError ):
144144 self .cmix_api .get_survey_status (self .survey_id )
145145
146+ def test_get_survey_sections (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_sections (self .survey_id )
157+
158+ base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
159+ surveys_url = '{}/surveys/{}/sections' .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_sections (self .survey_id )
171+
146172 def test_get_survey_test_url (self ):
147173 self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
148174 correct_test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
You can’t perform that action at this time.
0 commit comments