You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.6 KiB
90 lines
3.6 KiB
7 years ago
|
''' functional tests for ordr2.views.forgotten_password '''
|
||
|
|
||
|
from pyramid_mailer import get_mailer
|
||
|
|
||
|
from . import testappsetup, testapp, get_token_url # noqa: F401
|
||
|
|
||
|
|
||
|
def test_forgot_password_process(testapp): # noqa: F811
|
||
|
''' test the forgot password form '''
|
||
7 years ago
|
response = testapp.get('/account/forgot')
|
||
7 years ago
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 1: Validate Account' in active_step.text
|
||
|
assert 'Forgot Your Password?' in response
|
||
|
assert 'unknown username or email' not in response
|
||
7 years ago
|
|
||
7 years ago
|
# fill out this form with invalid data
|
||
|
form = response.form
|
||
|
form['identifier'] = 'unknown identifier'
|
||
|
response = form.submit(name='send_mail')
|
||
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 1: Validate Account' in active_step.text
|
||
|
assert 'Forgot Your Password?' in response
|
||
|
assert 'Username or email address unknown' in response
|
||
7 years ago
|
|
||
7 years ago
|
# fill out this form with valid data
|
||
7 years ago
|
response = testapp.get('/account/forgot')
|
||
7 years ago
|
form = response.form
|
||
|
form['identifier'] = 'TerryGilliam'
|
||
|
response = form.submit(name='send_mail')
|
||
7 years ago
|
assert response.location == 'http://localhost/account/forgot/verify'
|
||
7 years ago
|
|
||
|
response = response.follow()
|
||
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 1: Validate Account' in active_step.text
|
||
|
assert 'Verify Your Email Address' in response
|
||
7 years ago
|
|
||
7 years ago
|
# click the email verification token
|
||
|
mailer = get_mailer(testapp.app.registry)
|
||
|
email = mailer.outbox[-1]
|
||
|
assert email.subject == '[ordr] Password Reset'
|
||
7 years ago
|
|
||
7 years ago
|
token_link = get_token_url(email, prefix='/forgot/')
|
||
|
response = testapp.get(token_link)
|
||
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 2: Change Password' in active_step.text
|
||
|
assert 'Forgot Your Password?' in response
|
||
|
assert 'do not match' not in response
|
||
7 years ago
|
|
||
7 years ago
|
# fill out the change password form with invalid data
|
||
|
form = response.form
|
||
|
form['password'] = 'some passwords'
|
||
|
form['password-confirm'] = 'that do not match'
|
||
|
response = form.submit(name='change')
|
||
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 2: Change Password' in active_step.text
|
||
|
assert 'Forgot Your Password?' in response
|
||
|
assert 'Password did not match confirm' in response
|
||
|
|
||
|
# fill out the change password form with valid data
|
||
|
form = response.form
|
||
|
form['password'] = 'Lost in La Mancha'
|
||
|
form['password-confirm'] = 'Lost in La Mancha'
|
||
|
response = form.submit(name='change')
|
||
7 years ago
|
assert response.location == 'http://localhost/account/forgot/completed'
|
||
|
|
||
7 years ago
|
response = response.follow()
|
||
|
active_nav = response.html.find('li', class_='active')
|
||
|
active_step = response.html.find('p', class_='text-primary')
|
||
|
content = response.html.find('div', class_='content')
|
||
|
assert active_nav is None
|
||
|
assert 'Step 3: Finished' in active_step.text
|
||
|
assert 'Forgot Your Password?' in response
|
||
|
assert 'Password Reset Succesfull' in response
|
||
|
assert content.a['href'] == 'http://localhost/'
|
||
|
assert content.a.text == 'log in'
|
||
|
|
||
|
# old password should not work but the new one
|
||
|
assert not testapp.login('TerryGilliam', 'Terry')
|
||
|
assert testapp.login('TerryGilliam', 'Lost in La Mancha')
|