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.

126 lines
4.5 KiB

''' functional tests for ordr2.views.account.py '''
from pyramid_mailer import get_mailer
from .. import testappsetup, testapp, get_token_url # noqa: F401
def test_account_change_settings(testapp): # noqa: F811
testapp.login('TerryGilliam', 'Terry')
response = testapp.get('/account/settings')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Settings' in response
assert 'value="gilliam@example.com"' in response
assert 'Wrong Password' not in response
# fill out the form without confirmation password
form = response.form
form['first_name'] = 'Amy'
form['last_name'] = 'McDonald'
response = form.submit(name='change')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Settings' in response
assert 'required' in response
# fill out the form with invalid data but correct password
response = testapp.get('/account/settings')
form = response.form
form['first_name'] = 'Amy'
form['last_name'] = 'McDonald'
form['email'] = 'this is not an email address'
form['confirmation'] = 'Terry'
response = form.submit(name='change')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Settings' in response
assert 'Invalid email address' in response
# fill out the form with valid data and correct password
response = testapp.get('/account/settings')
form = response.form
form['first_name'] = 'Amy'
form['last_name'] = 'McDonald'
form['confirmation'] = 'Terry'
response = form.submit(name='change')
assert response.location == 'http://localhost/'
response = testapp.get('/account/settings')
assert 'value="Amy"' in response
def test_account_change_email(testapp): # noqa: F811
testapp.login('TerryGilliam', 'Terry')
response = testapp.get('/account/settings')
# fill out the form with valid data and correct password
form = response.form
form['email'] = 'amy@example.com'
form['confirmation'] = 'Terry'
response = form.submit(name='change')
assert response.location == 'http://localhost/account/verify'
# click the email verification token
mailer = get_mailer(testapp.app.registry)
email = mailer.outbox[-1]
assert email.subject == '[ordr] Verify New Email Address'
assert email.recipients == ['amy@example.com']
token_link = get_token_url(email, prefix='/account/')
response = testapp.get(token_link)
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Settings' in response
assert 'changed sucessfully' not in response
def test_account_change_password(testapp): # noqa: F811
testapp.login('TerryGilliam', 'Terry')
response = testapp.get('/account/password')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Password' in response
assert 'Wrong Password' not in response
# fill out the form with incorrect confirmation password
form = response.form
form['password'] = 'Lost in La Mancha'
form['password-confirm'] = 'Lost in La Mancha'
form['confirmation'] = 'Unknown Password'
response = form.submit(name='change')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Password' in response
assert 'Wrong password' in response
# fill out the form with invalid data but correct password
response = testapp.get('/account/password')
form = response.form
form['password'] = 'Lost in La Mancha'
form['password-confirm'] = 'confirmation does not match'
form['confirmation'] = 'Terry'
response = form.submit(name='change')
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Change Password' in response
assert 'Password did not match confirm' in response
# fill out the form with valid data and correct password
response = testapp.get('/account/password')
form = response.form
form['password'] = 'Lost in La Mancha'
form['password-confirm'] = 'Lost in La Mancha'
form['confirmation'] = 'Terry'
response = form.submit(name='change')
assert response.location == 'http://localhost/account/changed'
response = response.follow()
active_nav = response.html.find('li', class_='active')
assert active_nav is None
assert 'Your password was changed successfully' in response
assert testapp.login('TerryGilliam', 'Lost in La Mancha')