Holger Frey
7 years ago
4 changed files with 90 additions and 46 deletions
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
''' Tests for ordr2.resources.account ''' |
||||
|
||||
import pytest |
||||
|
||||
|
||||
def test_account_resource_init(): |
||||
''' test __init__ function of base resource ''' |
||||
from pyramid.testing import DummyRequest |
||||
from ordr2.resources import AccountResource, RootResource |
||||
|
||||
request = DummyRequest(user='Eric Idle') |
||||
root = RootResource(request) |
||||
resource = AccountResource('resource name', root) |
||||
|
||||
assert resource.__name__ == 'resource name' |
||||
assert resource.__parent__ == root |
||||
assert resource.request == request |
||||
assert resource.model == request.user |
||||
|
||||
|
||||
def test_account_resource_acl(): |
||||
''' test __acl__ function of base resource ''' |
||||
from pyramid.security import Allow, Authenticated, Deny, Everyone, DENY_ALL |
||||
from pyramid.testing import DummyRequest |
||||
from ordr2.resources import AccountResource, RootResource |
||||
|
||||
request = DummyRequest(user=None) |
||||
root = RootResource(request) |
||||
resource = AccountResource('resource name', root) |
||||
|
||||
assert resource.__acl__() == [ |
||||
(Allow, Everyone, 'login'), |
||||
(Allow, Everyone, 'logout'), |
||||
(Deny, Authenticated, 'register'), |
||||
(Allow, Everyone, 'register'), |
||||
(Allow, Authenticated, 'settings'), |
||||
DENY_ALL |
||||
] |
||||
|
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
''' 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__() |
||||
|
||||
|
||||
@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' |
Reference in new issue