|
20 | 20 | from mock import Mock |
21 | 21 |
|
22 | 22 | from github3api import GitHubAPI |
| 23 | +from github3api.githubapi import DEFAULT_PAGE_SIZE |
23 | 24 |
|
24 | 25 | from datetime import datetime |
25 | 26 |
|
@@ -345,3 +346,49 @@ def test__retry_chunkedencodingerror_error_Should_Return_False_When_NotChunkEnco |
345 | 346 | def test__retry_chunkedencodingerror_error_Should_Return_True_When_ChunkEncodingError(self, *patches): |
346 | 347 |
|
347 | 348 | self.assertTrue(GitHubAPI._retry_chunkedencodingerror_error(ChunkedEncodingError())) |
| 349 | + |
| 350 | + def test__get_endpoint_from_url_Should_ReturnExpected_When_Called(self, *patches): |
| 351 | + client = GitHubAPI(bearer_token='bearer-token') |
| 352 | + result = client.get_endpoint_from_url('https://api.github.com/user/repos?page=2') |
| 353 | + expected_result = '/user/repos?page=2' |
| 354 | + self.assertEqual(result, expected_result) |
| 355 | + |
| 356 | + def test__get_page_from_url_Should_ReturnExpected_When_Match(self, *patches): |
| 357 | + result = GitHubAPI.get_page_from_url('https://api.github.com/user/repos?page=213') |
| 358 | + expected_result = 213 |
| 359 | + self.assertEqual(result, expected_result) |
| 360 | + |
| 361 | + def test__get_page_from_url_Should_ReturnExpected_When_NoMatch(self, *patches): |
| 362 | + result = GitHubAPI.get_page_from_url('https://api.github.com/user/repos') |
| 363 | + self.assertIsNone(result) |
| 364 | + |
| 365 | + def test__get_per_page_from_url_Should_Return_Expected_When_Match(self, *patches): |
| 366 | + result = GitHubAPI.get_per_page_from_url('https://api.github.com/user/repos?page=213&per_page=75') |
| 367 | + expected_result = 75 |
| 368 | + self.assertEqual(result, expected_result) |
| 369 | + |
| 370 | + def test__get_per_page_from_url_Should_Return_Expected_When_NoMatch(self, *patches): |
| 371 | + result = GitHubAPI.get_per_page_from_url('https://api.github.com/user/repos?page=213') |
| 372 | + expected_result = DEFAULT_PAGE_SIZE |
| 373 | + self.assertEqual(result, expected_result) |
| 374 | + |
| 375 | + @patch('github3api.GitHubAPI.get') |
| 376 | + def test__get_total_Should_ReturnExpected_When_NoLinks(self, get_patch, *patches): |
| 377 | + response_mock = Mock() |
| 378 | + response_mock.links = {} |
| 379 | + response_mock.json.return_value = ['', '', ''] |
| 380 | + get_patch.return_value = response_mock |
| 381 | + client = GitHubAPI(bearer_token='bearer-token') |
| 382 | + result = client.total('/user/repos') |
| 383 | + expected_result = len(response_mock.json.return_value) |
| 384 | + self.assertEqual(result, expected_result) |
| 385 | + |
| 386 | + @patch('github3api.GitHubAPI.get') |
| 387 | + def test__get_total_Should_ReturnExpected_When_Links(self, get_patch, *patches): |
| 388 | + response1_mock = Mock() |
| 389 | + response1_mock.links = {'next': {'url': 'https://api.github.com/user/repos?page=2', 'rel': 'next'}, 'last': {'url': 'https://api.github.com/user/repos?page=208', 'rel': 'last'}} |
| 390 | + get_patch.side_effect = [response1_mock, ['', '', '']] |
| 391 | + client = GitHubAPI(bearer_token='bearer-token') |
| 392 | + result = client.total('/user/repos') |
| 393 | + expected_result = DEFAULT_PAGE_SIZE * 207 + 3 |
| 394 | + self.assertEqual(result, expected_result) |
0 commit comments