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.

55 lines
1.5 KiB

''' Tests for the root resource '''
import pytest
from ordr.resources.account import (
RegistrationResource,
PasswordResetResource,
AccountResource
)
def test_root_init():
''' test RootResource initialization '''
from ordr.resources import RootResource
root = RootResource('request')
assert root.__name__ is None
assert root.__parent__ is None
assert root.request == 'request'
def test_root_acl():
''' test access controll list for RootResource '''
from pyramid.security import Allow, Everyone, DENY_ALL
from ordr.resources import RootResource
root = RootResource(None)
assert root.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL]
@pytest.mark.parametrize(
'key,resource_class', [
('register', RegistrationResource),
('forgot', PasswordResetResource),
('account', AccountResource)
]
)
def test_root_getitem(key, resource_class):
''' test '__getitem__()' method of RootResource '''
from ordr.resources import RootResource
root = RootResource(None)
child = root[key]
assert isinstance(child, resource_class)
assert child.__name__ == key
assert child.__parent__ == root
assert child.request == root.request
def test_root_getitem_raises_error():
''' test '__getitem__()' method raises KeyError '''
from ordr.resources import RootResource
root = RootResource(None)
with pytest.raises(KeyError):
root['unknown child name']