Skip to content

Commit 4a267aa

Browse files
Merge branch 'dev' into 6-get-sections
2 parents dd0cadb + f8eb3fa commit 4a267aa

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

CmixAPIClient/api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def get_survey_respondents(self, survey_id, respondent_type, live):
213213
respondents_response = requests.get(respondents_url, headers=self._authentication_headers)
214214
return respondents_response.json()
215215

216+
def get_survey_locales(self, survey_id):
217+
self.check_auth_headers()
218+
locales_url = '{}/surveys/{}/locales'.format(CMIX_SERVICES['survey'][self.url_type], survey_id)
219+
locales_response = requests.get(locales_url, headers=self._authentication_headers)
220+
if locales_response.status_code != 200:
221+
raise CmixError(
222+
'CMIX returned a non-200 response code while getting locales: {} and error {}'.format(
223+
locales_response.status_code,
224+
locales_response.text
225+
)
226+
)
227+
return locales_response.json()
228+
216229
def get_survey_status(self, survey_id):
217230
self.check_auth_headers()
218231
status_url = '{}/surveys/{}'.format(CMIX_SERVICES['survey'][self.url_type], survey_id)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
3131
get_surveys(status, *args, **kwargs)
3232
get_survey_data_layouts(survey_id)
3333
get_survey_definition(survey_id)
34+
get_survey_locales(survey_id)
3435
get_survey_xml(survey_id)
3536
get_survey_sections(survey_id)
3637
get_survey_simulations(survey_id)

tests/test_api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,18 @@ def test_get_survey_sections(self):
178178
mock_get.status_code = 200
179179
mock_get.json.return_value = {}
180180
mock_request.get.return_value = mock_get
181+
self.cmix_api.get_survey_locales(self.survey_id)
181182

183+
base_url = CMIX_SERVICES['survey']['BASE_URL']
184+
surveys_url = '{}/surveys/{}/locales'.format(base_url, self.survey_id)
185+
mock_request.get.assert_any_call(surveys_url, headers=self.cmix_api._authentication_headers)
186+
187+
# error case (survey not found)
188+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
189+
mock_get = mock.Mock()
190+
mock_get.status_code = 404
191+
mock_get.json.return_value = {}
192+
mock_request.get.return_value = mock_get
182193
self.cmix_api.get_survey_sections(self.survey_id)
183194

184195
base_url = CMIX_SERVICES['survey']['BASE_URL']
@@ -195,6 +206,31 @@ def test_get_survey_sections(self):
195206
with self.assertRaises(CmixError):
196207
self.cmix_api.get_survey_sections(self.survey_id)
197208

209+
def test_get_survey_locales(self):
210+
self.cmix_api._authentication_headers = {'Authentication': 'Bearer test'}
211+
212+
# success case
213+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
214+
mock_get = mock.Mock()
215+
mock_get.status_code = 200
216+
mock_get.json.return_value = {}
217+
mock_request.get.return_value = mock_get
218+
self.cmix_api.get_survey_locales(self.survey_id)
219+
220+
base_url = CMIX_SERVICES['survey']['BASE_URL']
221+
surveys_url = '{}/surveys/{}/locales'.format(base_url, self.survey_id)
222+
mock_request.get.assert_any_call(surveys_url, headers=self.cmix_api._authentication_headers)
223+
224+
# error case (survey not found)
225+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
226+
mock_get = mock.Mock()
227+
mock_get.status_code = 404
228+
mock_get.json.return_value = {}
229+
mock_request.get.return_value = mock_get
230+
231+
with self.assertRaises(CmixError):
232+
self.cmix_api.get_survey_locales(self.survey_id)
233+
198234
def test_get_survey_sources(self):
199235
self.cmix_api._authentication_headers = {'Authentication': 'Bearer test'}
200236

0 commit comments

Comments
 (0)