@ -29,6 +29,26 @@ PASSWORD_RESET_FORM_DATA = MultiDict([
@@ -29,6 +29,26 @@ PASSWORD_RESET_FORM_DATA = MultiDict([
( ' __end__ ' , ' password:mapping ' ) ,
] )
SETTINGS_FORM_DATA = MultiDict ( [
( ' __start__ ' , ' general:mapping ' ) ,
( ' username ' , ' TerryGilliam ' ) ,
( ' first_name ' , ' Terry ' ) ,
( ' last_name ' , ' Gilliam ' ) ,
( ' email ' , ' gilliam@example.com ' ) ,
( ' role ' , ' USER ' ) ,
( ' __end__ ' , ' general:mapping ' ) ,
( ' __start__ ' , ' change_password:mapping ' ) ,
( ' __start__ ' , ' new_password:mapping ' ) ,
( ' new_password ' , ' Amy ' ) ,
( ' new_password-confirm ' , ' Amy ' ) ,
( ' __end__ ' , ' new_password:mapping ' ) ,
( ' __end__ ' , ' change_password:mapping ' ) ,
( ' __start__ ' , ' confirm_changes:mapping ' ) ,
( ' password ' , ' Terry ' ) ,
( ' __end__ ' , ' confirm_changes:mapping ' )
] )
@pytest . mark . parametrize ( ' rolename ' , [ ' user ' , ' purchaser ' , ' admin ' ] )
def test_account_login_active_users ( dbsession , rolename ) :
@ -152,7 +172,7 @@ def test_registration_form_processing_ok(dbsession):
@@ -152,7 +172,7 @@ def test_registration_form_processing_ok(dbsession):
# doesn't know about event subscribers in the unittest
def test_registration_form_processing_cancel ( app_config ) :
def test_registration_form_processing_cancel ( dbsession ) :
''' canceling registration form processing '''
from ordr2 . models . account import User , Role , TokenSubject
from ordr2 . views . account import registration_form_processing
@ -325,7 +345,7 @@ def test_reset_password_form_processing_ok(dbsession):
@@ -325,7 +345,7 @@ def test_reset_password_form_processing_ok(dbsession):
assert dbsession . query ( User ) . count ( ) == 1
def test_reset_password_form_processing_cancel ( ) :
def test_reset_password_form_processing_cancel ( dbsession ) :
''' reset password form processing is canceled '''
from ordr2 . views . account import reset_password_form_processing
@ -354,3 +374,76 @@ def test_reset_password_form_processing_invalid(pw, confirm):
@@ -354,3 +374,76 @@ def test_reset_password_form_processing_invalid(pw, confirm):
result = reset_password_form_processing ( None , request )
assert isinstance ( result [ ' form ' ] , deform . Form )
# settings
def test_settings_form ( dbsession ) :
''' settings form display '''
from ordr2 . views . account import settings_form
user = get_user ( ' user ' )
context = DummyResource ( model = user )
request = DummyRequest ( )
result = settings_form ( context , request )
assert isinstance ( result [ ' form ' ] , deform . Form )
def test_settings_form_processing_cancel ( dbsession ) :
''' settings form processing is canceled '''
from ordr2 . views . account import settings_form_processing
user = get_user ( ' user ' )
context = DummyResource ( model = user )
request = DummyRequest ( dbsession = dbsession , POST = { ' Cancel ' : ' cancel ' } )
result = settings_form_processing ( None , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
def test_settings_form_processing_change_name ( dbsession ) :
''' settings form processing change name only '''
from ordr2 . views . account import settings_form_processing
user = get_user ( ' user ' )
context = DummyResource ( model = user )
request = DummyRequest ( dbsession = dbsession , user = user , context = context )
changes = {
' username ' : ' AmyMcDonald ' ,
' first_name ' : ' Amy ' ,
' last_name ' : ' McDonald ' ,
' role ' : ' ADMIN ' ,
' new_password ' : ' ' ,
' new_password-confirm ' : ' ' ,
}
set_deform_data ( request , SETTINGS_FORM_DATA , changes )
result = settings_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
assert user . username == ' TerryGilliam '
assert user . first_name == ' Amy '
assert user . last_name == ' McDonald '
assert user . email == ' gilliam@example.com '
assert user . check_password ( ' Terry ' )
def test_settings_form_processing_change_password ( dbsession ) :
''' settings form processing change name only '''
from ordr2 . views . account import settings_form_processing
user = get_user ( ' user ' )
context = DummyResource ( model = user )
request = DummyRequest ( dbsession = dbsession , user = user , context = context )
changes = {
' new_password ' : ' Amy ' ,
' new_password-confirm ' : ' Amy ' ,
}
set_deform_data ( request , SETTINGS_FORM_DATA , changes )
result = settings_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
assert user . check_password ( ' Amy ' )