33import pytest
44from web_poet .page_inputs import ResponseData
55from web_poet .requests import (
6- GenericRequest ,
6+ Request ,
77 perform_request ,
88 HttpClient ,
99 RequestBackendError ,
@@ -25,13 +25,13 @@ async def async_test(req):
2525
2626def test_generic_request ():
2727
28- req = GenericRequest ("url" )
28+ req = Request ("url" )
2929 assert req .url == "url"
3030 assert req .method == "GET"
3131 assert req .headers is None
3232 assert req .body is None
3333
34- req = GenericRequest (
34+ req = Request (
3535 "url" , method = "POST" , headers = {"User-Agent" : "test agent" }, body = b"body"
3636 )
3737 assert req .method == "POST"
@@ -42,7 +42,7 @@ def test_generic_request():
4242@pytest .mark .asyncio
4343async def test_perform_request (async_mock ):
4444
45- req = GenericRequest ("url" )
45+ req = Request ("url" )
4646
4747 with pytest .raises (RequestBackendError ):
4848 await perform_request (req )
@@ -56,16 +56,36 @@ async def test_perform_request(async_mock):
5656
5757
5858@pytest .mark .asyncio
59- async def test_http_client (async_mock ):
59+ async def test_http_client_single_requests (async_mock ):
6060 client = HttpClient (async_mock )
6161 assert client .request_downloader == async_mock
6262
63- req_1 = GenericRequest ("url-1" )
64- req_2 = GenericRequest ("url-2" )
63+ with mock .patch ("web_poet.requests.Request" ) as mock_request :
64+ response = await client .request ("url" )
65+ response .url == "url"
6566
66- # It should be able to accept arbitrary number of requests
67- client .request (req_1 )
68- responses = await client .request (req_1 , req_2 )
67+ response = await client .get ("url-get" )
68+ response .url == "url-get"
6969
70- assert responses [0 ].url == req_1 .url
71- assert responses [1 ].url == req_2 .url
70+ response = await client .post ("url-post" )
71+ response .url == "url-post"
72+
73+ assert mock_request .call_args_list == [
74+ mock .call ("url" , "GET" , None , None ),
75+ mock .call ("url-get" , "GET" , None , None ),
76+ mock .call ("url-post" , "POST" , None , None ),
77+ ]
78+
79+
80+ @pytest .mark .asyncio
81+ async def test_http_client_batch_requests (async_mock ):
82+ client = HttpClient (async_mock )
83+
84+ requests = [
85+ Request ("url-1" ),
86+ Request ("url-get" , method = "GET" ),
87+ Request ("url-post" , method = "POST" ),
88+ ]
89+ responses = await client .batch_requests (* requests )
90+
91+ assert all ([isinstance (response , ResponseData ) for response in responses ])
0 commit comments