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 details)
Built Distribution
File details
Details for the file aiohttp-hijacks-0.0.1.tar.gz
.
File metadata
- Download URL: aiohttp-hijacks-0.0.1.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 913d717dbe080816cee5a33843cc655176ee3ee9458964b4ae05521dc5c22217 |
|
MD5 | 7da48f5c8d38a738a41e57e85c9974a6 |
|
BLAKE2b-256 | 40b1f13155390210bf3a9647d0208a7ff08215f36c8c2efc6c05f8bb25cad867 |
File details
Details for the file aiohttp_hijacks-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_hijacks-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb39909bbc58273be25ba303567521e91d676686e9cc8a5d86f6d8a02697a77a |
|
MD5 | dbb657410f8825f06e17225826db0510 |
|
BLAKE2b-256 | f89fe9ec48f8ffd1d11f35c6a77bbdcc93cf1a13c569382702d0c7a4e52b6f08 |