Esempio n. 1
0
    def test_it_passes_arbitrary_kwargs_to_requests(self, svc):
        session = Mock()
        svc = HTTPService(session)

        svc.request("GET", "https://example.com", foo="bar")

        assert session.request.call_args[1]["foo"] == "bar"
Esempio n. 2
0
    def test_request_with_regular_exceptions(self, error_translator, session, url):
        svc = HTTPService(session, error_translator)

        session.request.side_effect = ValueError

        with pytest.raises(ValueError):
            svc.request("GET", url)
Esempio n. 3
0
    def test_with_custom_exceptions(self, error_translator, session, url):
        svc = HTTPService(session, error_translator)

        session.request.side_effect = FileNotFoundError

        with pytest.raises(NotADirectoryError):
            svc.request("GET", url)
Esempio n. 4
0
    def test_it_raises_if_sending_the_request_fails(self, exception, session):
        session.request.side_effect = exception
        svc = HTTPService(session)

        with pytest.raises(UpstreamServiceError) as exc_info:
            svc.request("GET", "https://example.com")

        assert exc_info.value.response is None
        assert exc_info.value.__cause__ == exception
Esempio n. 5
0
    def test_request_with_error_translator_defaults(
        self,
        error_translator,
        session,
        request_exception,
        expected_exception,
        url,
    ):
        svc = HTTPService(session, error_translator)

        session.request.side_effect = request_exception

        with pytest.raises(expected_exception):
            svc.request("GET", url)
Esempio n. 6
0
    def test_it_uses_custom_timeouts(self, session):
        svc = HTTPService(session)

        svc.request("GET", "https://example.com", timeout=3)

        assert session.request.call_args[1]["timeout"] == 3