Skip to content

Commit 49a6664

Browse files
committed
get projects function
1 parent 40b6dac commit 49a6664

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CmixAPIClient/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,9 @@ def get_survey_simulations(self, survey_id):
418418
)
419419
)
420420
return simulations_response.json()
421+
422+
def get_projects(self):
423+
project_endpoint = 'projects'
424+
project_error = 'CMIX returned a non-200 response code while getting projects'
425+
project_response = self.api_get(project_endpoint, project_error)
426+
return project_response

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
2929
authenticate(*args, **kwargs)
3030
fetch_banner_filter(survey_id, question_a, question_b, response_id)
3131
fetch_raw_results(survey_id, payload)
32-
get_project(project_id)
32+
get_projects()
3333
get_surveys(status, *args, **kwargs)
3434
get_survey_data_layouts(survey_id)
3535
get_survey_definition(survey_id)
@@ -50,9 +50,15 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
5050

5151
### CmixProject
5252

53+
get_full_links()
5354
get_groups()
55+
get_links()
56+
get_locales()
57+
get_markup_files()
5458
get_project()
59+
get_respondent_links()
5560
get_sources()
61+
get_surveys()
5662

5763
## Contributing
5864

tests/test_api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ def setUp(self):
2424
self.survey_id = 1337
2525
self.project_id = 1492
2626

27+
def helper_get(self, function_name, endpoint):
28+
func = getattr(self.cmix_api, function_name)
29+
30+
# success case
31+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
32+
mock_get = mock.Mock()
33+
mock_get.status_code = 200
34+
mock_get.json.return_value = {}
35+
mock_request.get.return_value = mock_get
36+
37+
func()
38+
39+
base_url = CMIX_SERVICES['survey']['BASE_URL']
40+
project_url = '{}/{}'.format(base_url, endpoint)
41+
mock_request.get.assert_any_call(project_url, headers=self.cmix_api._authentication_headers)
42+
43+
# error case (survey not found)
44+
with mock.patch('CmixAPIClient.api.requests') as mock_request:
45+
mock_get = mock.Mock()
46+
mock_get.status_code = 404
47+
mock_get.json.return_value = {}
48+
mock_request.get.return_value = mock_get
49+
50+
with self.assertRaises(CmixError):
51+
func()
52+
2753
def test_cmix_authentication_check(self):
2854
with self.assertRaises(CmixError):
2955
CmixAPI()
@@ -425,3 +451,6 @@ def test_get_survey_simulations(self):
425451

426452
with self.assertRaises(CmixError):
427453
self.cmix_api.get_survey_simulations(self.survey_id)
454+
455+
def test_get_projects(self):
456+
self.helper_get('get_projects', 'projects')

0 commit comments

Comments
 (0)