Skip to content

Commit f8eb3fa

Browse files
Merge pull request #99 from wogsland/7-get-locales
added git survey locales function
2 parents 86805e2 + bae1d96 commit f8eb3fa

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
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_simulations(survey_id)
3637
get_survey_sources(survey_id)

tests/test_api.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_get_survey_status_error_handled(self):
169169
with self.assertRaises(CmixError):
170170
self.cmix_api.get_survey_status(self.survey_id)
171171

172-
def test_get_survey_sources(self):
172+
def test_get_survey_locales(self):
173173
self.cmix_api._authentication_headers = {'Authentication': 'Bearer test'}
174174

175175
# success case
@@ -178,7 +178,31 @@ def test_get_survey_sources(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)
182+
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
181193

194+
with self.assertRaises(CmixError):
195+
self.cmix_api.get_survey_locales(self.survey_id)
196+
197+
def test_get_survey_sources(self):
198+
self.cmix_api._authentication_headers = {'Authentication': 'Bearer test'}
199+
200+
# success case
201+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
202+
mock_get = mock.Mock()
203+
mock_get.status_code = 200
204+
mock_get.json.return_value = {}
205+
mock_request.get.return_value = mock_get
182206
self.cmix_api.get_survey_sources(self.survey_id)
183207

184208
base_url = CMIX_SERVICES['survey']['BASE_URL']

0 commit comments

Comments
 (0)