<s> import unittest <EOL> from pyramid import testing <EOL> class Test_principal_added ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import principal_added <EOL> return principal_added ( event ) <EOL> def test_event_wo_loading_attr ( self ) : <EOL> event = testing . DummyResource ( ) <EOL> event . object = testing . DummyResource ( ) <EOL> self . assertRaises ( AttributeError , self . _callFUT , event ) <EOL> def test_event_w_loading_True ( self ) : <EOL> event = testing . DummyResource ( loading = True ) <EOL> result = self . _callFUT ( event ) <EOL> self . assertEqual ( result , None ) <EOL> def test_wo_principals_service ( self ) : <EOL> from zope . interface import directlyProvides <EOL> from ... interfaces import IFolder <EOL> event = testing . DummyResource ( loading = False ) <EOL> root = testing . DummyResource ( ) <EOL> directlyProvides ( root , IFolder ) <EOL> event . object = root [ '<STR_LIT>' ] = testing . DummyResource ( ) <EOL> self . assertRaises ( ValueError , self . _callFUT , event ) <EOL> def test_user_not_in_groups ( self ) : <EOL> from ... testing import make_site <EOL> from ... interfaces import IUser <EOL> site = make_site ( ) <EOL> user = testing . DummyResource ( __provides__ = IUser ) <EOL> site [ '<STR_LIT:user>' ] = user <EOL> event = testing . DummyResource ( object = user , loading = False ) <EOL> self . _callFUT ( event ) <EOL> def test_user_in_groups ( self ) : <EOL> from ... testing import make_site <EOL> from ... interfaces import IUser <EOL> site = make_site ( ) <EOL> groups = site [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> groups [ '<STR_LIT:user>' ] = testing . DummyResource ( ) <EOL> user = testing . DummyResource ( __provides__ = IUser ) <EOL> site [ '<STR_LIT:user>' ] = user <EOL> event = testing . DummyResource ( object = user , loading = False ) <EOL> self . assertRaises ( ValueError , self . _callFUT , event ) <EOL> def test_group_not_in_users ( self ) : <EOL> from ... testing import make_site <EOL> site = make_site ( ) <EOL> group = testing . DummyResource ( ) <EOL> site [ '<STR_LIT>' ] = group <EOL> event = testing . DummyResource ( object = group , loading = False ) <EOL> self . _callFUT ( event ) <EOL> def test_group_in_users ( self ) : <EOL> from ... testing import make_site <EOL> site = make_site ( ) <EOL> users = site [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> users [ '<STR_LIT>' ] = testing . DummyResource ( ) <EOL> group = testing . DummyResource ( ) <EOL> site [ '<STR_LIT>' ] = group <EOL> event = testing . DummyResource ( object = group , loading = False ) <EOL> self . assertRaises ( ValueError , self . _callFUT , event ) <EOL> class Test_user_will_be_removed ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import user_will_be_removed <EOL> return user_will_be_removed ( event ) <EOL> def test_loading ( self ) : <EOL> event = testing . DummyResource ( loading = True , moving = None ) <EOL> result = self . _callFUT ( event ) <EOL> self . assertEqual ( result , None ) <EOL> def test_moving ( self ) : <EOL> event = testing . DummyResource ( loading = False , moving = True ) <EOL> result = self . _callFUT ( event ) <EOL> self . assertEqual ( result , None ) <EOL> def test_it ( self ) : <EOL> from ... interfaces import IFolder <EOL> parent = testing . DummyResource ( __provides__ = IFolder ) <EOL> user = testing . DummyResource ( ) <EOL> reset = testing . DummyResource ( ) <EOL> def commit_suicide ( ) : <EOL> reset . committed = True <EOL> reset . commit_suicide = commit_suicide <EOL> objectmap = DummyObjectMap ( ( reset , ) ) <EOL> parent . __objectmap__ = objectmap <EOL> parent [ '<STR_LIT:user>' ] = user <EOL> event = testing . DummyResource ( object = user , loading = False , moving = None ) <EOL> self . _callFUT ( event ) <EOL> self . assertTrue ( reset . committed ) <EOL> def test_it_moving ( self ) : <EOL> event = testing . DummyResource ( object = None , loading = False ) <EOL> event . moving = True <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> class Test_user_added ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import user_added <EOL> return user_added ( event ) <EOL> def test_loading ( self ) : <EOL> event = testing . DummyResource ( loading = True ) <EOL> result = self . _callFUT ( event ) <EOL> self . assertEqual ( result , None ) <EOL> def test_it_user_has_no_oid ( self ) : <EOL> user = testing . DummyResource ( ) <EOL> event = testing . DummyResource ( object = user , loading = False ) <EOL> event . registry = DummyRegistry ( ) <EOL> self . assertRaises ( AttributeError , self . _callFUT , event ) <EOL> def test_it ( self ) : <EOL> from pyramid . security import Allow <EOL> user = testing . DummyResource ( ) <EOL> user . __oid__ = <NUM_LIT:1> <EOL> event = testing . DummyResource ( object = user , loading = False ) <EOL> event . registry = DummyRegistry ( ) <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( <EOL> user . __acl__ , <EOL> [ ( Allow , <NUM_LIT:1> , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) ) ] ) <EOL> class Test_acl_maybe_added ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import acl_maybe_added <EOL> return acl_maybe_added ( event ) <EOL> def test_moving ( self ) : <EOL> event = DummyEvent ( moving = True , loading = False ) <EOL> self . assertEqual ( self . _callFUT ( event ) , False ) <EOL> def test_loading ( self ) : <EOL> event = DummyEvent ( moving = None , loading = True ) <EOL> self . assertEqual ( self . _callFUT ( event ) , False ) <EOL> def test_objectmap_is_None ( self ) : <EOL> event = DummyEvent ( moving = None , object = None , loading = False ) <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> def test_no_acls ( self ) : <EOL> from substanced . interfaces import IFolder <EOL> resource1 = testing . DummyResource ( __provides__ = IFolder ) <EOL> resource2 = testing . DummyResource ( ) <EOL> resource1 [ '<STR_LIT>' ] = resource2 <EOL> objectmap = DummyObjectMap ( ) <EOL> resource1 . __objectmap__ = objectmap <EOL> event = DummyEvent ( moving = None , object = resource1 , loading = False ) <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( objectmap . connections , [ ] ) <EOL> def test_with_acls ( self ) : <EOL> from ... interfaces import PrincipalToACLBearing <EOL> from substanced . interfaces import IFolder <EOL> resource1 = testing . DummyResource ( __provides__ = IFolder ) <EOL> resource2 = testing . DummyResource ( ) <EOL> resource1 [ '<STR_LIT>' ] = resource2 <EOL> resource1 . __acl__ = [ ( None , '<STR_LIT>' , None ) , ( None , <NUM_LIT:1> , None ) ] <EOL> resource2 . __acl__ = [ ( None , '<STR_LIT>' , None ) , ( None , <NUM_LIT:2> , None ) ] <EOL> objectmap = DummyObjectMap ( ) <EOL> resource1 . __objectmap__ = objectmap <EOL> event = DummyEvent ( moving = None , object = resource1 , loading = False ) <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( <EOL> objectmap . connections , <EOL> [ ( <NUM_LIT:2> , resource2 , PrincipalToACLBearing ) , <EOL> ( <NUM_LIT:1> , resource1 , PrincipalToACLBearing ) ] <EOL> ) <EOL> class Test_acl_modified ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import acl_modified <EOL> return acl_modified ( event ) <EOL> def test_objectmap_is_None ( self ) : <EOL> event = DummyEvent ( object = None ) <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> def test_gardenpath ( self ) : <EOL> from ... interfaces import PrincipalToACLBearing <EOL> resource = testing . DummyResource ( ) <EOL> objectmap = DummyObjectMap ( ) <EOL> resource . __objectmap__ = objectmap <EOL> event = DummyEvent ( <EOL> object = resource , <EOL> new_acl = [ ( None , '<STR_LIT>' , None ) , ( None , <NUM_LIT:1> , None ) ] , <EOL> old_acl = [ ( None , '<STR_LIT>' , None ) , ( None , <NUM_LIT:2> , None ) ] , <EOL> ) <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( <EOL> objectmap . connections , <EOL> [ ( <NUM_LIT:1> , resource , PrincipalToACLBearing ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> objectmap . disconnections , <EOL> [ ( <NUM_LIT:2> , resource , PrincipalToACLBearing ) ] <EOL> ) <EOL> class DummyObjectMap ( object ) : <EOL> def __init__ ( self , result = ( ) ) : <EOL> self . result = result <EOL> self . connections = [ ] <EOL> self . disconnections = [ ] <EOL> def targets ( self , object , reftype ) : <EOL> return self . result <EOL> def connect ( self , source , target , reftype ) : <EOL> self . connections . append ( ( source , target , reftype ) ) <EOL> def disconnect ( self , source , target , reftype ) : <EOL> self . disconnections . append ( ( source , target , reftype ) ) <EOL> class DummyEvent ( object ) : <EOL> def __init__ ( self , ** kw ) : <EOL> self . __dict__ . update ( kw ) <EOL> class DummyRegistry ( object ) : <EOL> def subscribers ( self , * arg ) : <EOL> return </s>
