@ -82,15 +82,9 @@ def test_get_user_no_unauthenticated_user_id():
@@ -82,15 +82,9 @@ def test_get_user_no_unauthenticated_user_id():
assert get_user ( request ) is None
@pytest . mark . parametrize (
' user_id ' , [
3 , # active user, must work
pytest . mark . xfail ( 1 ) , # inactive user, must fail
pytest . mark . xfail ( 1969 ) , # unknown user id, must fail
]
)
def test_get_user_no_unauthenticated_user_id ( user_id , dbsession ) :
''' get_user() should return None if unauthenticated_userid is None '''
@pytest . mark . parametrize ( ' user_id ' , [ 3 , 4 , 5 ] )
def test_get_user_known_authenticated_user_id ( user_id , dbsession ) :
''' get_user() should return user instance on known active user '''
from collections import namedtuple
from ordr2 . models import User , Role
from ordr2 . security import get_user
@ -103,3 +97,20 @@ def test_get_user_no_unauthenticated_user_id(user_id, dbsession):
@@ -103,3 +97,20 @@ def test_get_user_no_unauthenticated_user_id(user_id, dbsession):
user = get_user ( request )
assert isinstance ( user , User )
@pytest . mark . parametrize ( ' user_id ' , [ 1 , 2 , 6 , 1969 ] )
def test_get_user_with_unknown_or_inactive_id ( user_id , dbsession ) :
''' get_user() should return None on inactive users or unknown ids '''
from collections import namedtuple
from ordr2 . models import User , Role
from ordr2 . security import get_user
create_users ( dbsession )
# pyramid.testing.DummyRequest can't be used, since the parameter
# unauthenticated_userid cannot be set. A named tuple is used instead
Request = namedtuple ( ' Request ' , ' dbsession, unauthenticated_userid ' )
request = Request ( dbsession = dbsession , unauthenticated_userid = user_id )
user = get_user ( request )
assert user is None