from unittest import mock

from aioworkers.net.web.request import Request


async def test_content_length():
    r = Request(
        {"headers": [(b"Content-Length", b"1")]},
        receive=mock.Mock(),
        send=mock.Mock(),
        context=mock.Mock(),
        app=mock.Mock(),
    )
    assert r.content_length == 1


async def test_method():
    r = Request(
        {"method": "GET"},
        receive=mock.Mock(),
        send=mock.Mock(),
        context=mock.Mock(),
        app=mock.Mock(),
    )
    assert r.method == "GET"


async def test_url():
    r = Request(
        {
            "scheme": "http",
            "path": "/api",
            "query_string": b"a=yes",
        },
        receive=mock.Mock(),
        send=mock.Mock(),
        context=mock.Mock(),
        app=mock.Mock(),
    )
    assert r.url.query.get("a") == "yes"

@@ -20,16 +20,72 @@
 t mock%0A%0A
+from aioworkers.net.web.exceptions import HttpException%0A
 from aio
@@ -902,8 +902,689 @@
 = %22yes%22%0A
+%0A%0Aasync def test_response_simple():%0A    r = Request(%0A        %7B%7D,%0A        receive=mock.Mock(),%0A        send=mock.Mock(),%0A        context=mock.Mock(),%0A        app=mock.Mock(),%0A    )%0A    assert r.response()%0A    assert not r.response()%0A%0A%0Aasync def test_response_headers():%0A    r = Request(%0A        %7B%7D,%0A        receive=mock.Mock(),%0A        send=mock.Mock(),%0A        context=mock.Mock(),%0A        app=mock.Mock(),%0A    )%0A    assert r.response(headers=%5B(b%22H%22, b%22V%22)%5D)%0A%0A%0Aasync def test_response_exception():%0A    r = Request(%0A        %7B%7D,%0A        receive=mock.Mock(),%0A        send=mock.Mock(),%0A        context=mock.Mock(),%0A        app=mock.Mock(),%0A    )%0A    assert r.response(HttpException())%0A

improve tests of request