11import github3
2- from json import load
32from mock import patch
4- from tests .utils import (generate_response ,expect ,path , BaseCase )
3+ from tests .utils import (generate_response ,expect ,BaseCase , load )
54
65
76class TestGitHub (BaseCase ):
@@ -51,7 +50,7 @@ def test_create_issue(self):
5150assert self .request .called is False
5251
5352with 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' ),
5554self .g )
5655i = self .g .create_issue ('user' ,'repo' ,'Title' )
5756
@@ -83,7 +82,7 @@ def test_delete_key(self):
8382
8483self .login ()
8584with 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 )
8786assert self .g .delete_key (10 )is True
8887
8988assert self .request .called is True
@@ -144,7 +143,7 @@ def test_issue(self):
144143
145144assert self .g .issue (None ,None ,0 )is None
146145with 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' ))
148147i = self .g .issue ('user' ,'repo' ,1 )
149148
150149expect (i ).isinstance (github3 .issues .Issue )
@@ -212,7 +211,7 @@ def test_iter_followers(self):
212211self .g .iter_followers ()
213212
214213with 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' ))
216215u = next (self .g .iter_followers ('sigmavirus24' ))
217216expect (u ).isinstance (github3 .users .User )
218217assert self .request .called is True
@@ -235,7 +234,7 @@ def test_iter_following(self):
235234assert self .request .called is False
236235
237236with 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' ))
239238u = next (self .g .iter_following ('sigmavirus24' ))
240239expect (u ).isinstance (github3 .users .User )
241240self .mock_assertions (* args ,** self .conf )
@@ -359,9 +358,54 @@ def test_iter_starred(self):
359358self .mock_assertions (* args ,** self .conf )
360359
361360with 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' ))
363362args = ('get' ,
364363'https://api.github.com/users/sigmavirus24/starred' )
365364expect (next (self .g .iter_starred ('sigmavirus24' ))).isinstance (
366365github3 .repos .Repository )
367366self .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 )