adding decorator and demo code
This commit is contained in:
@@ -15,10 +15,6 @@ class Autz(AbstractAuthorizationPolicy):
|
||||
def permits(self, identity, permission, context=None):
|
||||
pass
|
||||
|
||||
@asyncio.coroutine
|
||||
def authorized_userid(self, identity):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.run_loop
|
||||
def test_remember(create_app_and_client):
|
||||
|
||||
@@ -2,8 +2,7 @@ import asyncio
|
||||
import pytest
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp_security import (remember,
|
||||
authorized_userid, permits,
|
||||
from aiohttp_security import (remember, permits, get_user_identity,
|
||||
AbstractAuthorizationPolicy)
|
||||
from aiohttp_security import setup as _setup
|
||||
from aiohttp_security.cookies_identity import CookiesIdentityPolicy
|
||||
@@ -18,12 +17,14 @@ class Autz(AbstractAuthorizationPolicy):
|
||||
else:
|
||||
return False
|
||||
|
||||
'''
|
||||
@asyncio.coroutine
|
||||
def authorized_userid(self, identity):
|
||||
if identity == 'UserID':
|
||||
return 'Andrew'
|
||||
else:
|
||||
return None
|
||||
'''
|
||||
|
||||
|
||||
@pytest.mark.run_loop
|
||||
@@ -32,12 +33,12 @@ def test_authorized_userid(create_app_and_client):
|
||||
@asyncio.coroutine
|
||||
def login(request):
|
||||
response = web.HTTPFound(location='/')
|
||||
yield from remember(request, response, 'UserID')
|
||||
yield from remember(request, response, 'Andrew')
|
||||
return response
|
||||
|
||||
@asyncio.coroutine
|
||||
def check(request):
|
||||
userid = yield from authorized_userid(request)
|
||||
userid = yield from get_user_identity(request)
|
||||
assert 'Andrew' == userid
|
||||
return web.Response(text=userid)
|
||||
|
||||
@@ -58,7 +59,7 @@ def test_authorized_userid_not_authorized(create_app_and_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def check(request):
|
||||
userid = yield from authorized_userid(request)
|
||||
userid = yield from get_user_identity(request)
|
||||
assert userid is None
|
||||
return web.Response()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import asyncio
|
||||
import pytest
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp_security import authorized_userid, permits
|
||||
from aiohttp_security import permits, get_user_identity
|
||||
|
||||
|
||||
@pytest.mark.run_loop
|
||||
@@ -10,7 +10,7 @@ def test_authorized_userid(create_app_and_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def check(request):
|
||||
userid = yield from authorized_userid(request)
|
||||
userid = yield from get_user_identity(request)
|
||||
assert userid is None
|
||||
return web.Response()
|
||||
|
||||
|
||||
@@ -17,10 +17,6 @@ class Autz(AbstractAuthorizationPolicy):
|
||||
def permits(self, identity, permission, context=None):
|
||||
pass
|
||||
|
||||
@asyncio.coroutine
|
||||
def authorized_userid(self, identity):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def create_app_and_client2(create_app_and_client):
|
||||
|
||||
Reference in New Issue
Block a user