1
1
import github3
2
2
from unittest import TestCase
3
- try :
4
- from unittest .mock import patch , NonCallableMock
5
- except ImportError :
6
- from mock import patch , NonCallableMock
3
+ #from .utils.mock import patch, NonCallableMock
4
+ from .utils import mock
7
5
8
6
9
7
class TestAPI (TestCase ):
10
8
def setUp (self ):
11
- self .mock = patch ('github3.api.gh' , autospec = github3 .GitHub )
9
+ self .mock = mock . patch ('github3.api.gh' , autospec = github3 .GitHub )
12
10
self .gh = self .mock .start ()
13
11
14
12
def tearDown (self ):
@@ -17,21 +15,21 @@ def tearDown(self):
17
15
def test_authorize (self ):
18
16
args = ('login' , 'password' , ['scope1' ], 'note' , 'note_url.com' , '' ,
19
17
'' )
20
- with patch .object (github3 .api .GitHub , 'authorize' ) as authorize :
18
+ with mock . patch .object (github3 .api .GitHub , 'authorize' ) as authorize :
21
19
github3 .authorize (* args )
22
20
authorize .assert_called_once_with (* args )
23
21
24
22
def test_login (self ):
25
23
args = ('login' , 'password' , None , None )
26
- with patch .object (github3 .api .GitHub , 'login' ) as login :
24
+ with mock . patch .object (github3 .api .GitHub , 'login' ) as login :
27
25
g = github3 .login (* args )
28
26
assert isinstance (g , github3 .github .GitHub )
29
27
assert not isinstance (g , github3 .github .GitHubEnterprise )
30
28
login .assert_called_with (* args )
31
29
32
30
def test_enterprise_login (self ):
33
31
args = ('login' , 'password' , None , 'http://ghe.invalid/' , None )
34
- with patch .object (github3 .api .GitHubEnterprise , 'login' ) as login :
32
+ with mock . patch .object (github3 .api .GitHubEnterprise , 'login' ) as login :
35
33
g = github3 .login (* args )
36
3
75DF
4
assert isinstance (g , github3 .github .GitHubEnterprise )
37
35
login .assert_called_with ('login' , 'password' , None , None )
@@ -146,7 +144,7 @@ def test_rate_limit(self):
146
144
def test_ratelimit_remaining (self ):
147
145
# This prevents a regression in the API
148
146
# See 81c800658db43f86419b9c0764fc16aad3d60007
149
- self .gh .ratelimit_remaining = NonCallableMock ()
147
+ self .gh .ratelimit_remaining = mock . NonCallableMock ()
150
148
github3 .ratelimit_remaining ()
151
149
152
150
def test_zen (self ):
0 commit comments