コード例 #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"),
    )
コード例 #2
0
 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,
コード例 #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)
コード例 #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, [],