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.

104 lines
3.0 KiB

import pytest
7 years ago
from pyramid.httpexceptions import HTTPFound
from pyramid.testing import DummyRequest
7 years ago
from ordr.models.account import Role
from .. import app_config, dbsession, get_example_user # noqa: F401
@pytest.mark.parametrize(
7 years ago
'user,location',
[(None, '/login'), ('someone', '/orders')]
)
def test_welcome(user, location):
''' test redirects on web root '''
7 years ago
from ordr.views.pages import welcome
request = DummyRequest(user=user)
result = welcome(None, request)
assert isinstance(result, HTTPFound)
assert result.location == f'http://example.com/{location}'
7 years ago
def test_faq():
''' test the view for the faq page '''
7 years ago
from ordr.views.pages import faq
result = faq(None, None)
assert result == {}
def test_login():
''' test the view for the login form '''
from ordr.views.pages import login
result = login(None, None)
7 years ago
assert result == {'loginerror': False}
7 years ago
@pytest.mark.parametrize( # noqa: F811
'role', [Role.USER, Role.PURCHASER, Role.ADMIN]
)
def test_check_login_ok(dbsession, role):
''' test the processing of the login form with valid credentials '''
from ordr.views.pages import check_login
user = get_example_user(role)
dbsession.add(user)
post_data = {'username': user.username, 'password': user.first_name}
request = DummyRequest(dbsession=dbsession, POST=post_data)
result = check_login(None, request)
assert isinstance(result, HTTPFound)
assert result.location == 'http://example.com//'
7 years ago
@pytest.mark.parametrize( # noqa: F811
'role', [Role.UNVALIDATED, Role.NEW, Role.INACTIVE]
)
def test_check_login_not_activated(dbsession, role):
''' test the processing of the login form with an inactive user '''
from ordr.views.pages import check_login
user = get_example_user(role)
dbsession.add(user)
post_data = {'username': user.username, 'password': user.first_name}
request = DummyRequest(dbsession=dbsession, POST=post_data)
result = check_login(None, request)
7 years ago
assert result == {'loginerror': True}
7 years ago
@pytest.mark.parametrize( # noqa: F811
'username,password', [
7 years ago
('', ''),
('TerryGilliam', ''),
('', 'Terry'),
('TerryGilliam', 'wrong password'),
('wrong username', 'Terry'),
]
)
def test_check_login_invalid_credentials(dbsession, username, password):
''' test the processing of the login form with invalid credentials '''
from ordr.views.pages import check_login
user = get_example_user(Role.USER)
dbsession.add(user)
post_data = {'username': username, 'password': password}
request = DummyRequest(dbsession=dbsession, POST=post_data)
result = check_login(None, request)
7 years ago
assert result == {'loginerror': True}
def test_logout():
''' test the logout view '''
from ordr.views.pages import logout
request = DummyRequest()
result = logout(None, request)
assert isinstance(result, HTTPFound)
assert result.location == 'http://example.com//'