44from urllib .parse import urlsplit , urlunsplit
55
66import pytest
7- from aioresponses import aioresponses
7+ from aiointercept import aiointercept
88
99from telescope import config as global_config
1010from telescope import utils
@@ -61,10 +61,10 @@ async def config():
6161
6262
6363@pytest .fixture
64- def mock_aioresponses (cli ):
64+ async def mock_aioresponses (cli ):
6565 test_server = f"http://{ cli .host } :{ cli .port } "
66- with aioresponses ( passthrough = [test_server ]) as m :
67- # `aioresponses ` matches URLs including query parameters.
66+ async with aiointercept ( mock_external_urls = True , passthrough = [test_server ]) as m :
67+ # `aiointercept ` matches URLs including query parameters.
6868 # This monkeypatch makes it ignore them, so that a mock at
6969 # `/endpoint` will match a request done at `/endpoint?param=value`.
7070 original_add = m .add
@@ -75,8 +75,9 @@ def new_add(url, *args, **kwargs):
7575 scheme , netloc , path , query , _ = urlsplit (url )
7676 if not query :
7777 base_url = urlunsplit ((scheme , netloc , path , "" , "" ))
78- # ^base(?:\?.*)?$ → base, optionally followed by ?...
79- url = re .compile (re .escape (base_url ) + r"(?:\?.*)?$" )
78+ # ^base/?(?:\?.*)?$ → base, optional trailing slash,
79+ # optionally followed by ?...
80+ url = re .compile (re .escape (base_url ) + r"/?(?:\?.*)?$" )
8081 return original_add (url , * args , ** kwargs )
8182
8283 m .add = new_add # ty: ignore[invalid-assignment]
0 commit comments