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=())
示例#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'))
示例#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)
示例#5
0
 def request_info(self) -> aiohttp.RequestInfo:
     """Return a container with generic request information."""
     return aiohttp.RequestInfo(self.real_url, 'get', {})  # type: ignore
示例#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,
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)
示例#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, [],