@@ -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