1
1
import github3
2
- from json import load
3
2
from mock import patch
4
- from tests .utils import (generate_response ,expect ,path , BaseCase )
3
+ from tests .utils import (generate_response ,expect ,BaseCase , load )
5
4
6
5
7
6
class TestGitHub (BaseCase ):
@@ -51,7 +50,7 @@ def test_create_issue(self):
51
50
assert self .request .called is False
52
51
53
52
with patch .object (github3 .GitHub ,'repository' )as repo :
54
- repo .return_value = github3 .repos .Repository (load (path ( 'repo' ) ),
53
+ repo .return_value = github3 .repos .Repository (load ('repo' ),
55
54
self .g )
56
55
i = self .g .create_issue ('user' ,'repo' ,'Title' )
57
56
@@ -83,7 +82,7 @@ def test_delete_key(self):
83
82
84
83
self .login ()
85
84
with patch .object (github3 .github .GitHub ,'key' )as key :
86
- key .return_value = github3 .users .Key (load (path ( 'key' ) ),self .g )
85
+ key .return_value = github3 .users .Key (load ('key' ),self .g )
87
86
assert self .g .delete_key (10 )is True
88
87
89
88
assert self .request .called is True
@@ -144,7 +143,7 @@ def test_issue(self):
144
143
145
144
assert self .g .issue (None ,None ,0 )is None
146
145
with patch .object (github3 .github .GitHub ,'repository' )as repo :
147
- repo .return_value = github3 .repos .Repository (load (path ( 'repo' ) ))
146
+ repo .return_value = github3 .repos .Repository (load ('repo' ))
148
147
i = self .g .issue ('user' ,'repo' ,1 )
149
148
150
149
expect (i ).isinstance (github3 .issues .Issue )
@@ -212,7 +211,7 @@ def test_iter_followers(self):
212
211
self .g .iter_followers ()
213
212
214
213
with patch .object (github3 .github .GitHub ,'user' )as ghuser :
215
- ghuser .return_value = github3 .users .User (load (path ( 'user' ) ))
214
+ ghuser .return_value = github3 .users .User (load ('user' ))
216
215
u = next (self .g .iter_followers ('sigmavirus24' ))
217
216
expect (u ).isinstance (github3 .users .User )
218
217
assert self .request .called is True
@@ -235,7 +234,7 @@ def test_iter_following(self):
235
234
assert self .request .called is False
236
235
237
236
with patch .object (github3 .github .GitHub ,'user' )as ghuser :
238
- ghuser .return_value = github3 .users .User (load (path ( 'user' ) ))
237
+ ghuser .return_value = github3 .users .User (load ('user' ))
239
238
u = next (self .g .iter_following ('sigmavirus24' ))
240
239
expect (u ).isinstance (github3 .users .User )
241
240
self .mock_assertions (* args ,** self .conf )
@@ -359,9 +358,54 @@ def test_iter_starred(self):
359
358
self .mock_assertions (* args ,** self .conf )
360
359
361
360
with patch .object (github3 .github .GitHub ,'user' )as user :
362
- user .return_value = github3 .users .User (load (path ( 'user' ) ))
361
+ user .return_value = github3 .users .User (load ('user' ))
363
362
args = ('get' ,
364
363
'https://api.github.com/users/sigmavirus24/starred' )
365
364
expect (next (self .g .iter_starred ('sigmavirus24' ))).isinstance (
366
365
github3 .repos .Repository )
367
366
self .mock_assertions (* args ,** self .conf )
367
+
368
+ def test_iter_subscribed (self ):
369
+ self .request .return_value = generate_response ('repo' ,_iter = True )
370
+ args = ('get' ,'https://api.github.com/user/subscriptions' )
371
+ self .conf .update (params = None )
372
+
373
+ self .login ()
374
+ expect (next (self .g .iter_subscribed ())).isinstance (
375
+ github3 .repos .Repository )
376
+ self .mock_assertions (* args ,** self .conf )
377
+
378
+ with patch .object (github3 .github .GitHub ,'user' )as user :
379
+ user .return_value = github3 .users .User (load ('user' ))
380
+ args = ('get' ,
381
+ 'https://api.github.com/users/sigmavirus24/subscriptions' )
382
+ expect (next (self .g .iter_subscribed ('sigmavirus24' ))).isinstance (
383
+ github3 .repos .Repository )
384
+ self .mock_assertions (* args ,** self .conf )
385
+
386
+ def test_login (self ):
387
+ self .g .login ('user' ,'password' )
388
+ expect (self .g ._session .auth )== ('user' ,'password' )
389
+
390
+ self .g .login (token = 'FakeOAuthToken' )
391
+ auth = self .g ._session .headers .get ('Authorization' )
392
+ expect (auth )== 'token FakeOAuthToken'
393
+
394
+ # Unwritten test, not entirely sure how to mock this
395
+ def test_markdown (self ):
396
+ pass
397
+
398
+ def test_pull_request (self ):
399
+ self .request .return_value = generate_response ('pull' )
400
+ args = ('get' ,
401
+ 'https://api.github.com/repos/sigmavirus24/github3.py/pulls/18'
402
+ )
403
+ pr = None
404
+
405
+ with patch .object (github3 .github .GitHub ,'repository' )as repo :
406
+ repo .return_value = github3 .repos .Repository (load ('repo' ))
407
+ pr = self .g .pull_request ('sigmavirus24' ,'github3.py' ,18 )
408
+
409
+ expect (pr ).isinstance (github3 .pulls .PullRequest )
410
+
411
+ self .mock_assertions (* args ,** self .conf )