Skip to content

Commit f7ef465

Browse files
committed
Accept sessions in GitHub{,Enterprise,Status}
Allow all of our main entry points to accept Sessions customized by the user, especially for the purposes of testing with Betamax. Closes sigmavirus24#699
1 parent fc081be commit f7ef465

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

github3/github.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class GitHub(models.GitHubCore):
5656
call the GitHub object with authentication parameters.
5757
"""
5858

59-
def __init__(self, username='', password='', token=''):
59+
def __init__(self, username='', password='', token='', session=None):
6060
"""Create a new GitHub instance to talk to the API."""
61-
super(GitHub, self).__init__({}, self.new_session())
61+
super(GitHub, self).__init__({}, session or self.new_session())
6262
if token:
6363
self.login(username, token=token)
6464
elif username and password:
@@ -2173,9 +2173,11 @@ class GitHubEnterprise(GitHub):
21732173
override the validation by passing `verify=False`.
21742174
"""
21752175

2176-
def __init__(self, url, username='', password='', token='', verify=True):
2176+
def __init__(self, url, username='', password='', token='', verify=True,
2177+
session=None):
21772178
"""Create a client for a GitHub Enterprise instance."""
2178-
super(GitHubEnterprise, self).__init__(username, password, token)
2179+
super(GitHubEnterprise, self).__init__(username, password, token,
2180+
session=session)
21792181
self.session.base_url = url.rstrip('/') + '/api/v3'
21802182
self.session.verify = verify
21812183
self.url = url
@@ -2233,9 +2235,9 @@ class GitHubStatus(models.GitHubCore):
22332235
This will only ever return the JSON objects returned by the API.
22342236
"""
22352237

2236-
def __init__(self):
2238+
def __init__(self, session=None):
22372239
"""Create a status API client."""
2238-
super(GitHubStatus, self).__init__({}, self.new_session())
2240+
super(GitHubStatus, self).__init__({}, session or self.new_session())
22392241
self.session.base_url = 'https://status.github.com'
22402242

22412243
def _repr(self):

tests/unit/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ def create_instance_of_described_class(self):
108108

109109
else:
110110
if self.enterprise_url is None:
111-
instance = self.described_class()
111+
instance = self.described_class(session=self.session)
112112
else:
113-
instance = self.described_class(self.enterprise_url)
114-
instance.session = self.session
113+
instance = self.described_class(self.enterprise_url,
114+
session=self.session)
115115

116116
return instance
117117

0 commit comments

Comments
 (0)