Skip to main content

webtest-aiohttp provides integration of WebTest with aiohttp.web applications

Project description

Latest version Travis-CI

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'}

License

MIT licensed. See the bundled LICENSE file for more details.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page