Re-route aiohttp session requests. Usefull for testing.
Project description
aiohttp-hijacks
Hijack aiohttp session to re-route the requests.
from aiohttp_hijacks import FakeServer, FakeSession, route
class Server(FakeServer):
""" Application that will respond to the client. """
@route('/')
async def get_abc(self, request):
self.calls += 1
return self.json_response({"status": "ok"})
# Reroute google.com → 127.0.0.1
async with Server() as server: # instantiate Server handling '127.0.0.1:{server.port}/abc'
async with FakeSession(reroute={'google.com': server.port}) as session:
# redirecting calls to http(s)://google.com to 127.0.0.1:{server.port}
resp = await session.get("https://google.com")
data = await resp.json()
assert data == {"status": "ok"}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiohttp-hijacks-0.0.1.tar.gz
(22.0 kB
view hashes)
Built Distribution
Close
Hashes for aiohttp_hijacks-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb39909bbc58273be25ba303567521e91d676686e9cc8a5d86f6d8a02697a77a |
|
MD5 | dbb657410f8825f06e17225826db0510 |
|
BLAKE2b-256 | f89fe9ec48f8ffd1d11f35c6a77bbdcc93cf1a13c569382702d0c7a4e52b6f08 |