|
|
|
''' tests for the login, logout, registration and account settings'''
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from . import testapp
|
|
|
|
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
|
|
|
|
form = resonse.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.submitt()
|
|
|
|
|
|
|
|
assert response.location == '/account/verify'
|
|
|
|
response = response.follow()
|
|
|
|
assert 'email sent' in response
|
|
|
|
|
|
|
|
# click the email verification token
|
|
|
|
email = ''
|
|
|
|
token = email
|
|
|
|
response = testapp.get('/account/' + token)
|
|
|
|
assert 'consider a longer password' in response
|
|
|
|
assert 'activated by an administrator' 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
|
|
|
|
|
|
|
|
|