跳转到主要内容

webtest-aiohttp为WebTest与aiohttp.web应用程序提供集成

项目描述

Latest version Travis-CI

webtest-aiohttp为WebTest与aiohttp.web应用程序提供集成。

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

安装

pip install webtest-aiohttp

注意:如果您正在使用aiohttp<2.0.0,则需要安装webtest-aiohttp 1.x。

pip install 'webtest-aiohttp<2.0.0'

与pytest一起使用

如果您正在使用pytest和pytest-aiohttp,您可以使用 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'}

许可

MIT许可。有关更多详细信息,请参阅捆绑的 LICENSE 文件。

项目详情


下载文件

下载适合您平台的自定义文件。如果您不确定要选择哪个,请了解有关 安装软件包 的更多信息。

源分布

webtest-aiohttp-2.0.0.tar.gz (8.4 kB 查看哈希)

上传于

构建分发

webtest_aiohttp-2.0.0-py2.py3-none-any.whl (4.8 kB 查看哈希值)

上传于 Python 2 Python 3

由以下支持