Пример #1
0
async def test_from_header_binding(expected_type, header_value, expected_value):

    request = Request('GET', b'/', [(b'X-Foo', header_value)])

    parameter = FromHeader(expected_type, 'X-Foo')

    value = await parameter.get_value(request)

    assert isinstance(value, expected_type)
    assert value == expected_value
Пример #2
0
async def test_from_header_binding_iterables(declared_type, expected_type,
                                             header_values, expected_values):

    request = Request('GET', b'/',
                      [(b'X-Foo', value) for value in header_values])

    parameter = FromHeader(declared_type, 'X-Foo')

    value = await parameter.get_value(request)

    assert isinstance(value, expected_type)
    assert value == expected_values
Пример #3
0
async def test_nested_iterables_raise_missing_converter_from_header(
        declared_type):
    with raises(MissingConverterError):
        FromHeader(declared_type)
Пример #4
0
 def home(request, xx: FromHeader(str)):
     assert xx == 'Hello World'
Пример #5
0
 async def middleware(request, handler, example: FromHeader(str)):
     assert request is fake_request
     assert handler is fake_handler
     assert example == 'Lorem'
     return await handler(request)
Пример #6
0
 def handler(a: FromHeader(str, 'example')):
     pass
Пример #7
0
 def handler(a: FromQuery(List[str]), b: FromServices(Dog),
             c: FromJson(Cat), d: FromRoute(), e: FromHeader()):
     pass