Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad79943

Browse files
committed
Refactor and fix lots of things
Closessigmavirus24#163
1 parent42aee7d commitad79943

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

‎github3/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ class GitHubEnterprise(GitHub):
11481148
"""
11491149
def__init__(self,url,login='',password='',token=''):
11501150
super(GitHubEnterprise,self).__init__(login,password,token)
1151-
self._github_url=url.rstrip('/')+'/api/v3'
1151+
self._session.base_url=url.rstrip('/')+'/api/v3'
11521152

11531153
def__repr__(self):
11541154
return'<GitHub Enterprise [0.url]>'.format(self)
@@ -1177,7 +1177,7 @@ class GitHubStatus(GitHubCore):
11771177
"""
11781178
def__init__(self):
11791179
super(GitHubStatus,self).__init__({})
1180-
self._github_url='https://status.github.com'
1180+
self._session.base_url='https://status.github.com'
11811181

11821182
def__repr__(self):
11831183
return'<GitHub Status>'

‎github3/models.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
fromdatetimeimportdatetime
1414
fromloggingimportgetLogger
1515

16-
__url_cache__= {}
1716
__timeformat__='%Y-%m-%dT%H:%M:%SZ'
1817
__logs__=getLogger(__package__)
1918

@@ -136,15 +135,7 @@ def _put(self, url, **kwargs):
136135

137136
def_build_url(self,*args,**kwargs):
138137
"""Builds a new API url from scratch."""
139-
parts= [kwargs.get('base_url')orself._github_url]
140-
parts.extend(args)
141-
parts= [str(p)forpinparts]
142-
key=tuple(parts)
143-
__logs__.info('Building a url from %s',key)
144-
ifnotkeyin__url_cache__:
145-
__logs__.info('Missed the cache building the url')
146-
__url_cache__[key]='/'.join(parts)
147-
return__url_cache__[key]
138+
returnself._session.build_url(*args,**kwargs)
148139

149140
@property
150141
def_api(self):

‎github3/session.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
importrequests
22

33
fromgithub3import__version__
4+
fromloggingimportgetLogger
5+
6+
__url_cache__= {}
7+
__logs__=getLogger(__package__)
48

59

610
classGitHubSession(requests.Session):
@@ -16,6 +20,7 @@ def __init__(self):
1620
# Set our own custom User-Agent string
1721
'User-Agent':'github3.py/{0}'.format(__version__),
1822
})
23+
self.base_url='https://api.github.com'
1924

2025
defbasic_auth(self,username,password):
2126
"""Set the Basic Auth credentials on this Session.
@@ -28,6 +33,18 @@ def basic_auth(self, username, password):
2833

2934
self.auth= (username,password)
3035

36+
defbuild_url(self,*args,**kwargs):
37+
"""Builds a new API url from scratch."""
38+
parts= [kwargs.get('base_url')orself.base_url]
39+
parts.extend(args)
40+
parts= [str(p)forpinparts]
41+
key=tuple(parts)
42+
__logs__.info('Building a url from %s',key)
43+
ifnotkeyin__url_cache__:
44+
__logs__.info('Missed the cache building the url')
45+
__url_cache__[key]='/'.join(parts)
46+
return__url_cache__[key]
47+
3148
deftoken_auth(self,token):
3249
"""Use an application token for authentication.
3350

‎tests/unit/helper.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
importmock
2-
importrequests
2+
importgithub3
33
importunittest
44

5-
MockedSession=mock.create_autospec(requests.Session)
5+
MockedSession=mock.create_autospec(github3.session.GitHubSession)
6+
7+
8+
defbuild_url(self,*args,**kwargs):
9+
# We want to assert what is happening with the actual calls to the
10+
# Internet. We can proxy this.
11+
returngithub3.session.GitHubSession().build_url(*args,**kwargs)
612

713

814
classUnitHelper(unittest.TestCase):
@@ -28,3 +34,7 @@ def create_session_mock(self, *args):
2834
defsetUp(self):
2935
self.session=self.create_session_mock()
3036
self.instance=self.described_class(self.example_data,self.session)
37+
# Proxy the build_url method to the class so it can build the URL and
38+
# we can assert things about the call that will be attempted to the
39+
# internet
40+
self.described_class._build_url=build_url

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp