@@ -16,8 +16,9 @@ def setUp(self):
16
16
self .cmix_api ._authentication_headers = {'Authorization' : 'Bearer test' }
17
17
self .project_id = 1492
18
18
19
- def test_get_project (self ):
19
+ def helper_get (self , function_name , endpoint ):
20
20
project = CmixProject (self .cmix_api , self .project_id )
21
+ func = getattr (project , function_name )
21
22
22
23
# success case
23
24
with mock .patch ('CmixAPIClient.api.requests' ) as mock_request :
@@ -26,10 +27,10 @@ def test_get_project(self):
26
27
mock_get .json .return_value = {}
27
28
mock_request .get .return_value = mock_get
28
29
29
- project . get_project ()
30
+ func ()
30
31
31
32
base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
32
- project_url = '{}/projects/ {}' .format (base_url , self . project_id )
33
+ project_url = '{}/projects{}' .format (base_url , endpoint )
33
34
mock_request .get .assert_any_call (project_url , headers = self .cmix_api ._authentication_headers )
34
35
35
36
# error case (survey not found)
@@ -40,4 +41,10 @@ def test_get_project(self):
40
41
mock_request .get .return_value = mock_get
41
42
42
43
with self .assertRaises (CmixError ):
43
- project .get_project ()
44
+ func ()
45
+
46
+ def test_get_project (self ):
47
+ self .helper_get ('get_project' , '/{}' .format (self .project_id ))
48
+
49
+ def test_get_sources (self ):
50
+ self .helper_get ('get_sources' , '/{}/sources' .format (self .project_id ))
0 commit comments