Skip to content

Commit 3407682

Browse files
committed
Merge branch 'dev' into 10-termination-codes
2 parents 0759e1b + dba067a commit 3407682

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CmixAPIClient/api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,16 @@ def create_survey(self, xml_string):
348348
response_json = response.json()
349349
self.update_project(response_json.get('projectId'), status=self.SURVEY_STATUS_DESIGN)
350350
return response_json
351+
352+
def get_survey_simulations(self, survey_id):
353+
self.check_auth_headers()
354+
simulations_url = '{}/surveys/{}/simulations'.format(CMIX_SERVICES['survey'][self.url_type], survey_id)
355+
simulations_response = requests.get(simulations_url, headers=self._authentication_headers)
356+
if simulations_response.status_code != 200:
357+
raise CmixError(
358+
'CMIX returned a non-200 response code while getting simulations: {} and error {}'.format(
359+
simulations_response.status_code,
360+
simulations_response.text
361+
)
362+
)
363+
return simulations_response.json()

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_definition(survey_id)
3333
get_survey_xml(survey_id)
34+
get_survey_simulations(survey_id)
3435
get_survey_test_url(survey_id)
3536
get_survey_respondents(survey_id, respondent_type, live)
3637
get_survey_status(survey_id)

tests/test_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,29 @@ def test_add_extra_url_params(self):
296296
extra_params_formatted = '&{}&{}'.format(extra_params[0], extra_params[1])
297297
expected = '{}{}'.format(url, extra_params_formatted)
298298
self.assertEqual(result, expected)
299+
300+
def test_get_survey_simulations(self):
301+
self.cmix_api._authentication_headers = {'Authentication': 'Bearer test'}
302+
303+
# success case
304+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
305+
mock_get = mock.Mock()
306+
mock_get.status_code = 200
307+
mock_get.json.return_value = {}
308+
mock_request.get.return_value = mock_get
309+
310+
self.cmix_api.get_survey_simulations(self.survey_id)
311+
312+
base_url = CMIX_SERVICES['survey']['BASE_URL']
313+
surveys_url = '{}/surveys/{}/simulations'.format(base_url, self.survey_id)
314+
mock_request.get.assert_any_call(surveys_url, headers=self.cmix_api._authentication_headers)
315+
316+
# error case (survey not found)
317+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
318+
mock_get = mock.Mock()
319+
mock_get.status_code = 404
320+
mock_get.json.return_value = {}
321+
mock_request.get.return_value = mock_get
322+
323+
with self.assertRaises(CmixError):
324+
self.cmix_api.get_survey_simulations(self.survey_id)

0 commit comments

Comments
 (0)