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

import asyncio

from aiohttp import web
from webtest_aiohttp import TestApp

loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)

app = web.Application(loop=loop)

@asyncio.coroutine
def hello(request):
    return web.Response(body=json.dumps(
        {'message': 'Hello world'}
    ).encode('utf-8'), content_type='application/json')

app.router.add_route('GET', '/', handler)


def test_hello():
    client = TestApp(app)
    res = client.get('/')
    assert res.status_code == 200
    assert res.json == {'message': 'Hello world'}

Installation

pip install webtest-aiohttp

Credits

This code was adapted from Kirill Klenov’s muffin library.

License

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

Supported by

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