@@ -73,29 +73,6 @@ def tearDown(self):
7373
7474 pass
7575
76- def test__match_keys_Should_Return_Items_When_NoAttributes (self , * patches ):
77- result = GitHubAPI .match_keys (self .items , None )
78- self .assertEqual (result , self .items )
79-
80- def test__match_keys_Should_ReturnExpected_When_Called (self , * patches ):
81- result = GitHubAPI .match_keys (self .items , ['name' , 'key1' ])
82- expected_result = [
83- {
84- 'name' : 'name1-mid-last1' ,
85- 'key1' : 'value1'
86- }, {
87- 'name' : 'name2-mid-last2' ,
88- 'key1' : 'value1'
89- }, {
90- 'name' : 'name3-med-last3' ,
91- 'key1' : 'value1'
92- }, {
93- 'name' : 'name4-mid-last4' ,
94- 'key1' : 'value1'
95- }
96- ]
97- self .assertEqual (result , expected_result )
98-
9976 def test__get_ratelimit_Should_ReturnExpected_When_NoHeader (self , * patches ):
10077 result = GitHubAPI .get_ratelimit ({})
10178 expected_result = {}
@@ -184,116 +161,6 @@ def test__get_next_endpoint_Should_ReturnExpected_When_CalledWithNextEndpoint(se
184161 expected_result = '/organizations/27781926/repos?page=4'
185162 self .assertEqual (result , expected_result )
186163
187- @patch ('github3api.GitHubAPI._get_next_endpoint' )
188- @patch ('github3api.githubapi.RESTclient.get' )
189- def test__get_all_Should_ReturnExpected_When_GetReturnsList (self , get_patch , get_next_endpoint_patch , * patches ):
190- response_mock1 = Mock ()
191- response_mock1 .json .return_value = ['item1' , 'item2' ]
192- response_mock2 = Mock ()
193- response_mock2 .json .return_value = ['item3' , 'item4' ]
194- get_patch .side_effect = [
195- response_mock1 ,
196- response_mock2
197- ]
198- get_next_endpoint_patch .side_effect = [
199- {'Link' : 'link-header-value' },
200- {}
201- ]
202- client = GitHubAPI (bearer_token = 'bearer-token' )
203- result = client ._get_all ('/repos/edgexfoundry/cd-management/milestones' )
204- expected_result = ['item1' , 'item2' , 'item3' , 'item4' ]
205- self .assertEqual (result , expected_result )
206-
207- @patch ('github3api.GitHubAPI._get_next_endpoint' )
208- @patch ('github3api.githubapi.RESTclient.get' )
209- def test__get_all_Should_ReturnExpected_When_GetReturnsDict (self , get_patch , get_next_endpoint_patch , * patches ):
210- response_mock1 = Mock ()
211- response_mock1 .json .return_value = {'key1' : 'value1' }
212- response_mock2 = Mock ()
213- response_mock2 .json .return_value = {'key2' : 'value2' }
214- get_patch .side_effect = [
215- response_mock1 ,
216- response_mock2
217- ]
218- get_next_endpoint_patch .side_effect = [
219- {'Link' : 'link-header-value' },
220- {}
221- ]
222- client = GitHubAPI (bearer_token = 'bearer-token' )
223- result = client ._get_all ('/repos/edgexfoundry/cd-management/milestones' )
224- expected_result = [{'key1' : 'value1' }, {'key2' : 'value2' }]
225- self .assertEqual (result , expected_result )
226-
227- @patch ('github3api.GitHubAPI._get_next_endpoint' )
228- @patch ('github3api.githubapi.RESTclient.get' )
229- def test__get_all_Should_ReturnEmptyList_When_NoResponse (self , get_patch , get_next_endpoint_patch , * patches ):
230- get_patch .side_effect = [
231- None
232- ]
233- get_next_endpoint_patch .side_effect = [
234- None
235- ]
236- client = GitHubAPI (bearer_token = 'bearer-token' )
237- result = client ._get_all ('/repos/edgexfoundry/cd-management/milestones' )
238- expected_result = []
239- self .assertEqual (result , expected_result )
240-
241- @patch ('github3api.GitHubAPI._get_next_endpoint' )
242- @patch ('github3api.githubapi.RESTclient.get' )
243- def test__get_page_Should_ReturnExpected_When_Called (self , get_patch , get_next_endpoint_patch , * patches ):
244- response_mock1 = Mock ()
245- response_mock1 .json .return_value = ['page1' , 'page2' ]
246- response_mock2 = Mock ()
247- response_mock2 .json .return_value = ['page3' , 'page4' ]
248- get_patch .side_effect = [response_mock1 , response_mock2 ]
249- get_next_endpoint_patch .return_value = ['next-endpoint' , 'next-endpoint' , None ]
250- client = GitHubAPI (bearer_token = 'bearer-token' )
251- result = client ._get_page ('endpoint' )
252- self .assertEqual (next (result ), ['page1' , 'page2' ])
253- self .assertEqual (next (result ), ['page3' , 'page4' ])
254- # with self.assertRaises(StopIteration):
255- # next(result)
256-
257- @patch ('github3api.GitHubAPI._get_next_endpoint' )
258- @patch ('github3api.githubapi.RESTclient.get' )
259- def test__get_page_Should_ReturnExpected_When_NoEndpoint (self , get_patch , get_next_endpoint_patch , * patches ):
260- response_mock1 = Mock ()
261- response_mock1 .json .return_value = ['page1' , 'page2' ]
262- get_patch .side_effect = [response_mock1 ]
263- get_next_endpoint_patch .side_effect = [None ]
264- client = GitHubAPI (bearer_token = 'bearer-token' )
265- result = client ._get_page ('endpoint' )
266- self .assertEqual (next (result ), ['page1' , 'page2' ])
267- with self .assertRaises (StopIteration ):
268- next (result )
269-
270- @patch ('github3api.GitHubAPI.match_keys' )
271- @patch ('github3api.GitHubAPI._get_all' )
272- def test__get_Should_CallExpected_When_AllDirective (self , get_all_patch , match_keys_patch , * patches ):
273- client = GitHubAPI (bearer_token = 'bearer-token' )
274- endpoint = '/repos/edgexfoundry/cd-management/milestones'
275- attributes = ['key1' , 'key2' ]
276- result = client .get (endpoint , _get = 'all' , _attributes = attributes )
277- get_all_patch .assert_called_once_with (endpoint )
278- match_keys_patch .assert_called_once_with (get_all_patch .return_value , attributes )
279- self .assertEqual (result , match_keys_patch .return_value )
280-
281- @patch ('github3api.GitHubAPI._get_page' )
282- def test__get_Should_CallExpected_When_GenDirective (self , get_page_patch , * patches ):
283- client = GitHubAPI (bearer_token = 'bearer-token' )
284- endpoint = '/repos/edgexfoundry/cd-management/milestones'
285- result = client .get (endpoint , _get = 'page' )
286- get_page_patch .assert_called_once_with (endpoint )
287- self .assertEqual (result , get_page_patch .return_value )
288-
289- @patch ('github3api.githubapi.RESTclient.get' )
290- def test__get_Should_CallExpected_When_NoDirective (self , get_patch , * patches ):
291- client = GitHubAPI (bearer_token = 'bearer-token' )
292- endpoint = '/repos/edgexfoundry/cd-management/milestones'
293- result = client .get (endpoint , k1 = 'v1' , k2 = 'v2' )
294- get_patch .assert_called_once_with (endpoint , k1 = 'v1' , k2 = 'v2' )
295- self .assertEqual (result , get_patch .return_value )
296-
297164 @patch ('github3api.githubapi.getenv' , return_value = 'token' )
298165 @patch ('github3api.githubapi.GitHubAPI' )
299166 def test__get_client_Should_CallAndReturnExpected_When_Called (self , githubapi_patch , getenv_patch , * patches ):
@@ -322,12 +189,6 @@ def test__get_retries_Should_ReturnExpected_When_Called(self, *patches):
322189 ]
323190 self .assertEqual (client .retries , expected_retries )
324191
325- def test__get_endpoint_from_url_Should_ReturnExpected_When_Called (self , * patches ):
326- client = GitHubAPI (bearer_token = 'bearer-token' )
327- result = client .get_endpoint_from_url ('https://api.github.com/user/repos?page=2' )
328- expected_result = '/user/repos?page=2'
329- self .assertEqual (result , expected_result )
330-
331192 def test__get_page_from_url_Should_ReturnExpected_When_Match (self , * patches ):
332193 result = GitHubAPI .get_page_from_url ('https://api.github.com/user/repos?page=213' )
333194 expected_result = 213
0 commit comments