aiohttp-security/tests/test_no_auth.py

35 lines
940 B
Python
Raw Normal View History

from aiohttp import web
2015-11-19 11:53:38 +00:00
from aiohttp_security import authorized_userid, permits
2017-12-13 14:51:46 +00:00
async def test_authorized_userid(loop, test_client):
2017-12-13 14:51:46 +00:00
async def check(request):
userid = await authorized_userid(request)
2015-11-19 11:53:38 +00:00
assert userid is None
return web.Response()
2016-09-27 14:57:11 +00:00
app = web.Application(loop=loop)
2015-11-19 11:53:38 +00:00
app.router.add_route('GET', '/', check)
2017-12-13 14:51:46 +00:00
client = await test_client(app)
resp = await client.get('/')
2015-11-19 11:53:38 +00:00
assert 200 == resp.status
2017-12-13 14:51:46 +00:00
async def test_permits(loop, test_client):
2017-12-13 14:51:46 +00:00
async def check(request):
ret = await permits(request, 'read')
2015-11-19 11:53:38 +00:00
assert ret
2017-12-13 14:51:46 +00:00
ret = await permits(request, 'write')
2015-11-19 11:53:38 +00:00
assert ret
2017-12-13 14:51:46 +00:00
ret = await permits(request, 'unknown')
2015-11-19 11:53:38 +00:00
assert ret
return web.Response()
2016-09-27 14:57:11 +00:00
app = web.Application(loop=loop)
2015-11-19 11:53:38 +00:00
app.router.add_route('GET', '/', check)
2017-12-13 14:51:46 +00:00
client = await test_client(app)
resp = await client.get('/')
2015-11-19 11:53:38 +00:00
assert 200 == resp.status