Fix tests

Thanks to @ErikKalkoken for helping here
This commit is contained in:
Peter Pfeufer 2021-11-23 02:31:18 +01:00
parent 49548d6f9f
commit b6d6c68e54
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27

View File

@ -310,7 +310,23 @@ class TestFetchListFromGitlab(TestCase):
self.assertEqual(requests_mocker.call_count, max_pages)
@requests_mock.mock()
def test_can_handle_connection_timeout(self, requests_mocker):
requests_mocker.get(self.url, exc=requests.exceptions.ConnectTimeout)
with self.assertRaises(requests.exceptions.ConnectTimeout):
result = _fetch_list_from_gitlab(self.url)
@patch(MODULE_PATH + '.admin_status.logger')
def test_should_not_raise_any_exception_from_github_request_but_log_as_warning(
self, requests_mocker, mock_logger
):
for my_exception in [
requests.exceptions.ConnectionError,
requests.exceptions.HTTPError,
requests.exceptions.URLRequired,
requests.exceptions.TooManyRedirects,
requests.exceptions.ConnectTimeout,
requests.exceptions.Timeout,
]:
requests_mocker.get(self.url, exc=my_exception)
try:
result = _fetch_list_from_gitlab(self.url)
except Exception as ex:
self.fail(f"Unexpected exception raised: {ex}")
self.assertTrue(mock_logger.warning.called)
self.assertListEqual(result, [])