3
3
import requests
4
4
5
5
from github3 import session
6
- try :
7
- from unittest .mock import patch , Mock
8
- except ImportError :
9
- from mock import patch , Mock
6
+ from .helper import mock
10
7
11
8
12
9
class TestGitHubSession :
@@ -87,7 +84,7 @@ def test_basic_login_disables_token_auth(self):
87
84
s .basic_auth ('username' , 'password' )
88
85
assert 'Authorization' not in s .headers
89
86
90
- @patch .object (requests .Session , 'request' )
87
+ @mock . patch .object (requests .Session , 'request' )
91
88
def test_handle_two_factor_auth (self , request_mock ):
92
89
"""Test the method that handles getting the 2fa code"""
93
90
s = self .build_session ()
@@ -99,11 +96,11 @@ def test_handle_two_factor_auth(self, request_mock):
99
96
headers = {'X-GitHub-OTP' : 'fake' }
100
97
)
101
98
102
- @patch .object (requests .Session , 'request' )
99
+ @mock . patch .object (requests .Session , 'request' )
103
100
def test_request_ignores_responses_that_do_not_require_2fa (self ,
104
101
request_mock ):
105
102
"""Test that request does not try to handle 2fa when it should not"""
106
- response = Mock ()
103
+ response = mock . Mock ()
107
104
response .configure_mock (status_code = 200 , headers = {})
108
105
request_mock .return_value = response
109
106
s = self .build_session ()
@@ -114,10 +111,10 @@ def test_request_ignores_responses_that_do_not_require_2fa(self,
114
111
'GET' , 'http://example.com' , allow_redirects = True
115
112
)
116
113
117
- @patch .object (requests .Session , 'request' )
114
+ @mock . patch .object (requests .Session , 'request' )
118
115
def test_creates_history_while_handling_2fa (self , request_mock ):
119
116
"""Test that the overridden request method will create history"""
120
- response = Mock ()
117
+ response = mock . Mock ()
121
118
response .configure_mock (
122
119
status_code = 401 ,
123
120
headers = {'X-GitHub-OTP' : 'required;2fa' },
0 commit comments