Skip to content

Commit 476fbd0

Browse files
ben-beauhurstclaudep
authored andcommitted
Replaced @patch('requests.head') with @requests_mock.Mocker(), bringing it in line with the other tests.
1 parent 71f5127 commit 476fbd0

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
@@ -677,26 +677,20 @@ def test_external_check_blocked_user_agent_blocked_head(self):
677677
'linkcheck.models.PROXIES',
678678
{'http': 'http://proxy.example.com:8080'},
679679
)
680-
@patch('requests.head')
681-
def test_external_proxy_request(self, mock_head):
682-
mock_response = Mock()
683-
mock_response.status_code = 200
684-
mock_response.reason = 'OK'
685-
mock_response.history = []
686-
mock_head.return_value = mock_response
687-
request_url = 'http://test.com'
688-
uv = Url(url=request_url)
680+
@requests_mock.Mocker()
681+
def test_external_proxy_request(self, mocker):
682+
mocker.register_uri('HEAD', 'http://test.com', reason='OK'),
683+
uv = Url(url='http://test.com')
684+
self.assertEqual(mocker.called, False)
689685
uv.check_url()
686+
self.assertEqual(mocker.called, True)
690687
self.assertEqual(uv.status, True)
691688
self.assertEqual(uv.message, '200 OK')
692689
self.assertEqual(uv.type, 'external')
693-
mock_head.assert_called_once()
694-
(call_url,), call_kwargs = mock_head.call_args
695-
self.assertEqual(call_url, request_url)
696-
self.assertEqual(
697-
call_kwargs.get('proxies'),
698-
{'http': 'http://proxy.example.com:8080'},
699-
)
690+
last_request = mocker.last_request
691+
self.assertEqual(last_request.hostname, 'test.com')
692+
self.assertEqual(last_request.scheme, 'http')
693+
self.assertEqual(last_request.proxies, {'http': 'http://proxy.example.com:8080'})
700694

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

0 commit comments

Comments
 (0)