aiohttp-security/tests/test_no_auth.py

43 lines
1.1 KiB
Python
Raw Normal View History

import asyncio
from aiohttp import web
2015-11-19 11:53:38 +00:00
from aiohttp_security import authorized_userid, permits
2016-09-27 14:57:11 +00:00
@asyncio.coroutine
def test_authorized_userid(loop, test_client):
@asyncio.coroutine
2015-11-19 11:53:38 +00:00
def check(request):
userid = yield from authorized_userid(request)
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)
2016-09-27 14:57:11 +00:00
client = yield from test_client(app)
2015-11-19 11:53:38 +00:00
resp = yield from client.get('/')
assert 200 == resp.status
yield from resp.release()
2016-09-27 14:57:11 +00:00
@asyncio.coroutine
def test_permits(loop, test_client):
2015-11-19 11:53:38 +00:00
@asyncio.coroutine
def check(request):
ret = yield from permits(request, 'read')
assert ret
ret = yield from permits(request, 'write')
assert ret
ret = yield from permits(request, 'unknown')
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)
2016-09-27 14:57:11 +00:00
client = yield from test_client(app)
2015-11-19 11:53:38 +00:00
resp = yield from client.get('/')
assert 200 == resp.status
yield from resp.release()