|
|
|
''' tests for the common layout and simple (static)'''
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from . import testapp
|
|
|
|
from .. import get_user
|
|
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('role_name', ['user', 'purchaser', 'admin', ])
|
|
|
|
def test_account_login_for_active_users(testapp, role_name):
|
|
|
|
''' check if user login works '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
user = get_user(role_name)
|
|
|
|
root = testapp.get('/')
|
|
|
|
login_form = root.forms['login-form']
|
|
|
|
login_form.set('username', user.username)
|
|
|
|
login_form.set('password', user.first_name)
|
|
|
|
response = login_form.submit()
|
|
|
|
|
|
|
|
# a login leads to a redirect
|
|
|
|
assert response.status == '302 Found'
|
|
|
|
assert response.location.endswith('/orders')
|
|
|
|
|
|
|
|
# the layout should reflect the login
|
|
|
|
response = testapp.get('/faq')
|
|
|
|
assert '<!-- user is logged in -->' in response
|
|
|
|
assert 'id="login-form"' not in response
|
|
|
|
assert 'Logged in as <span>{}</span>'.format(user.username) in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('role_name', ['unvalidated', 'new', 'inactive'])
|
|
|
|
def test_account_login_for_inactive_users(testapp, role_name):
|
|
|
|
''' check if user login works '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
user = get_user(role_name)
|
|
|
|
root = testapp.get('/')
|
|
|
|
login_form = root.forms['login-form']
|
|
|
|
login_form.set('username', user.username)
|
|
|
|
login_form.set('password', user.first_name)
|
|
|
|
response = login_form.submit()
|
|
|
|
|
|
|
|
assert '<!-- No logged in user -->' in response
|
|
|
|
assert 'id="login-form' in response
|
|
|
|
assert 'Logged in as <span>{}</span>'.format(user.username) not in response
|
|
|
|
assert 'You entered the wrong username or password' in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'username, password', [
|
|
|
|
('EricIdle', 'wrong password'),
|
|
|
|
('unknown user', 'Eric'),
|
|
|
|
('unknown user', 'unknown password')
|
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_account_login_fails(testapp, username, password):
|
|
|
|
''' check if user login works '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
root = testapp.get('/')
|
|
|
|
login_form = root.forms['login-form']
|
|
|
|
login_form.set('username', username)
|
|
|
|
login_form.set('password', password)
|
|
|
|
response = login_form.submit()
|
|
|
|
|
|
|
|
assert '<!-- No logged in user -->' in response
|
|
|
|
assert 'id="login-form' in response
|
|
|
|
assert 'Logged in as <span>{}</span>'.format(username) not in response
|
|
|
|
assert 'You entered the wrong username or password' in response
|
|
|
|
|
|
|
|
|
|
|
|
def test_account_login_only_by_post(testapp):
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
|
|
|
|
def test_account_logout_works(testapp):
|
|
|
|
''' check if a user can log out '''
|
|
|
|
testapp.reset()
|
|
|
|
|
|
|
|
testapp.login('user')
|
|
|
|
response = testapp.get('/account/logout').follow()
|
|
|
|
|
|
|
|
assert '<!-- No logged in user -->' in response
|
|
|
|
assert 'id="login-form' in response
|