@ -3,6 +3,10 @@ import pytest
@@ -3,6 +3,10 @@ import pytest
from pyramid . httpexceptions import HTTPFound
from pyramid . testing import DummyRequest
from ordr . models . account import Role
from . . import app_config , dbsession , get_example_user # noqa: F401
@pytest . mark . parametrize (
' user,location ' ,
@ -20,3 +24,59 @@ def test_faq():
@@ -20,3 +24,59 @@ def test_faq():
from ordr . views . pages import faq
result = faq ( None , None )
assert result == { }
def test_login ( ) :
from ordr . views . pages import login
result = login ( None , None )
assert result == { ' loginerror ' : False }
@pytest . mark . parametrize ( ' role ' , [ Role . USER , Role . PURCHASER , Role . ADMIN ] )
def test_check_login_ok ( dbsession , role ) :
from ordr . views . pages import check_login
user = get_example_user ( role )
dbsession . add ( user )
post_data = { ' username ' : user . username , ' password ' : user . first_name }
request = DummyRequest ( dbsession = dbsession , POST = post_data )
result = check_login ( None , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
@pytest . mark . parametrize ( ' role ' , [ Role . UNVALIDATED , Role . NEW , Role . INACTIVE ] )
def test_check_login_not_activated ( dbsession , role ) :
from ordr . views . pages import check_login
user = get_example_user ( role )
dbsession . add ( user )
post_data = { ' username ' : user . username , ' password ' : user . first_name }
request = DummyRequest ( dbsession = dbsession , POST = post_data )
result = check_login ( None , request )
assert result == { ' loginerror ' : True }
@pytest . mark . parametrize (
' username,password ' , [
( ' ' , ' ' ) ,
( ' TerryGilliam ' , ' ' ) ,
( ' ' , ' Terry ' ) ,
( ' TerryGilliam ' , ' wrong password ' ) ,
( ' wrong username ' , ' Terry ' ) ,
]
)
def test_check_login_invalid_credentials ( dbsession , username , password ) :
from ordr . views . pages import check_login
user = get_example_user ( Role . USER )
dbsession . add ( user )
post_data = { ' username ' : username , ' password ' : password }
request = DummyRequest ( dbsession = dbsession , POST = post_data )
result = check_login ( None , request )
assert result == { ' loginerror ' : True }
def test_logout ( ) :
from ordr . views . pages import logout
request = DummyRequest ( )
result = logout ( None , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '