Exemplo n.º 1
0
def test_request_info_with_fragment(make_request: Any) -> None:
    req = make_request("get", "http://python.org/#urlfragment")
    assert req.request_info == aiohttp.RequestInfo(
        URL("http://python.org/"),
        "GET",
        req.headers,
        URL("http://python.org/#urlfragment"),
    )
 def maybe_fail(self, method, path, headers):
     if self.should_fail():
         raise aiohttp.ClientResponseError(
             status=503,
             message=
             'Service Unavailable from FailureInjectingClientSession',
             request_info=aiohttp.RequestInfo(url=path,
                                              method=method,
                                              headers=headers,
                                              real_url=path),
             history=())
Exemplo n.º 3
0
def test_request_info_with_fragment(make_request) -> None:
    req = make_request('get', 'http://python.org/#urlfragment')
    assert req.request_info == aiohttp.RequestInfo(
        URL('http://python.org/'), 'GET', req.headers,
        URL('http://python.org/#urlfragment'))
Exemplo n.º 4
0
def test_request_info(make_request) -> None:
    req = make_request('get', 'http://python.org/')
    assert req.request_info == aiohttp.RequestInfo(URL('http://python.org/'),
                                                   'GET', req.headers)
Exemplo n.º 5
0
 def request_info(self) -> aiohttp.RequestInfo:
     """Return a container with generic request information."""
     return aiohttp.RequestInfo(self.real_url, 'get', {})  # type: ignore
Exemplo n.º 6
0
import asyncio
from http import HTTPStatus

import aiohttp
import pytest
from multidict import CIMultiDict, CIMultiDictProxy
from yarl import URL

from galaxy.api.errors import (AccessDenied, AuthenticationRequired,
                               BackendTimeout, BackendNotAvailable,
                               BackendError, NetworkError, TooManyRequests,
                               UnknownBackendResponse, UnknownError)
from galaxy.http import handle_exception

request_info = aiohttp.RequestInfo(URL("http://o.pl"), "GET",
                                   CIMultiDictProxy(CIMultiDict()))


@pytest.mark.parametrize(
    "aiohttp_exception,expected_exception_type",
    [(asyncio.TimeoutError(), BackendTimeout),
     (aiohttp.ServerDisconnectedError(), BackendNotAvailable),
     (aiohttp.ClientConnectionError(), NetworkError),
     (aiohttp.ContentTypeError(request_info, ()), UnknownBackendResponse),
     (aiohttp.ClientResponseError(
         request_info,
         (), status=HTTPStatus.UNAUTHORIZED), AuthenticationRequired),
     (aiohttp.ClientResponseError(request_info, (),
                                  status=HTTPStatus.FORBIDDEN), AccessDenied),
     (aiohttp.ClientResponseError(
         request_info,
Exemplo n.º 7
0
def test_request_info(make_request: Any) -> None:
    req = make_request("get", "http://python.org/")
    assert req.request_info == aiohttp.RequestInfo(URL("http://python.org/"),
                                                   "GET", req.headers)
Exemplo n.º 8
0
import asyncio
from http import HTTPStatus

import aiohttp
import pytest

from galaxy.api.errors import (AccessDenied, AuthenticationRequired,
                               BackendTimeout, BackendNotAvailable,
                               BackendError, NetworkError, TooManyRequests,
                               UnknownBackendResponse, UnknownError)
from galaxy.http import handle_exception

request_info = aiohttp.RequestInfo("http://o.pl", "GET", {})


@pytest.mark.parametrize(
    "aiohttp_exception,expected_exception_type",
    [(asyncio.TimeoutError(), BackendTimeout),
     (aiohttp.ServerDisconnectedError(), BackendNotAvailable),
     (aiohttp.ClientConnectionError(), NetworkError),
     (aiohttp.ContentTypeError(request_info, []), UnknownBackendResponse),
     (aiohttp.ClientResponseError(
         request_info, [],
         status=HTTPStatus.UNAUTHORIZED), AuthenticationRequired),
     (aiohttp.ClientResponseError(request_info, [],
                                  status=HTTPStatus.FORBIDDEN), AccessDenied),
     (aiohttp.ClientResponseError(
         request_info, [],
         status=HTTPStatus.SERVICE_UNAVAILABLE), BackendNotAvailable),
     (aiohttp.ClientResponseError(
         request_info, [],