|
|
|
''' tests for the login, logout, registration and account settings'''
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pyramid_mailer import get_mailer
|
|
|
|
|
|
|
|
from . import testapp, get_token_url
|
|
|
|
from .. import get_user
|
|
|
|
|
|
|
|
|
|
|
|
def test_account_register_authenticated_users(testapp):
|
|
|
|
''' registration page should not be accessible for authenticated users '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
testapp.login('user')
|
|
|
|
response = testapp.get('/account/register', status=403)
|
|
|
|
|
|
|
|
assert response.status.startswith('403')
|
|
|
|
|
|
|
|
|
|
|
|
def test_account_register_unauthenticated(testapp):
|
|
|
|
''' test the registration page for a unauthenticated user '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
response = testapp.get('/account/register')
|
|
|
|
# basic content test
|
|
|
|
assert 'Ordr | Account Registration' in response
|
|
|
|
# test the main nav section links and highlighting
|
|
|
|
li_one, li_two = response.html.find_all('li', class_='nav-item')
|
|
|
|
assert 'active' not in li_one['class']
|
|
|
|
assert li_one.find('a').text == 'FAQs'
|
|
|
|
assert 'active' in li_two['class']
|
|
|
|
assert li_two.find('a').text == 'Register'
|
|
|
|
# check for the registration form
|
|
|
|
form = response.html.find('form', class_='registration')
|
|
|
|
assert form is not None
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.xfail
|
|
|
|
def test_account_registeration_flow(testapp):
|
|
|
|
''' test the complete registration process '''
|
|
|
|
|
|
|
|
# submit the registration form
|
|
|
|
response = testapp.get('/account/register')
|
|
|
|
form = response.forms[1]
|
|
|
|
form['username'] = 'AmyMcDonald'
|
|
|
|
form['first_name'] = 'Amy'
|
|
|
|
form['last_name'] = 'McDonald'
|
|
|
|
form['email'] = 'amy@example.com'
|
|
|
|
form['password'] = 'Amy'
|
|
|
|
form['password-confirm'] = 'Amy'
|
|
|
|
response = form.submit()
|
|
|
|
|
|
|
|
assert response.location == 'http://localhost/account/registered'
|
|
|
|
response = response.follow()
|
|
|
|
assert 'Verify Your Email Address' in response
|
|
|
|
assert 'consider a longer password' in response
|
|
|
|
|
|
|
|
# click the email verification token
|
|
|
|
mailer = get_mailer(testapp.app.registry)
|
|
|
|
email = mailer.outbox[-1]
|
|
|
|
assert email.subject == '[ordr] Please verify your email address'
|
|
|
|
token_link = get_token_url(email)
|
|
|
|
|
|
|
|
response = testapp.get(token_link)
|
|
|
|
assert 'Account Registration Completed' in response
|
|
|
|
|
|
|
|
# logging in should not work
|
|
|
|
form = response.forms[0]
|
|
|
|
form['username'] = 'AmyMcDonald'
|
|
|
|
form['password'] = 'Amy'
|
|
|
|
response = form.submit()
|
|
|
|
assert '<!-- user is logged in -->' not in response
|
|
|
|
|
|
|
|
# activate the new user
|
|
|
|
testapp.login('admin')
|
|
|
|
response = testapp.get('/admin/users?role=new')
|
|
|
|
response = response.click('edit user')
|
|
|
|
form = response.forms[1]
|
|
|
|
form['role'] = 'USER'
|
|
|
|
form.submit()
|
|
|
|
testapp.logout()
|
|
|
|
|
|
|
|
# login should now work
|
|
|
|
response = testapp.get('/')
|
|
|
|
form = response.forms[0]
|
|
|
|
form['username'] = 'AmyMcDonald'
|
|
|
|
form['password'] = 'Amy'
|
|
|
|
response = form.submit()
|
|
|
|
assert '<!-- user is logged in -->' in response
|
|
|
|
|
|
|
|
|