8000 Update references to mock in tests/unit/ · davidmoss/github3.py@c864320 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit c864320

Browse files
committed
Update references to mock in tests/unit/
1 parent 965f0bd commit c864320

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

tests/unit/test_github_session.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import requests
44

55
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
107

118

129
class TestGitHubSession:
@@ -87,7 +84,7 @@ def test_basic_login_disables_token_auth(self):
8784
s.basic_auth('username', 'password')
8885
assert 'Authorization' not in s.headers
8986

90-
@patch.object(requests.Session, 'request')
87+
@mock.patch.object(requests.Session, 'request')
9188
def test_handle_two_factor_auth(self, request_mock):
9289
"""Test the method that handles getting the 2fa code"""
9390
s = self.build_session()
@@ -99,11 +96,11 @@ def test_handle_two_factor_auth(self, request_mock):
9996
headers={'X-GitHub-OTP': 'fake'}
10097
)
10198

102-
@patch.object(requests.Session, 'request')
99+
@mock.patch.object(requests.Session, 'request')
103100
def test_request_ignores_responses_that_do_not_require_2fa(self,
104101
request_mock):
105102
"""Test that request does not try to handle 2fa when it should not"""
106-
response = Mock()
103+
response = mock.Mock()
107104
response.configure_mock(status_code=200, headers={})
108105
request_mock.return_value = response
109106
s = self.build_session()
@@ -114,10 +111,10 @@ def test_request_ignores_responses_that_do_not_require_2fa(self,
114111
'GET', 'http://example.com', allow_redirects=True
115112
)
116113

117-
@patch.object(requests.Session, 'request')
114+
@mock.patch.object(requests.Session, 'request')
118115
def test_creates_history_while_handling_2fa(self, request_mock):
119116
"""Test that the overridden request method will create history"""
120-
response = Mock()
117+
response = mock.Mock()
121118
response.configure_mock(
122119
status_code=401,
123120
headers={'X-GitHub-OTP': 'required;2fa'},

tests/unit/test_structs.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
from .helper import UnitHelper
1+
from .helper import UnitHelper, mock
22
from github3.structs import GitHubIterator
33

4-
try:
5-
from unittest import mock
6-
except ImportError:
7-
import mock
8-
94

105
class TestGitHubIterator(UnitHelper):
116
described_class = GitHubIterator

0 commit comments

Comments
 (0)
0