Пример #1
0
async def test_from_body_form_binding_multipart():

    request = Request("POST", b"/", []).with_content(
        MultiPartFormData([FormPart(b"a", b"world"),
                           FormPart(b"b", b"9000")]))

    parameter = FormBinder(ExampleOne)
    value = await parameter.get_value(request)

    assert isinstance(value, ExampleOne)
    assert value.a == "world"
    assert value.b == 9000
Пример #2
0
async def test_from_body_form_binding_urlencoded_keys_duplicates():

    request = Request("POST", b"/", []).with_content(
        FormContent([("a", "world"), ("b", "one"), ("b", "two"),
                     ("b", "three")]))

    parameter = FormBinder(ExampleThree)

    value = await parameter.get_value(request)

    assert isinstance(value, ExampleThree)
    assert value.a == "world"
    assert value.b == ["one", "two", "three"]
Пример #3
0
async def test_from_body_form_binding_urlencoded():

    request = Request("POST", b"/", []).with_content(
        FormContent({"a": "world", "b": 9000})
    )

    parameter = FormBinder(ExampleOne)

    value = await parameter.get_value(request)

    assert isinstance(value, ExampleOne)
    assert value.a == "world"
    assert value.b == 9000
Пример #4
0
async def test_from_body_form_binding_multipart_keys_duplicates():

    request = Request("POST", b"/", []).with_content(
        MultiPartFormData([
            FormPart(b"a", b"world"),
            FormPart(b"b", b"one"),
            FormPart(b"b", b"two"),
            FormPart(b"b", b"three"),
        ]))

    parameter = FormBinder(ExampleThree)

    value = await parameter.get_value(request)

    assert isinstance(value, ExampleThree)
    assert value.a == "world"
    assert value.b == ["one", "two", "three"]