diff --git a/github/MainClass.py b/github/MainClass.py index ceac54e0..31a24d01 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -106,6 +106,7 @@ class Github: per_page=DEFAULT_PER_PAGE, verify=True, retry=None, + pool_size=None, ): """ :param login_or_token: string @@ -118,6 +119,7 @@ class Github: :param per_page: int :param verify: boolean or string :param retry: int or urllib3.util.retry.Retry object + :param pool_size: int """ assert login_or_token is None or isinstance(login_or_token, str), login_or_token @@ -133,6 +135,8 @@ class Github: or isinstance(retry, (int)) or isinstance(retry, (urllib3.util.Retry)) ) + assert pool_size is None or isinstance(pool_size, (int)), pool_size + if client_id is not None or client_secret is not None: warnings.warn( "client_id and client_secret are deprecated and will be removed in a future release, switch to token authentication", @@ -151,6 +155,7 @@ class Github: per_page, verify, retry, + pool_size, ) def __get_FIX_REPO_GET_GIT_REF(self): diff --git a/github/Requester.py b/github/Requester.py index 8842e3ed..30f5748f 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -82,7 +82,14 @@ class RequestsResponse: class HTTPSRequestsConnectionClass: # mimic the httplib connection object def __init__( - self, host, port=None, strict=False, timeout=None, retry=None, **kwargs + self, + host, + port=None, + strict=False, + timeout=None, + retry=None, + pool_size=None, + **kwargs, ): self.port = port if port else 443 self.host = host @@ -90,11 +97,23 @@ class HTTPSRequestsConnectionClass: self.timeout = timeout self.verify = kwargs.get("verify", True) self.session = requests.Session() - # Code to support retries - if retry: + + if retry is None: + self.retry = requests.adapters.DEFAULT_RETRIES + else: self.retry = retry - self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry) - self.session.mount("https://", self.adapter) + + if pool_size is None: + self.pool_size = requests.adapters.DEFAULT_POOLSIZE + else: + self.pool_size = pool_size + + self.adapter = requests.adapters.HTTPAdapter( + max_retries=self.retry, + pool_connections=self.pool_size, + pool_maxsize=self.pool_size, + ) + self.session.mount("https://", self.adapter) def request(self, verb, url, input, headers): self.verb = verb @@ -122,7 +141,14 @@ class HTTPSRequestsConnectionClass: class HTTPRequestsConnectionClass: # mimic the httplib connection object def __init__( - self, host, port=None, strict=False, timeout=None, retry=None, **kwargs + self, + host, + port=None, + strict=False, + timeout=None, + retry=None, + pool_size=None, + **kwargs, ): self.port = port if port else 80 self.host = host @@ -130,11 +156,23 @@ class HTTPRequestsConnectionClass: self.timeout = timeout self.verify = kwargs.get("verify", True) self.session = requests.Session() - # Code to support retries - if retry: + + if retry is None: + self.retry = requests.adapters.DEFAULT_RETRIES + else: self.retry = retry - self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry) - self.session.mount("http://", self.adapter) + + if pool_size is None: + self.pool_size = requests.adapters.DEFAULT_POOLSIZE + else: + self.pool_size = pool_size + + self.adapter = requests.adapters.HTTPAdapter( + max_retries=self.retry, + pool_connections=self.pool_size, + pool_maxsize=self.pool_size, + ) + self.session.mount("http://", self.adapter) def request(self, verb, url, input, headers): self.verb = verb @@ -264,6 +302,7 @@ class Requester: per_page, verify, retry, + pool_size, ): self._initializeDebugFeature() @@ -287,6 +326,7 @@ class Requester: self.__prefix = o.path self.__timeout = timeout self.__retry = retry # NOTE: retry can be either int or an urllib3 Retry object + self.__pool_size = pool_size self.__scheme = o.scheme if o.scheme == "https": self.__connectionClass = self.__httpsConnectionClass @@ -354,11 +394,17 @@ class Requester: ): # issue80 if o.scheme == "http": cnx = self.__httpConnectionClass( - o.hostname, o.port, retry=self.__retry + o.hostname, + o.port, + retry=self.__retry, + pool_size=self.__pool_size, ) elif o.scheme == "https": cnx = self.__httpsConnectionClass( - o.hostname, o.port, retry=self.__retry + o.hostname, + o.port, + retry=self.__retry, + pool_size=self.__pool_size, ) return cnx @@ -575,7 +621,11 @@ class Requester: return self.__connection self.__connection = self.__connectionClass( - self.__hostname, self.__port, retry=self.__retry, **kwds + self.__hostname, + self.__port, + retry=self.__retry, + pool_size=self.__pool_size, + **kwds, ) return self.__connection diff --git a/tests/Framework.py b/tests/Framework.py index fce12927..0b0be964 100644 --- a/tests/Framework.py +++ b/tests/Framework.py @@ -244,6 +244,7 @@ class BasicTestCase(unittest.TestCase): tokenAuthMode = False jwtAuthMode = False retry = None + pool_size = None replayDataFolder = os.path.join(os.path.dirname(__file__), "ReplayData") def setUp(self): @@ -352,11 +353,17 @@ class TestCase(BasicTestCase): github.Requester.Requester.setOnCheckMe(self.getFrameChecker()) if self.tokenAuthMode: - self.g = github.Github(self.oauth_token, retry=self.retry) + self.g = github.Github( + self.oauth_token, retry=self.retry, pool_size=self.pool_size + ) elif self.jwtAuthMode: - self.g = github.Github(jwt=self.jwt, retry=self.retry) + self.g = github.Github( + jwt=self.jwt, retry=self.retry, pool_size=self.pool_size + ) else: - self.g = github.Github(self.login, self.password, retry=self.retry) + self.g = github.Github( + self.login, self.password, retry=self.retry, pool_size=self.pool_size + ) def activateRecordMode(): # pragma no cover (Function useful only when recording new tests, not used during automated tests) @@ -373,3 +380,7 @@ def activateJWTAuthMode(): # pragma no cover (Function useful only when recordi def enableRetry(retry): BasicTestCase.retry = retry + + +def setPoolSize(pool_size): + BasicTestCase.pool_size = pool_size diff --git a/tests/PoolSize.py b/tests/PoolSize.py new file mode 100644 index 00000000..f58b5077 --- /dev/null +++ b/tests/PoolSize.py @@ -0,0 +1,27 @@ +import github + +from . import Framework + +REPO_NAME = "PyGithub/PyGithub" + + +class PoolSize(Framework.TestCase): + def setUp(self): + Framework.setPoolSize(20) + super().setUp() + + def testReturnsRepoAfterSettingPoolSize(self): + repository = self.g.get_repo(REPO_NAME) + self.assertIsInstance(repository, github.Repository.Repository) + self.assertEqual(repository.full_name, REPO_NAME) + + def testReturnsRepoAfterSettingPoolSizeHttp(self): + g = github.Github( + self.login, + self.password, + base_url="http://my.enterprise.com", + pool_size=20, + ) + repository = g.get_repo(REPO_NAME) + self.assertIsInstance(repository, github.Repository.Repository) + self.assertEqual(repository.full_name, REPO_NAME) diff --git a/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSize.txt b/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSize.txt new file mode 100644 index 00000000..934eb9e5 --- /dev/null +++ b/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSize.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/repos/PyGithub/PyGithub +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Fri, 08 Jan 2021 10:42:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('Cache-Control', 'public, max-age=60, s-maxage=60'), ('Vary', 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"e132b35ca5ec517feb3106720dceb9394b5bf1f333ef886f8c407d3f2d5de3b2"'), ('Last-Modified', 'Fri, 08 Jan 2021 09:41:41 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '60'), ('X-RateLimit-Remaining', '32'), ('X-RateLimit-Reset', '1610104719'), ('X-RateLimit-Used', '28'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '9588:CCCC:9EFCE:B6C13:5FF83725')] +{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"https://api.github.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"https://api.github.com/users/PyGithub/followers","following_url":"https://api.github.com/users/PyGithub/following{/other_user}","gists_url":"https://api.github.com/users/PyGithub/gists{/gist_id}","starred_url":"https://api.github.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyGithub/subscriptions","organizations_url":"https://api.github.com/users/PyGithub/orgs","repos_url":"https://api.github.com/users/PyGithub/repos","events_url":"https://api.github.com/users/PyGithub/events{/privacy}","received_events_url":"https://api.github.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"https://api.github.com/repos/PyGithub/PyGithub","forks_url":"https://api.github.com/repos/PyGithub/PyGithub/forks","keys_url":"https://api.github.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyGithub/PyGithub/teams","hooks_url":"https://api.github.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/PyGithub/PyGithub/events","assignees_url":"https://api.github.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/PyGithub/PyGithub/tags","blobs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/PyGithub/PyGithub/languages","stargazers_url":"https://api.github.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/PyGithub/PyGithub/subscription","commits_url":"https://api.github.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyGithub/PyGithub/merges","archive_url":"https://api.github.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyGithub/PyGithub/downloads","issues_url":"https://api.github.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/PyGithub/PyGithub/deployments","created_at":"2012-02-25T12:53:47Z","updated_at":"2021-01-08T09:41:41Z","pushed_at":"2021-01-07T18:49:51Z","git_url":"git://github.com/PyGithub/PyGithub.git","ssh_url":"git@github.com:PyGithub/PyGithub.git","clone_url":"https://github.com/PyGithub/PyGithub.git","svn_url":"https://github.com/PyGithub/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13251,"stargazers_count":4000,"watchers_count":4000,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1245,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":82,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1245,"open_issues":82,"watchers":4000,"default_branch":"master","temp_clone_token":null,"organization":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"https://api.github.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"https://api.github.com/users/PyGithub/followers","following_url":"https://api.github.com/users/PyGithub/following{/other_user}","gists_url":"https://api.github.com/users/PyGithub/gists{/gist_id}","starred_url":"https://api.github.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyGithub/subscriptions","organizations_url":"https://api.github.com/users/PyGithub/orgs","repos_url":"https://api.github.com/users/PyGithub/repos","events_url":"https://api.github.com/users/PyGithub/events{/privacy}","received_events_url":"https://api.github.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"network_count":1245,"subscribers_count":105} + diff --git a/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSizeHttp.txt b/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSizeHttp.txt new file mode 100644 index 00000000..4e5cc4d3 --- /dev/null +++ b/tests/ReplayData/PoolSize.testReturnsRepoAfterSettingPoolSizeHttp.txt @@ -0,0 +1,11 @@ +http +GET +my.enterprise.com +None +/repos/PyGithub/PyGithub +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Fri, 08 Jan 2021 10:42:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('Cache-Control', 'public, max-age=60, s-maxage=60'), ('Vary', 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"e132b35ca5ec517feb3106720dceb9394b5bf1f333ef886f8c407d3f2d5de3b2"'), ('Last-Modified', 'Fri, 08 Jan 2021 09:41:41 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '60'), ('X-RateLimit-Remaining', '32'), ('X-RateLimit-Reset', '1610104719'), ('X-RateLimit-Used', '28'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '9588:CCCC:9EFCE:B6C13:5FF83725')] +{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"http://my.enterprise.com/repos/PyGithub/PyGithub","forks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/forks","keys_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/teams","hooks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/events","assignees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/tags","blobs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/languages","stargazers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscription","commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/merges","archive_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/downloads","issues_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/deployments","created_at":"2012-02-25T12:53:47Z","updated_at":"2021-01-08T09:41:41Z","pushed_at":"2021-01-07T18:49:51Z","git_url":"git://github.com/PyGithub/PyGithub.git","ssh_url":"git@github.com:PyGithub/PyGithub.git","clone_url":"https://github.com/PyGithub/PyGithub.git","svn_url":"https://github.com/PyGithub/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13251,"stargazers_count":4000,"watchers_count":4000,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1245,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":82,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"http://my.enterprise.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1245,"open_issues":82,"watchers":4000,"default_branch":"master","temp_clone_token":null,"organization":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"network_count":1245,"subscribers_count":105} + diff --git a/tests/ReplayData/Retry.testReturnsRepoAfterSettingRetryHttp.txt b/tests/ReplayData/Retry.testReturnsRepoAfterSettingRetryHttp.txt new file mode 100644 index 00000000..4e5cc4d3 --- /dev/null +++ b/tests/ReplayData/Retry.testReturnsRepoAfterSettingRetryHttp.txt @@ -0,0 +1,11 @@ +http +GET +my.enterprise.com +None +/repos/PyGithub/PyGithub +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Fri, 08 Jan 2021 10:42:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('Cache-Control', 'public, max-age=60, s-maxage=60'), ('Vary', 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"e132b35ca5ec517feb3106720dceb9394b5bf1f333ef886f8c407d3f2d5de3b2"'), ('Last-Modified', 'Fri, 08 Jan 2021 09:41:41 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '60'), ('X-RateLimit-Remaining', '32'), ('X-RateLimit-Reset', '1610104719'), ('X-RateLimit-Used', '28'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '9588:CCCC:9EFCE:B6C13:5FF83725')] +{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"http://my.enterprise.com/repos/PyGithub/PyGithub","forks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/forks","keys_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/teams","hooks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/events","assignees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/tags","blobs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/languages","stargazers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscription","commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/merges","archive_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/downloads","issues_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/deployments","created_at":"2012-02-25T12:53:47Z","updated_at":"2021-01-08T09:41:41Z","pushed_at":"2021-01-07T18:49:51Z","git_url":"git://github.com/PyGithub/PyGithub.git","ssh_url":"git@github.com:PyGithub/PyGithub.git","clone_url":"https://github.com/PyGithub/PyGithub.git","svn_url":"https://github.com/PyGithub/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13251,"stargazers_count":4000,"watchers_count":4000,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1245,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":82,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"http://my.enterprise.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1245,"open_issues":82,"watchers":4000,"default_branch":"master","temp_clone_token":null,"organization":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"network_count":1245,"subscribers_count":105} + diff --git a/tests/Retry.py b/tests/Retry.py index 940d4058..19ecf49c 100644 --- a/tests/Retry.py +++ b/tests/Retry.py @@ -75,3 +75,14 @@ class Retry(Framework.TestCase): self.assertEqual(len(httpretty.latest_requests), 4) for request in httpretty.latest_requests: self.assertEqual(request.path, "/repos/PyGithub/PyGithub") + + def testReturnsRepoAfterSettingRetryHttp(self): + g = github.Github( + self.login, + self.password, + base_url="http://my.enterprise.com", + retry=0, + ) # http here + repository = g.get_repo(REPO_NAME) + self.assertIsInstance(repository, github.Repository.Repository) + self.assertEqual(repository.full_name, REPO_NAME)