Пример #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
            ],
        ],
    )
],
                         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!