コード例 #1
0
async def test_bool(test_client):
    def handler(b):
        return web.json_response(b)

    r = SwaggerRouter()
    r.add_get('/',
              handler=handler,
              swagger_data={
                  'parameters': [{
                      'name': 'b',
                      'in': 'query',
                      'type': 'boolean',
                      'default': False,
                  }]
              })
    app = web.Application(router=r)
    client = await test_client(app)
    r = await client.get('/?b=True')
    assert r.status == 200, (await r.text())
    assert (await r.json()) is True
    r = await client.get('/?b=')
    assert r.status == 200, (await r.text())
    assert (await r.json()) is True
    r = await client.get('/?b')
    assert r.status == 200, (await r.text())
    assert (await r.json()) is True
    r = await client.get('/')
    assert r.status == 200, (await r.text())
    assert (await r.json()) is False
コード例 #2
0
async def test_validation_errors_constructor(test_client):
    def handler(request):
        raise ValidationError('', r=[''], q='')

    r = SwaggerRouter()
    r.add_get('/', handler=handler)
    app = web.Application(router=r)
    client = await test_client(app)
    r = await client.get('/')
    assert r.status == 400, (await r.text())