webtest-aiohttp provides integration of WebTest with aiohttp.web applications
Project description
webtest-aiohttp provides integration of WebTest with aiohttp.web applications.
Supports aiohttp>=2.3.8.
from aiohttp import web
from webtest_aiohttp import TestApp
app = web.Application()
async def hello(request):
return web.json_response({'message': 'Hello world'})
app.router.add_route('GET', '/', handler)
def test_hello(loop):
client = TestApp(app, loop=loop)
res = client.get('/')
assert res.status_code == 200
assert res.json == {'message': 'Hello world'}
Installation
pip install webtest-aiohttp
Note: If you are using aiohttp<2.0.0, you will need to install webtest-aiohttp 1.x.
pip install 'webtest-aiohttp<2.0.0'
Usage with pytest
If you are using pytest and pytest-aiohttp, you can make your tests more concise with a fixture.
from aiohttp import web
from webtest_aiohttp import TestApp as WebTestApp
app = web.Application()
async def hello(request):
return web.json_response({'message': 'Hello world'})
app.router.add_route('GET', '/', handler)
@pytest.fixture()
def testapp(loop):
return WebTestApp(app, loop=loop)
def test_get(testapp):
assert testapp.get('/').json == {'message': 'Hello world'}
Project Links
License
MIT licensed. See the bundled LICENSE file for more details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
webtest-aiohttp-2.0.0.tar.gz
(8.4 kB
view details)
Built Distribution
File details
Details for the file webtest-aiohttp-2.0.0.tar.gz
.
File metadata
- Download URL: webtest-aiohttp-2.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e2a2f13078c3f1f23ccebef03de4d6d118d096cd6e9d0d190e359d9ffb11f8 |
|
MD5 | 768c20c45e4f29c07c131cf5a93a9ebe |
|
BLAKE2b-256 | 1f469c3f326522b83253b7156007c96977d6bb5fcf78b1dcb1da1b928ab876b8 |
Provenance
File details
Details for the file webtest_aiohttp-2.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: webtest_aiohttp-2.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8fc39fd73f30bb56c8b990e6a70ca477522f5b1a91b3b6c91401ecbca750847 |
|
MD5 | b1578608c5c2c9a436de3e375c2260cf |
|
BLAKE2b-256 | f4646ac160e44859602962495e0d52ef8bac1e244c48365b38d7424d2dc70222 |