예제 #1
0
파일: test_ant.py 프로젝트: xxtlyf/ant_nest
async def test_with_real_request():
    httpbin_base_url = os.getenv("TEST_HTTPBIN", "http://*****:*****@localhost:3128")
    ant.request_proxies.append(proxy)
    res = await ant.request("http://httpbin.org/anything")
    assert res.status == 200
    # no proxy anymore
    ant.request_proxies.pop()
    res = await ant.request("http://httpbin.org/anything")
    assert res.status == 200
    # set proxy by request
    res = await ant.request("http://httpbin.org/anything", proxy=proxy)
    assert res.status == 200
    # with stream
    ant.response_in_stream = True
    res = await ant.request(httpbin_base_url + "anything")
    assert res.status == 200
    with pytest.raises(ValueError):
        getattr(res, "simple_text")
    while True:
        chunk = await res.content.read(10)
        if len(chunk) == 0:
            break
    # set streaming by request
    res = await ant.request(httpbin_base_url + "anything",
                            response_in_stream=False)
    assert res.status == 200
    assert res.simple_text is not None

    await ant.close()
예제 #2
0
async def test_with_real_request():
    httpbin_base_url = os.getenv('TEST_HTTPBIN', 'http://*****:*****@localhost:3128')
    ant.request_proxies.append(proxy)
    res = await ant.request('http://httpbin.org/anything')
    assert res.status == 200
    # no proxy anymore
    ant.request_proxies.pop()
    res = await ant.request('http://httpbin.org/anything')
    assert res.status == 200
    # set proxy by request
    res = await ant.request('http://httpbin.org/anything', proxy=proxy)
    assert res.status == 200
    # with stream
    ant.response_in_stream = True
    res = await ant.request(httpbin_base_url + 'anything')
    assert res.status == 200
    with pytest.raises(ValueError):
        res.simple_text
    while True:
        chunk = await res.content.read(10)
        if len(chunk) == 0:
            break
    # set streaming by request
    res = await ant.request(httpbin_base_url + 'anything',
                            response_in_stream=False)
    assert res.status == 200
    assert res.simple_text is not None

    await ant.close()