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.
 
 
 
 
 

172 lines
5.7 KiB

''' Tests for the account resources '''
import pytest
from pyramid.testing import DummyRequest, DummyResource
from .. import app_config, dbsession, get_example_user # noqa: F401
def test_registration_token_acl():
''' test access controll list for RegistrationTokenResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources.account import RegistrationTokenResource
parent = DummyResource(request='request')
resource = RegistrationTokenResource('name', parent)
assert resource.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL]
def test_registration_acl():
''' test access controll list for RegistrationResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources.account import RegistrationResource
parent = DummyResource(request='request')
resource = RegistrationResource('a name', parent)
assert resource.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL]
def test_registration_get_registration_form():
''' test 'get_registration_form()' method of RegistrationResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources.account import RegistrationResource
import deform
request = DummyRequest()
parent = DummyResource(request=request)
resource = RegistrationResource('a name', parent)
form = resource.get_registration_form()
assert isinstance(form, deform.Form)
assert len(form.buttons) == 2
assert form.buttons[0].title == 'Create Account'
assert form.buttons[1].title == 'Cancel'
def test_registration_getitem_found(dbsession): # noqa: F811
''' test '__getitem__()' method returns child resource '''
from ordr.models.account import Role, TokenSubject
from ordr.resources.account import (
RegistrationResource,
RegistrationTokenResource
)
request = DummyRequest(dbsession=dbsession)
user = get_example_user(Role.NEW)
token = user.issue_token(request, TokenSubject.REGISTRATION)
dbsession.add(user)
dbsession.flush()
parent = DummyResource(request=request)
resource = RegistrationResource('a name', parent)
result = resource[token.hash]
assert isinstance(result, RegistrationTokenResource)
assert result.__name__ == token.hash
assert result.__parent__ == resource
assert result.model == token
def test_registration_getitem_not_found(dbsession): # noqa: F811
''' test '__getitem__()' method raises KeyError '''
from ordr.models.account import Role, TokenSubject
from ordr.resources.account import RegistrationResource
request = DummyRequest(dbsession=dbsession)
user = get_example_user(Role.NEW)
user.issue_token(request, TokenSubject.REGISTRATION)
dbsession.add(user)
dbsession.flush()
parent = DummyResource(request=request)
resource = RegistrationResource('a name', parent)
with pytest.raises(KeyError):
resource['unknown hash']
def test_password_reset_token_acl():
''' test access controll list for PasswordResetTokenResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources.account import PasswordResetTokenResource
parent = DummyResource(request='request')
resource = PasswordResetTokenResource('name', parent)
assert resource.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL]
def test_password_reset_token_get_reset_form():
''' test the setup of the password reset form'''
from ordr.resources.account import PasswordResetTokenResource
import deform
request = DummyRequest()
parent = DummyResource(request=request)
resource = PasswordResetTokenResource('some name', parent)
form = resource.get_reset_form()
assert isinstance(form, deform.Form)
assert len(form.buttons) == 2
assert form.buttons[0].title == 'Set New Password'
assert form.buttons[1].title == 'Cancel'
def test_password_reset_acl():
''' test access controll list for PasswordResetResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources.account import PasswordResetResource
parent = DummyResource(request='request')
resource = PasswordResetResource('a name', parent)
assert resource.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL]
def test_password_reset_getitem_found(dbsession): # noqa: F811
''' test '__getitem__()' method returns child resource '''
from ordr.models.account import Role, TokenSubject
from ordr.resources.account import (
PasswordResetResource,
PasswordResetTokenResource
)
request = DummyRequest(dbsession=dbsession)
user = get_example_user(Role.NEW)
token = user.issue_token(request, TokenSubject.RESET_PASSWORD)
dbsession.add(user)
dbsession.flush()
parent = DummyResource(request=request)
resource = PasswordResetResource('a name', parent)
result = resource[token.hash]
assert isinstance(result, PasswordResetTokenResource)
assert result.__name__ == token.hash
assert result.__parent__ == resource
assert result.model == token
def test_password_reset_getitem_not_found(dbsession): # noqa: F811
''' test '__getitem__()' method raises KeyError '''
from ordr.models.account import Role, TokenSubject
from ordr.resources.account import PasswordResetResource
request = DummyRequest(dbsession=dbsession)
user = get_example_user(Role.NEW)
user.issue_token(request, TokenSubject.RESET_PASSWORD)
dbsession.add(user)
dbsession.flush()
parent = DummyResource(request=request)
resource = PasswordResetResource('a name', parent)
with pytest.raises(KeyError):
resource['unknown hash']