Beispiel #1
0
async def group(number, duration):
    acurl_el = acurl.EventLoop()
    requests = duration_generator('http://localhost:9003', duration)
    results = await asyncio.gather(
        *[runner(acurl_el, requests) for i in range(number)])
    acurl_el.stop()
    return sum(results)
Beispiel #2
0
async def test_max_redirects_raises(httpserver):
    httpserver.expect_oneshot_request("/test", "GET").respond_with_response(
        WZResponse(status=301, headers={"Location": "/test2"}))

    loop = acurl.EventLoop()
    s = loop.session()
    with pytest.raises(acurl.RequestError):
        await s.get(httpserver.url_for("/test"), max_redirects=0)
Beispiel #3
0
async def test_get(httpserver):
    httpserver.expect_oneshot_request("/test", "GET").respond_with_data("hi")
    loop = acurl.EventLoop()
    s = loop.session()
    r = await s.get(httpserver.url_for("/test"))

    assert isinstance(r, acurl.Response)
    assert r.request.method == "GET"
    assert r.body == b"hi"
    httpserver.check_assertions()
Beispiel #4
0
async def test_disallow_redirects(httpserver):
    httpserver.expect_oneshot_request("/test", "GET").respond_with_response(
        WZResponse(status=301, headers={"Location": "/test2"}))

    loop = acurl.EventLoop()
    s = loop.session()
    r = await s.get(httpserver.url_for("/test"), allow_redirects=False)

    assert r.status_code == 301
    assert r.headers["Location"].endswith("/test2")
Beispiel #5
0
    def __init__(self, use_new_acurl_implementation=False):
        if use_new_acurl_implementation:
            import acurl_ng

            self._wrapper = acurl_ng.CurlWrapper(asyncio.get_event_loop())
        else:
            import acurl

            self._wrapper = acurl.EventLoop()
        self._pool = deque()
Beispiel #6
0
async def test_response_cookies(httpserver):
    hdrs = Headers()
    hdrs.add("Set-Cookie", "foo=bar")
    hdrs.add("Set-Cookie", "quux=xyzzy")
    httpserver.expect_request("/foo").respond_with_response(
        Response(response="", status=200, headers=hdrs))
    el = acurl.EventLoop()
    el._run_in_thread()
    s = el.session()
    r = await s.get(httpserver.url_for("/foo"))
    assert r.cookies == {"foo": "bar", "quux": "xyzzy"}
Beispiel #7
0
async def test_post_json(httpserver):
    httpserver.expect_oneshot_request(
        "/test", "POST", data='{"foo":"bar"}').respond_with_data("hi")
    loop = acurl.EventLoop()
    s = loop.session()

    r = await s.post(httpserver.url_for("/test"), json={"foo": "bar"})

    assert isinstance(r, acurl.Response)
    assert r.request.method == "POST"
    assert r.body == b"hi"
    httpserver.check_assertions()
Beispiel #8
0
async def test_redirect(httpserver):
    httpserver.expect_oneshot_request("/test", "GET").respond_with_response(
        WZResponse(status=301, headers={"Location": "/test2"}))
    httpserver.expect_oneshot_request("/test2", "GET").respond_with_data("hi")

    loop = acurl.EventLoop()
    s = loop.session()
    r = await s.get(httpserver.url_for("/test"))

    assert r.body == b"hi"
    assert r.url == httpserver.url_for("/test2")
    assert r._prev.url == httpserver.url_for("/test")
    assert len(r.history) == 1
Beispiel #9
0
async def test_response_callback(httpserver):
    httpserver.expect_oneshot_request("/test", "GET").respond_with_data("hi")
    loop = acurl.EventLoop()
    s = loop.session()
    called = False

    def response_cb(resp):
        nonlocal called
        if called:
            raise Exception("called too many times")
        assert isinstance(resp, acurl.Response)
        called = True

    s.set_response_callback(response_cb)
    await s.get(httpserver.url_for("/test"))
    assert called
    httpserver.check_assertions()
Beispiel #10
0
def session():
    el = acurl.EventLoop()
    return el.session()
Beispiel #11
0
async def test_request_no_data_raises():
    loop = acurl.EventLoop()
    s = loop.session()
    with pytest.raises(ValueError):
        await s.request("GET", "http://foo.com", json={}, data="")
Beispiel #12
0
async def test_invalid_method_raises():
    loop = acurl.EventLoop()
    s = loop.session()
    with pytest.raises(ValueError):
        await s.request("FOO", "http://foo.com")