8000 Merge pull request #643 from jmoldow/authorize_with_github_object · pythonthings/github3.py@a657d1c · GitHub
[go: up one dir, main page]

Skip to content

Commit a657d1c

Browse files
authored
Merge pull request sigmavirus24#643 from jmoldow/authorize_with_github_object
Allow authorize() to be given a GitHub object
2 parents 0c69d9c + b7540a3 commit a657d1c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

github3/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def authorize(username, password, scopes, note='', note_url='', client_id='',
17-
client_secret='', two_factor_callback=None):
17+
client_secret='', two_factor_callback=None, github=None):
1818
"""Obtain an authorization token for the GitHub API.
1919
2020
:param str username: (required)
@@ -29,10 +29,12 @@ def authorize(username, password, scopes, note='', note_url='', client_id='',
2929
which to create the token
3030
:param func two_factor_callback: (optional), function to call when a
3131
Two-Factor Authentication code needs to be provided by the user.
32+
:param GitHub github: (optional), GitHub (or GitHubEnterprise) object for
33+
login.
3234
:returns: :class:`Authorization <Authorization>`
3335
3436
"""
35-
gh = GitHub()
37+
gh = github or GitHub()
3638
gh.login(two_factor_callback=two_factor_callback)
3739
return gh.authorize(username, password, scopes, note, note_url, client_id,
3840
client_secret)

tests/unit/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ def test_authorize(self):
4646
github3.authorize(*args)
4747
gh().authorize.assert_called_once_with(*args)
4848

49+
def test_authorize_with_github_argument(self):
50+
"""Show that github3.authorize can use an existing GitHub object."""
51+
args = ('login', 'password', ['scope'], 'note', 'url.com', '', '')
52+
github = mock.Mock(spec_set=github3.GitHub)
53+
with mock.patch('github3.api.GitHub') as gh:
54+
github3.authorize(*args, github=github)
55+
gh().assert_not_called()
56+
github.authorize.assert_called_once_with(*args)
57+
4958
def test_create_gist(self):
5059
"""Show that github3.create_gist proxies to GitHub."""
5160
args = ('description', {'files': ['file']})

0 commit comments

Comments
 (0)
0