Skip to content

Commit 0502885

Browse files
committed
Test fallback coroutine download_request
1 parent eb98634 commit 0502885

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ def assert_correct_response(response: HtmlResponse, request: Request) -> None:
6565
assert response.request is request
6666
assert response.url == request.url
6767
assert response.status == 200
68-
assert "playwright" in response.flags
68+
if "playwright" in request.meta:
69+
assert "playwright" in response.flags
70+
else:
71+
assert "playwright" not in response.flags

tests/tests_asyncio/test_playwright_requests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ async def test_basic_response(self):
6767
assert resp2.meta["playwright_page"].url == resp2.url
6868
await resp2.meta["playwright_page"].close()
6969

70+
@pytest.mark.skipif(not _SCRAPY_ASYNC_API, reason="Requires Scrapy async API")
71+
@allow_windows
72+
async def test_non_playwright_request_fallback(self):
73+
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
74+
req = Request("http://example.com") # non-playwright request
75+
with patch.object(
76+
handler.__class__.__bases__[0], "download_request", new_callable=AsyncMock
77+
) as mock_parent_download:
78+
await handler.download_request(req)
79+
mock_parent_download.assert_called_once_with(req)
80+
7081
@allow_windows
7182
async def test_post_request(self):
7283
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:

0 commit comments

Comments
 (0)