Skip to content

Commit

Permalink
🩹 don't patch patches in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshix-1 committed Jan 17, 2024
1 parent e9ea740 commit 76264b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

from an_website import patches

patches.patch_tornado_httpclient = lambda: None

patches.apply()


Expand Down Expand Up @@ -197,7 +195,9 @@ def fetch(
parse_wrong_quote(WRONG_QUOTE_DATA)
host = f"http://127.0.0.1:{http_server_port[1]}"

async def _fetch(url: str, **kwargs: Any) -> HTTPResponse:
async def _fetch(
url: str, *, httpclient: None | AsyncHTTPClient = None, **kwargs: Any
) -> HTTPResponse:
"""Fetch a URL."""
if not url.startswith(("http://", "https://")):
url = f"{host}/{url.removeprefix('/')}"
Expand All @@ -207,7 +207,7 @@ async def _fetch(url: str, **kwargs: Any) -> HTTPResponse:
kwargs["headers"] = {}
kwargs["headers"].setdefault("Accept", "text/html, */*")
try:
return await http_client.fetch(url, **kwargs)
return await (httpclient or http_client).fetch(url, **kwargs)
except HTTPClientError:
print(url, kwargs)
raise
Expand Down
20 changes: 17 additions & 3 deletions tests/test_request_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from datetime import datetime

from time_machine import travel
from tornado.simple_httpclient import SimpleAsyncHTTPClient

from . import ( # noqa: F401 # pylint: disable=unused-import
FetchCallable,
Expand Down Expand Up @@ -100,13 +101,26 @@ async def test_not_found_handler(fetch: FetchCallable) -> None: # noqa: F811
await assert_valid_redirect(fetch, "/servces?x=y", "/services?x=y", {307})

await assert_valid_redirect(
fetch, "/vertauschtewörter", "/vertauschte-woerter", {307}
fetch,
"/vertauschtewörter",
"/vertauschte-woerter",
{307},
httpclient=SimpleAsyncHTTPClient(),
)

await assert_valid_redirect(
fetch, "/vertauschtew%C3%B6rter", "/vertauschte-woerter", {307}
fetch,
"/vertauschtew%C3%B6rter",
"/vertauschte-woerter",
{307},
httpclient=SimpleAsyncHTTPClient(),
)
await assert_valid_redirect(
fetch, "/vertauschte-w%F6rter", "/vertauschte-woerter", {307}
fetch,
"/vertauschte-w%F6rter",
"/vertauschte-woerter",
{307},
httpclient=SimpleAsyncHTTPClient(),
)

await assert_valid_redirect(fetch, "/a?x=y", "/?x=y", {307})
Expand Down

0 comments on commit 76264b5

Please sign in to comment.