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
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
async def test_nested_iterables_raise_missing_converter_from_header( declared_type): with raises(MissingConverterError): FromHeader(declared_type)
def home(request, xx: FromHeader(str)): assert xx == 'Hello World'
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)
def handler(a: FromHeader(str, 'example')): pass
def handler(a: FromQuery(List[str]), b: FromServices(Dog), c: FromJson(Cat), d: FromRoute(), e: FromHeader()): pass