|
|
|
''' Tests for ordr2.resources.base '''
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
with pytest.raises(NotImplementedError):
|
|
|
|
assert resource.__acl__()
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_resource_getitem_ok():
|
|
|
|
''' test the __getitem__ function of base resource '''
|
|
|
|
from ordr2.resources import BaseResource, RootResource
|
|
|
|
|
|
|
|
root = RootResource('request object')
|
|
|
|
root.nodes = {'known': BaseResource}
|
|
|
|
resource = root['known']
|
|
|
|
|
|
|
|
assert resource.__name__ == 'known'
|
|
|
|
assert resource.__parent__ == root
|
|
|
|
assert resource.request == 'request object'
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_resource_getitem_raises_key_error():
|
|
|
|
''' test the __getitem__ function of base resource '''
|
|
|
|
from ordr2.resources import BaseResource, RootResource
|
|
|
|
|
|
|
|
root = RootResource('request object')
|
|
|
|
root.nodes = {'known': BaseResource}
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
resource = root['unknown']
|