from requests import exceptions
import pytest
from rest_framework import status
from rest_framework.reverse import reverse

from company.data import CompaniesHouseException
from core.tests.helpers import create_response

expected_exceptions = (
    exceptions.RequestException(),
    exceptions.HTTPError(),
    exceptions.ConnectionError(),
    exceptions.ProxyError(),
    exceptions.SSLError(),
    exceptions.Timeout(),
    exceptions.ConnectTimeout(),
    exceptions.ReadTimeout(),
    CompaniesHouseException(404),
)


@pytest.fixture(autouse=True)
def mock_client_get():
    stub = mock.patch('company.data.CompaniesHouseClient.get')
    yield stub.start()
    stub.stop


def test_company_search_view_missing_querystring(api_client):
    url = reverse('api:search-companies')
    response = api_client.get(url)
 def test_heartbeat_fails_if_unreachable(self):
     self.mock.post.side_effect = requests_exceptions.ConnectTimeout()
     resp = self.app.get("/__heartbeat__", status=503)
     assert resp.json["signer"] is False
Beispiel #3
0
 def test_api_call(*args, **kwargs):
     raise request_exceptions.ConnectTimeout()
Beispiel #4
0
 def connect_timeout():
     raise requests_exceptions.ConnectTimeout()
 def test_connect_timeout(self):
     signal = http_checks.check_fail(rex.ConnectTimeout())
     self._assert_has_tags(self.timeout_tags, signal)
     self._assert_has_slug("HTTP_FAIL_CONNECT_TIMEOUT", signal)