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.
 
 
 
 
 

85 lines
2.2 KiB

''' Tests for ordr2.views.account '''
import pytest
from pyramid.httpexceptions import HTTPFound
from pyramid.testing import DummyRequest, DummyResource
from .. import app_config, dbsession, get_user, create_users
@pytest.mark.parametrize('rolename', ['user', 'purchaser', 'admin'])
def test_account_login_active_users(dbsession, rolename):
''' login ok for active users '''
from ordr2.views.account import login
create_users(dbsession)
user = get_user(rolename)
request = DummyRequest(
dbsession=dbsession,
post={
'username': user.username,
'password': user.first_name
}
)
result = login(None, request)
assert isinstance(result, HTTPFound)
assert result.location == '//orders'
@pytest.mark.parametrize('rolename', ['unvalidated', 'new', 'inactive'])
def test_account_login_fails_inactive_users(dbsession, rolename):
''' login fails for inactive users '''
from ordr2.views.account import login
create_users(dbsession)
user = get_user(rolename)
request = DummyRequest(
dbsession=dbsession,
post={
'username': user.username,
'password': user.first_name
}
)
result = login(None, request)
assert result == {}
@pytest.mark.parametrize(
'username, password', [
('EricIdle', 'wrong password'),
('unknown user', 'Eric'),
('unknown user', 'wrong password'),
('', '')
]
)
def test_account_login_fails_wrong_credentials(dbsession, username, password):
''' login fails for unknown or wrong credentials '''
from ordr2.views.account import login
create_users(dbsession)
request = DummyRequest(
dbsession=dbsession,
post={
'username': username,
'password': password
}
)
result = login(None, request)
assert result == {}
def test_logout(app_config):
''' logout works '''
from ordr2.views.account import logout
user = get_user('admin')
request = DummyRequest(user=user)
result = logout(None, request)
assert isinstance(result, HTTPFound)
assert result.location == 'http://example.com//'