Esempio n. 1
0
async def test_from_query_raises_for_invalid_parameter(expected_type,
                                                       invalid_value: bytes):
    request = Request("GET", b"/?foo=" + invalid_value, None)

    parameter = QueryBinder(expected_type, "foo", required=True)

    with raises(BadRequest):
        await parameter.get_value(request)
Esempio n. 2
0
async def test_from_query_binding(expected_type, query_value, expected_value):
    request = Request("GET", b"/?foo=" + query_value, None)

    parameter = QueryBinder(expected_type, "foo")

    value = await parameter.get_value(request)

    assert isinstance(value, expected_type)
    assert value == expected_value
Esempio n. 3
0
async def test_from_query_binding_iterables(declared_type, expected_type,
                                            query_values, expected_values):
    qs = b"&foo=".join([value for value in query_values])

    request = Request("GET", b"/?foo=" + qs, None)

    parameter = QueryBinder(declared_type, "foo")

    values = await parameter.get_value(request)

    assert isinstance(values, expected_type)
    assert values == expected_values
Esempio n. 4
0
async def test_nested_iterables_raise_missing_converter_from_query(
        declared_type):
    with raises(MissingConverterError):
        QueryBinder("example", declared_type)
Esempio n. 5
0
def test_sync_binders_source_name():
    assert CookieBinder().source_name == "cookie"
    assert HeaderBinder().source_name == "header"
    assert QueryBinder().source_name == "query"
    assert RouteBinder().source_name == "route"