Skip to content

Commit

Permalink
Merge pull request #10 from soda480/0.0.7
Browse files Browse the repository at this point in the history
Add version parameter and disable chunkedencodingerror retry
  • Loading branch information
soda480 authored Feb 22, 2021
2 parents e47185d + 40b22fb commit 15a28bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]
summary = 'An advanced REST client for the GitHub API'
url = 'https://github.com/soda480/github3api'
version = '0.0.6'
version = '0.0.7'
default_task = [
'clean',
'analyze',
Expand Down
6 changes: 4 additions & 2 deletions src/main/python/github3api/githubapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
logging.getLogger('urllib3.connectionpool').setLevel(logging.CRITICAL)

HOSTNAME = 'api.github.com'
VERSION = 'v3'


class GitHubAPI(RESTclient):
Expand All @@ -36,6 +37,7 @@ class GitHubAPI(RESTclient):
def __init__(self, **kwargs):
logger.debug('executing GitHubAPI constructor')
hostname = kwargs.pop('hostname', HOSTNAME)
self.version = kwargs.pop('version', VERSION)
super(GitHubAPI, self).__init__(hostname, **kwargs)

def get_response(self, response, **kwargs):
Expand All @@ -50,7 +52,7 @@ def get_headers(self, **kwargs):
""" return headers to pass to requests method
"""
headers = super(GitHubAPI, self).get_headers(**kwargs)
headers['Accept'] = 'application/vnd.github.v3+json'
headers['Accept'] = f'application/vnd.github.{self.version}+json'
return headers

def _get_next_endpoint(self, link_header):
Expand Down Expand Up @@ -175,7 +177,7 @@ def retry_ratelimit_error(exception):
return False

@staticmethod
def retry_chunkedencodingerror_error(exception):
def _retry_chunkedencodingerror_error(exception):
""" return True if exception is ChunkedEncodingError, False otherwise
retry:
wait_fixed:10000
Expand Down
19 changes: 12 additions & 7 deletions src/unittest/python/test_githubapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def test__get_headers_Should_SetAcceptHeader_When_Called(self, *patches):
result = client.get_headers()
self.assertEqual(result['Accept'], 'application/vnd.github.v3+json')

def test__get_headers_Should_SetAcceptHeader_When_Version(self, *patches):
client = GitHubAPI(bearer_token='bearer-token', version='v2')
result = client.get_headers()
self.assertEqual(result['Accept'], 'application/vnd.github.v2+json')

def test__get_next_endpoint_Should_ReturnNone_When_NoLinkHeader(self, *patches):
client = GitHubAPI(bearer_token='bearer-token')
self.assertIsNone(client._get_next_endpoint(None))
Expand Down Expand Up @@ -328,11 +333,11 @@ def test__get_client_Should_CallAndReturnExpected_When_Called(self, githubapi_pa
def test__get_retries_Should_ReturnExpected_When_Called(self, *patches):
client = GitHubAPI(bearer_token='bearer-token')
expected_retries = [
{
'retry_on_exception': client.retry_chunkedencodingerror_error,
'stop_max_attempt_number': 120,
'wait_fixed': 10000
},
# {
# 'retry_on_exception': client.retry_chunkedencodingerror_error,
# 'stop_max_attempt_number': 120,
# 'wait_fixed': 10000
# },
{
'retry_on_exception': client.retry_ratelimit_error,
'stop_max_attempt_number': 60,
Expand All @@ -344,8 +349,8 @@ def test__get_retries_Should_ReturnExpected_When_Called(self, *patches):

def test__retry_chunkedencodingerror_error_Should_Return_False_When_NotChunkEncodingError(self, *patches):

self.assertFalse(GitHubAPI.retry_chunkedencodingerror_error(Exception('test')))
self.assertFalse(GitHubAPI._retry_chunkedencodingerror_error(Exception('test')))

def test__retry_chunkedencodingerror_error_Should_Return_True_When_ChunkEncodingError(self, *patches):

self.assertTrue(GitHubAPI.retry_chunkedencodingerror_error(ChunkedEncodingError()))
self.assertTrue(GitHubAPI._retry_chunkedencodingerror_error(ChunkedEncodingError()))

0 comments on commit 15a28bd

Please sign in to comment.