2015-08-05 10:32:49 +00:00
|
|
|
import asyncio
|
2015-11-19 12:17:34 +00:00
|
|
|
import pytest
|
2015-08-05 10:32:49 +00:00
|
|
|
|
|
|
|
from aiohttp import web
|
|
|
|
from aiohttp_security import remember, forget
|
|
|
|
|
|
|
|
|
2015-11-19 12:17:34 +00:00
|
|
|
@pytest.mark.run_loop
|
|
|
|
def test_remember(create_app_and_client):
|
2015-08-05 10:32:49 +00:00
|
|
|
|
|
|
|
@asyncio.coroutine
|
2015-11-19 12:17:34 +00:00
|
|
|
def do_remember(request):
|
|
|
|
response = web.Response()
|
|
|
|
yield from remember(request, response, 'Andrew')
|
2015-08-05 10:32:49 +00:00
|
|
|
|
2015-11-19 12:17:34 +00:00
|
|
|
app, client = yield from create_app_and_client()
|
|
|
|
app.router.add_route('POST', '/', do_remember)
|
|
|
|
resp = yield from client.post('/')
|
|
|
|
assert 500 == resp.status
|
|
|
|
assert (('Security subsystem is not initialized, '
|
|
|
|
'call aiohttp_security.setup(...) first') ==
|
|
|
|
resp.reason)
|
|
|
|
yield from resp.release()
|
2015-08-05 10:32:49 +00:00
|
|
|
|
|
|
|
|
2015-11-19 12:17:34 +00:00
|
|
|
@pytest.mark.run_loop
|
|
|
|
def test_forget(create_app_and_client):
|
2015-08-05 10:32:49 +00:00
|
|
|
|
2015-11-19 12:17:34 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def do_forget(request):
|
|
|
|
response = web.Response()
|
|
|
|
yield from forget(request, response)
|
|
|
|
|
|
|
|
app, client = yield from create_app_and_client()
|
|
|
|
app.router.add_route('POST', '/', do_forget)
|
|
|
|
resp = yield from client.post('/')
|
|
|
|
assert 500 == resp.status
|
|
|
|
assert (('Security subsystem is not initialized, '
|
|
|
|
'call aiohttp_security.setup(...) first') ==
|
|
|
|
resp.reason)
|
|
|
|
yield from resp.release()
|