Skip to content

Commit 8ac4b36

Browse files
committed
Passing tests that are actually correct!
1 parent d05fd0e commit 8ac4b36

6 files changed

Lines changed: 50 additions & 36 deletions

File tree

github3/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Event(GitHubObject):
1414
returned by via the `Events <http://developer.github.com/v3/events>`_
1515
section of the GitHub API.
1616
"""
17-
def __init__(self, event, session=None):
18-
super(Event, self).__init__(event, session)
17+
def __init__(self, event):
18+
super(Event, self).__init__(event)
1919
from github3.users import User
2020
from github3.orgs import Organization
2121
#: :class:`User <github3.users.User>` object representing the actor.

github3/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self, login='', password='', token=''):
5757
def __repr__(self):
5858
return '<GitHub at 0x{0:x}>'.format(id(self))
5959

60+
@requires_auth
6061
def _iter_follow(self, which, number):
6162
url = self._build_url('user', which)
6263
return self._iter(number, url, User)
@@ -402,7 +403,7 @@ def iter_following(self, login=None, number=-1):
402403
"""
403404
if login:
404405
return self.user(login).iter_following()
405-
return self._iter_follow('followers', int(number))
406+
return self._iter_follow('following', int(number))
406407

407408
def iter_gists(self, username=None, number=-1):
408409
"""If no username is specified, GET /gists, otherwise GET

tests/json/key

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"url": "https://api.github.com/user/keys/4", "verified": true, "id": 495863, "key": "...", "title": "key"}
1+
{"url": "https://api.github.com/user/keys/10", "verified": true, "id": 495863, "key": "...", "title": "key"}

tests/json/user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"public_repos": 22, "public_gists": 5, "name": "Tadas Vilkeliskis", "bio": "", "url": "https://api.github.com/users/tadasv", "created_at": "2008-04-12T14:03:41Z", "html_url": "https://github.com/tadasv", "id": 6939, "blog": "http://tadas.vilkeliskis.com", "company": "Chartbeat, Inc", "avatar_url": "https://secure.gravatar.com/avatar/406bde80fb83ce0322edec4ba710696e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "_links": {"self": {"href": "https://api.github.com/users/tadasv"}}, "location": "USA", "gravatar_id": "406bde80fb83ce0322edec4ba710696e", "following": 12, "followers": 10, "hireable": false, "type": "User", "email": "vilkeliskis.t@gmail.com", "login": "tadasv"}
1+
{"bio": null, "public_gists": 10, "name": "Ian Cordasco", "public_repos": 24, "url": "https://api.github.com/users/sigmavirus24", "created_at": "2010-04-10T04:07:32Z", "html_url": "https://github.com/sigmavirus24", "id": 240830, "blog": "http://www.coglib.com/~icordasc/blog", "company": null, "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "followers": 7, "location": null, "gravatar_id": "c148356d89f925e692178bee1d93acf7", "following": 8, "_links": {"self": {"href": "https://api.github.com/users/sigmavirus24"}}, "hireable": true, "type": "User", "email": "graffatcolmingov@gmail.com", "login": "sigmavirus24"}

tests/test_github.py

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,26 @@ def test_create_repo(self):
8080

8181
def test_delete_key(self):
8282
self.request.return_value = generate_response(None, 204)
83-
args = ('delete', 'https://api.github.com/user/keys/10')
8483

8584
self.login()
8685
with patch.object(github3.github.GitHub, 'key') as key:
8786
key.return_value = github3.users.Key(load(path('key')), self.g)
8887
assert self.g.delete_key(10) is True
8988

90-
self.mock_assertions(*args, **self.conf)
89+
assert self.request.called is True
9190

9291
def test_follow(self):
9392
self.request.return_value = generate_response(None, 204)
94-
args = ('post', 'https://api.github.com/user/following/sigmavirus24')
93+
args = ('put', 'https://api.github.com/user/following/sigmavirus24')
94+
conf = dict(headers={'Content-Length': '0'}, data=None)
9595

9696
with expect.githuberror():
9797
self.g.follow('sigmavirus24')
9898

9999
self.login()
100100
assert self.g.follow(None) is False
101101
assert self.g.follow('sigmavirus24') is True
102-
self.mock_assertions(*args, **self.conf)
102+
self.mock_assertions(*args, **conf)
103103

104104
def test_gist(self):
105105
self.request.return_value = generate_response('gist', 200)
@@ -138,12 +138,14 @@ def test_is_subscribed(self):
138138

139139
def test_issue(self):
140140
self.request.return_value = generate_response('issue', 200)
141-
args = ('get', 'https://api.github.com/repos/user/repo/issues/1')
141+
args = ('get',
142+
'https://api.github.com/repos/sigmavirus24/github3.py/issues/1'
143+
)
142144

143145
assert self.g.issue(None, None, 0) is None
144146
with patch.object(github3.github.GitHub, 'repository') as repo:
145147
repo.return_value = github3.repos.Repository(load(path('repo')))
146-
i = self.g.issue(1)
148+
i = self.g.issue('user', 'repo', 1)
147149

148150
expect(i).isinstance(github3.issues.Issue)
149151
self.mock_assertions(*args, **self.conf)
@@ -166,7 +168,8 @@ def test_key(self):
166168
def test_iter_authorizations(self):
167169
self.request.return_value = generate_response('authorization',
168170
_iter=True)
169-
args = ('get', 'https://api.github.com/user/authorizations')
171+
args = ('get', 'https://api.github.com/authorizations')
172+
self.conf.update(params=None)
170173

171174
with expect.githuberror():
172175
self.g.iter_authorizations()
@@ -180,6 +183,7 @@ def test_iter_authorizations(self):
180183
def test_iter_emails(self):
181184
self.request.return_value = generate_response('emails')
182185
args = ('get', 'https://api.github.com/user/emails')
186+
self.conf.update(params=None)
183187

184188
with expect.githuberror():
185189
self.g.iter_emails()
@@ -193,6 +197,7 @@ def test_iter_emails(self):
193197
def test_iter_events(self):
194198
self.request.return_value = generate_response('event', _iter=True)
195199
args = ('get', 'https://api.github.com/events')
200+
self.conf.update(params=None)
196201

197202
event = next(self.g.iter_events())
198203
expect(event).isinstance(github3.events.Event)
@@ -201,44 +206,50 @@ def test_iter_events(self):
201206
def test_iter_followers(self):
202207
self.request.return_value = generate_response('user', _iter=True)
203208
args = ('get', 'https://api.github.com/users/sigmavirus24/followers')
204-
205-
u = next(self.g.iter_followers('sigmavirus24'))
206-
expect(u).isinstance(github3.users.User)
207-
assert self.request.called is True
208-
self.mock_assertions(*args, **self.conf)
209+
self.conf.update(params=None)
209210

210211
with expect.githuberror():
211-
next(self.g.iter_followers())
212-
213-
self.login()
214-
v = next(self.g.iter_followers())
215-
expect(v).isinstance(github3.users.User)
216-
args = (args[0], 'https://api.github.com/user/followers')
217-
assert self.request.called is True
218-
self.mock_assertions(*args, **self.conf)
212+
self.g.iter_followers()
213+
214+
with patch.object(github3.github.GitHub, 'user') as ghuser:
215+
ghuser.return_value = github3.users.User(load(path('user')))
216+
u = next(self.g.iter_followers('sigmavirus24'))
217+
expect(u).isinstance(github3.users.User)
218+
assert self.request.called is True
219+
self.mock_assertions(*args, **self.conf)
220+
221+
self.login()
222+
v = next(self.g.iter_followers())
223+
expect(v).isinstance(github3.users.User)
224+
args = (args[0], 'https://api.github.com/user/followers')
225+
assert self.request.called is True
226+
self.mock_assertions(*args, **self.conf)
219227

220228
def test_iter_following(self):
221229
self.request.return_value = generate_response('user', _iter=True)
222-
args = ('get',
223-
'https://api.github.com/users/sigmavirus24/followering')
230+
args = ('get', 'https://api.github.com/users/sigmavirus24/following')
231+
self.conf.update(params=None)
224232

225233
with expect.githuberror():
226234
next(self.g.iter_following())
227235
assert self.request.called is False
228236

229-
u = next(self.g.iter_following('sigmavirus24'))
230-
expect(u).isinstance(github3.users.User)
231-
self.mock_assertions(*args, **self.conf)
237+
with patch.object(github3.github.GitHub, 'user') as ghuser:
238+
ghuser.return_value = github3.users.User(load(path('user')))
239+
u = next(self.g.iter_following('sigmavirus24'))
240+
expect(u).isinstance(github3.users.User)
241+
self.mock_assertions(*args, **self.conf)
232242

233-
self.login()
234-
v = next(self.g.iter_following())
235-
expect(v).isinstance(github3.users.User)
236-
args = (args[0], 'https://api.github.com/user/following')
237-
self.mock_assertions(*args, **self.conf)
243+
self.login()
244+
v = next(self.g.iter_following())
245+
expect(v).isinstance(github3.users.User)
246+
args = (args[0], 'https://api.github.com/user/following')
247+
self.mock_assertions(*args, **self.conf)
238248

239249
def test_iter_gists(self):
240250
self.request.return_value = generate_response('gist', _iter=True)
241251
args = ('get', 'https://api.github.com/users/sigmavirus24/gists')
252+
self.conf.update(params=None)
242253

243254
g = next(self.g.iter_gists('sigmavirus24'))
244255
expect(g).isinstance(github3.gists.Gist)

tests/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ def login(self):
7575

7676
def mock_assertions(self, *args, **kwargs):
7777
assert self.request.called is True
78-
assert call(*args, **kwargs) in self.request.mock_calls
78+
c = call(*args, **kwargs)
79+
assert c in self.request.mock_calls, '{0} not in {1}'.format(c,
80+
self.request.mock_calls)

0 commit comments

Comments
 (0)