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.
67 lines
1.9 KiB
67 lines
1.9 KiB
''' Test package for ordr2.resources ''' |
|
|
|
import pytest |
|
|
|
|
|
def test_base_resource_init(): |
|
''' test __init__ function of base resource ''' |
|
from ordr2.resources import BaseResource, RootResource |
|
|
|
root = RootResource('request object') |
|
resource = BaseResource('resource name', root, 'model instance') |
|
|
|
assert resource.__name__ == 'resource name' |
|
assert resource.__parent__ == root |
|
assert resource.request == 'request object' |
|
assert resource.model == 'model instance' |
|
|
|
|
|
def test_base_resource_acl(): |
|
''' test __acl__ function of base resource ''' |
|
from ordr2.resources import BaseResource, RootResource |
|
from pyramid.security import DENY_ALL |
|
|
|
root = RootResource('request object') |
|
resource = BaseResource('resource name', root, 'model instance') |
|
|
|
assert resource.__acl__() == [ DENY_ALL ] |
|
|
|
|
|
@pytest.mark.parametrize( |
|
'segment', [ |
|
'known', |
|
pytest.mark.xfail('unknown', raises=KeyError) |
|
] |
|
) |
|
def test_base_resource_getitem(segment): |
|
''' test the __getitem__ function of base resource ''' |
|
from ordr2.resources import BaseResource, RootResource |
|
|
|
root = RootResource('request object') |
|
root.nodes = {'known': BaseResource} |
|
resource = root[segment] |
|
|
|
assert resource.__name__ == 'known' |
|
assert resource.__parent__ == root |
|
assert resource.request == 'request object' |
|
|
|
|
|
def test_root_resource_init(): |
|
''' test __init__ function of root resource ''' |
|
from ordr2.resources import RootResource |
|
|
|
resource = RootResource('request object') |
|
|
|
assert resource.__name__ is None |
|
assert resource.__parent__ is None |
|
assert resource.request == 'request object' |
|
|
|
|
|
def test_root_resource_acl(): |
|
''' test __acl__ function of root resource ''' |
|
from ordr2.resources import RootResource |
|
from pyramid.security import Allow, Everyone |
|
|
|
root = RootResource('request object') |
|
|
|
assert root.__acl__() == [ (Allow, Everyone, 'view') ]
|
|
|