def test_retry_delay(): # Test invalid URL (to trigger retries) with 1s delay between retries request_config = {"RETRIES": 2, "RETRY_DELAY": 1} request = Request("http://127.0.0.1:5999/", request_config=request_config) # Start a timer to time retries timer = time.time() _, response = asyncio.get_event_loop().run_until_complete( request.fetch_callback(sem=sem)) # Ensure that for 2 retries the time taken is > 2s (1s between each retry) assert time.time() - timer > 2
def test_retry_request(): request = Request("http://httpbin.org/404") _, response = asyncio.get_event_loop().run_until_complete( request.fetch_callback(sem=sem) ) assert response.url == "http://httpbin.org/404"
async def hello(response): return "hello ruia" sem = asyncio.Semaphore(3) params = {"name": "ruia"} request = Request( "https://httpbin.org/get", method="GET", metadata={"hello": "ruia"}, params=params, callback=hello, ) _, response = asyncio.get_event_loop().run_until_complete( request.fetch_callback(sem)) def test_response(): url = response.url method = response.method encoding = response.encoding metadata = response.metadata cookies = response.cookies history = response.history headers = response.headers status = response.status text = asyncio.get_event_loop().run_until_complete(response.text()) json = asyncio.get_event_loop().run_until_complete(response.json()) read = asyncio.get_event_loop().run_until_complete(response.read())
async def hello(response): return "hello ruia" sem = asyncio.Semaphore(3) params = {"name": "ruia"} request = Request( "https://httpbin.org/get", method="GET", metadata={"hello": "ruia"}, params=params, callback=hello, ) _, response = asyncio.get_event_loop().run_until_complete(request.fetch_callback(sem)) def test_response(): url = response.url method = response.method encoding = response.encoding html = response.html metadata = response.metadata cookies = response.cookies history = response.history headers = response.headers status = response.status html_etree = response.html_etree text = asyncio.get_event_loop().run_until_complete(response.text())