@ -3,7 +3,7 @@ import deform
@@ -3,7 +3,7 @@ import deform
from pyramid . httpexceptions import HTTPFound
from pyramid . testing import DummyRequest , DummyResource
from . . import ( # noqa: F401
from . . . import ( # noqa: F401
app_config ,
dbsession ,
get_example_user ,
@ -11,44 +11,33 @@ from .. import ( # noqa: F401
@@ -11,44 +11,33 @@ from .. import ( # noqa: F401
)
def test_account_redirect ( ) :
''' redirect on root of account resource '''
from ordr . views . account import account
request = DummyRequest ( )
result = account ( None , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
def test_settings_form ( ) :
''' tests for displaying the settings form '''
from ordr . models . account import Role
from ordr . resources . account import AccountResource
from ordr . schemas . account import SettingsSchema
from ordr . views . account import settings_form
user = get_example_user ( Role . USER )
request = DummyRequest ( user = user )
parent = DummyResource ( request = request )
context = AccountResource ( None , parent )
result = settings_form ( context , request )
form = result [ ' form ' ]
assert isinstance ( form , deform . Form )
assert isinstance ( form . schema , SettingsSchema )
def test_settings_form_processing_valid_data ( dbsession ) : # noqa: F811
''' tests for processing the settings form
The data is valid , but no email change requested
'''
from ordr . models . account import Role , Token , User
from ordr . resources . account import AccountResource
from ordr . views . account import settings_form_processing
data = {
' username ' : ' TerryG ' ,
' first_name ' : ' Amy ' ,
@ -57,7 +46,7 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
@@ -57,7 +46,7 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' change ' : ' Change Settings '
}
user = get_example_user ( Role . USER )
dbsession . add ( user )
dbsession . flush ( )
@ -66,10 +55,10 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
@@ -66,10 +55,10 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
context = AccountResource ( None , parent )
request . context = context
result = settings_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
account = dbsession . query ( User ) . first ( )
assert account . username == ' TerryGilliam '
assert account . first_name == ' Amy '
@ -80,13 +69,13 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
@@ -80,13 +69,13 @@ def test_settings_form_processing_valid_data(dbsession): # noqa: F811
def test_settings_form_processing_mail_change ( dbsession ) : # noqa: F811
''' tests for processing the settings form
The data is valid and an email change is requested
'''
from ordr . models . account import Role , Token , TokenSubject , User
from ordr . resources . account import AccountResource
from ordr . views . account import settings_form_processing
data = {
' username ' : ' TerryG ' ,
' first_name ' : ' Amy ' ,
@ -95,7 +84,7 @@ def test_settings_form_processing_mail_change(dbsession): # noqa: F811
@@ -95,7 +84,7 @@ def test_settings_form_processing_mail_change(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' change ' : ' Change Settings '
}
user = get_example_user ( Role . USER )
dbsession . add ( user )
request = get_post_request ( data = data , dbsession = dbsession , user = user )
@ -103,16 +92,16 @@ def test_settings_form_processing_mail_change(dbsession): # noqa: F811
@@ -103,16 +92,16 @@ def test_settings_form_processing_mail_change(dbsession): # noqa: F811
context = AccountResource ( None , parent )
request . context = context
result = settings_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com//verify '
account = dbsession . query ( User ) . first ( )
assert account . username == ' TerryGilliam '
assert account . first_name == ' Amy '
assert account . last_name == ' McDonald '
assert account . email == ' gilliam@example.com '
token = dbsession . query ( Token ) . first ( )
assert token . subject == TokenSubject . CHANGE_EMAIL
assert token . payload == { ' email ' : ' amy@example.com ' }
@ -128,7 +117,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
@@ -128,7 +117,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
from ordr . resources . account import AccountResource
from ordr . schemas . account import SettingsSchema
from ordr . views . account import settings_form_processing
data = {
' username ' : ' TerryG ' ,
' first_name ' : ' Amy ' ,
@ -137,7 +126,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
@@ -137,7 +126,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' change ' : ' Change Settings '
}
user = get_example_user ( Role . USER )
dbsession . add ( user )
request = get_post_request ( data = data , dbsession = dbsession , user = user )
@ -146,7 +135,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
@@ -146,7 +135,7 @@ def test_settings_form_processing_invalid_data(dbsession): # noqa: F811
request . context = context
result = settings_form_processing ( context , request )
form = result [ ' form ' ]
assert isinstance ( form , deform . Form )
assert isinstance ( form . schema , SettingsSchema )
@ -156,7 +145,7 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
@@ -156,7 +145,7 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
from ordr . models . account import Role , User
from ordr . resources . account import AccountResource
from ordr . views . account import settings_form_processing
data = {
' username ' : ' TerryG ' ,
' first_name ' : ' Amy ' ,
@ -165,7 +154,7 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
@@ -165,7 +154,7 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' cancel ' : ' cancel '
}
user = get_example_user ( Role . USER )
dbsession . add ( user )
request = get_post_request ( data = data , dbsession = dbsession , user = user )
@ -173,22 +162,22 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
@@ -173,22 +162,22 @@ def test_settings_form_processing_cancel(dbsession): # noqa: F811
context = AccountResource ( None , parent )
request . context = context
result = settings_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
account = dbsession . query ( User ) . first ( )
assert account . first_name == ' Terry '
def test_verify_email ( dbsession ) : # noqa: F811
def test_verify_email_change ( dbsession ) : # noqa: F811
''' tests for processing the change password form '''
from ordr . models . account import Role , Token , TokenSubject
from ordr . views . account import verify_email
from ordr . views . account import verify_email_change
user = get_example_user ( Role . USER )
request = DummyRequest ( dbsession = dbsession , user = user )
user . issue_token (
request ,
TokenSubject . CHANGE_EMAIL ,
@ -198,12 +187,12 @@ def test_verify_email(dbsession): # noqa: F811
@@ -198,12 +187,12 @@ def test_verify_email(dbsession): # noqa: F811
dbsession . flush ( )
token = dbsession . query ( Token ) . first ( )
context = DummyResource ( model = token )
result = verify_email ( context , request )
result = verify_email_change ( context , request )
assert result == { }
assert user . email == ' amy@example.com '
assert dbsession . query ( Token ) . count ( ) == 0
def test_password_form ( ) :
''' tests for displaying the change password form '''
@ -211,24 +200,24 @@ def test_password_form():
@@ -211,24 +200,24 @@ def test_password_form():
from ordr . resources . account import AccountResource
from ordr . schemas . account import ChangePasswordSchema
from ordr . views . account import password_form
user = get_example_user ( Role . USER )
request = DummyRequest ( user = user )
parent = DummyResource ( request = request )
context = AccountResource ( None , parent )
result = password_form ( context , request )
form = result [ ' form ' ]
assert isinstance ( form , deform . Form )
assert isinstance ( form . schema , ChangePasswordSchema )
def test_password_form_processing_valid ( dbsession ) : # noqa: F811
''' tests for processing the change password form '''
from ordr . models . account import Role
from ordr . resources . account import AccountResource
from ordr . views . account import password_form_processing
data = {
' __start__ ' : ' password:mapping ' ,
' password ' : ' Make Amy McDonald A Rich Girl Fund ' ,
@ -237,13 +226,13 @@ def test_password_form_processing_valid(dbsession): # noqa: F811
@@ -237,13 +226,13 @@ def test_password_form_processing_valid(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' change ' : ' Change Password '
}
user = get_example_user ( Role . USER )
request = get_post_request ( data = data , user = user )
parent = DummyResource ( request = request )
context = AccountResource ( None , parent )
result = password_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com//changed '
assert not user . check_password ( ' Terry ' )
@ -256,7 +245,7 @@ def test_password_form_processing_invalid(dbsession): # noqa: F811
@@ -256,7 +245,7 @@ def test_password_form_processing_invalid(dbsession): # noqa: F811
from ordr . resources . account import AccountResource
from ordr . schemas . account import ChangePasswordSchema
from ordr . views . account import password_form_processing
data = {
' __start__ ' : ' password:mapping ' ,
' password ' : ' Make Amy McDonald A Rich Girl Fund ' ,
@ -265,14 +254,14 @@ def test_password_form_processing_invalid(dbsession): # noqa: F811
@@ -265,14 +254,14 @@ def test_password_form_processing_invalid(dbsession): # noqa: F811
' confirmation ' : ' not the right password for confirmation ' ,
' change ' : ' Change Password '
}
user = get_example_user ( Role . USER )
request = get_post_request ( data = data , user = user )
parent = DummyResource ( request = request )
context = AccountResource ( None , parent )
result = password_form_processing ( context , request )
form = result [ ' form ' ]
assert isinstance ( form , deform . Form )
assert isinstance ( form . schema , ChangePasswordSchema )
assert user . check_password ( ' Terry ' )
@ -283,7 +272,7 @@ def test_password_form_processing_cancel(dbsession): # noqa: F811
@@ -283,7 +272,7 @@ def test_password_form_processing_cancel(dbsession): # noqa: F811
from ordr . models . account import Role
from ordr . resources . account import AccountResource
from ordr . views . account import password_form_processing
data = {
' __start__ ' : ' password:mapping ' ,
' password ' : ' Make Amy McDonald A Rich Girl Fund ' ,
@ -292,17 +281,17 @@ def test_password_form_processing_cancel(dbsession): # noqa: F811
@@ -292,17 +281,17 @@ def test_password_form_processing_cancel(dbsession): # noqa: F811
' confirmation ' : ' Terry ' ,
' cancel ' : ' cancel '
}
user = get_example_user ( Role . USER )
request = get_post_request ( data = data , user = user )
parent = DummyResource ( request = request )
context = AccountResource ( None , parent )
result = password_form_processing ( context , request )
assert isinstance ( result , HTTPFound )
assert result . location == ' http://example.com// '
assert user . check_password ( ' Terry ' )
def test_password_changed ( ) :
''' show password has changed message '''