Skip to content

Commit 9c60bd6

Browse files
committed
Replaced @patch('requests.head') with @requests_mock.Mocker(), bringing it in line with the other tests.
1 parent dff72ff commit 9c60bd6

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

linkcheck/tests/test_linkcheck.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -676,26 +676,20 @@ def test_external_check_blocked_user_agent_blocked_head(self):
676676
'linkcheck.models.PROXIES',
677677
{'http': 'http://proxy.example.com:8080'},
678678
)
679-
@patch('requests.head')
680-
def test_external_proxy_request(self, mock_head):
681-
mock_response = Mock()
682-
mock_response.status_code = 200
683-
mock_response.reason = 'OK'
684-
mock_response.history = []
685-
mock_head.return_value = mock_response
686-
request_url = 'http://test.com'
687-
uv = Url(url=request_url)
679+
@requests_mock.Mocker()
680+
def test_external_proxy_request(self, mocker):
681+
mocker.register_uri('HEAD', 'http://test.com', reason='OK'),
682+
uv = Url(url='http://test.com')
683+
self.assertEqual(mocker.called, False)
688684
uv.check_url()
685+
self.assertEqual(mocker.called, True)
689686
self.assertEqual(uv.status, True)
690687
self.assertEqual(uv.message, '200 OK')
691688
self.assertEqual(uv.type, 'external')
692-
mock_head.assert_called_once()
693-
(call_url,), call_kwargs = mock_head.call_args
694-
self.assertEqual(call_url, request_url)
695-
self.assertEqual(
696-
call_kwargs.get('proxies'),
697-
{'http': 'http://proxy.example.com:8080'},
698-
)
689+
last_request = mocker.last_request
690+
self.assertEqual(last_request.hostname, 'test.com')
691+
self.assertEqual(last_request.scheme, 'http')
692+
self.assertEqual(last_request.proxies, {'http': 'http://proxy.example.com:8080'})
699693

700694
def test_external_check_timedout(self):
701695
uv = Url(url=f"{self.live_server_url}/timeout/")

0 commit comments

Comments
 (0)