예제 #1
0
            finish,
        ],
        [(HttpMethods.GET, "/"), send_200, finish],
    ],
)
@curio_run
async def test_http_under_max_redirect(server):
    r = await asks.get(server.http_test_url + "/redirect_once",
                       max_redirects=2)
    assert r.status_code == 200


# Timeout tests


@Server(_TEST_LOC, steps=[delay(2), send_200, finish])
@curio_run
async def test_http_timeout_error(server):
    with pytest.raises(RequestTimeout):
        await asks.get(server.http_test_url, timeout=1)


@Server(_TEST_LOC, steps=[send_200, finish])
@curio_run
async def test_http_timeout(server):
    r = await asks.get(server.http_test_url, timeout=10)
    assert r.status_code == 200


# Param set test
예제 #2
0
파일: test_anyio.py 프로젝트: cauebs/asks
            ],
        ],
    )
],
                         indirect=True)
async def test_dont_follow_redirects(server):
    r = await asks.get(server.http_test_url + "/redirect_once",
                       follow_redirects=False)
    assert r.status_code == 303
    assert r.headers["location"] == "/"


# Timeout tests


@pytest.mark.parametrize('server', [dict(steps=[delay(2), send_200, finish])],
                         indirect=True)
async def test_http_timeout_error(server):
    with pytest.raises(RequestTimeout):
        await asks.get(server.http_test_url, timeout=1)


@pytest.mark.parametrize('server', [dict(steps=[send_200, finish])],
                         indirect=True)
async def test_http_timeout(server):
    r = await asks.get(server.http_test_url, timeout=10)
    assert r.status_code == 200


# Param set test
예제 #3
0
    delay,
    send_request_as_json,
    finish,
    HttpMethods,
)

import requests


if __name__ == "__main__":
    # Give the servers a location
    test_loc = ("localhost", 25001)

    # Wait one second and return the response as json

    Server(test_loc, steps=[delay(1), send_request_as_json, finish]).run()

    # HTTPS, same as above

    Server(
        test_loc,
        steps=[delay(1), send_request_as_json, finish],
        socket_wrapper=ssl_socket_wrapper,
    ).run()

    # Return a 404 with a custom body

    Server(test_loc, steps=[partial(send_404, data=b"Custom 404 page"), finish]).run()

    # Use Server as a decorator on a test!