CPI Ordering System (the old version)
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

90 lines
3.6 KiB

''' 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 '''
response = testapp.get('/account/forgot')
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
# 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
# fill out this form with valid data
response = testapp.get('/account/forgot')
form = response.form
form['identifier'] = 'TerryGilliam'
response = form.submit(name='send_mail')
assert response.location == 'http://localhost/account/forgot/verify'
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
# click the email verification token
mailer = get_mailer(testapp.app.registry)
email = mailer.outbox[-1]
assert email.subject == '[ordr] Password Reset'
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
# 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')
assert response.location == 'http://localhost/account/forgot/completed'
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')