<s> import json <EOL> import unittest <EOL> from pyramid import testing <EOL> import mock <EOL> class Test_acl_modified ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request = testing . DummyRequest ( ) <EOL> self . config = testing . setUp ( request = self . request ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import acl_modified <EOL> return acl_modified ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it ( self , mock_get_auditlog ) : <EOL> from substanced . audit import AuditLog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> auditlog = AuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> context . __oid__ = <NUM_LIT:5> <EOL> event . registry = _makeRegistry ( ) <EOL> event . object = context <EOL> event . old_acl = '<STR_LIT>' <EOL> event . new_acl = '<STR_LIT>' <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:5> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_nolog ( self , mock_get_auditlog ) : <EOL> mock_get_auditlog . side_effect = lambda c : None <EOL> event = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> context . __oid__ = <NUM_LIT:5> <EOL> event . object = context <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> _marker = object ( ) <EOL> class Test_content_added_moved_or_duplicated ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request = testing . DummyRequest ( ) <EOL> self . config = testing . setUp ( request = self . request ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import content_added_moved_or_duplicated <EOL> return content_added_moved_or_duplicated ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_added ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = _makeEvent ( ) <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:10> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:object_name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> '<STR_LIT>' : <NUM_LIT:5> <EOL> } <EOL> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_added_noscribe ( self , mock_get_auditlog ) : <EOL> mock_get_auditlog . side_effect = lambda c : None <EOL> event = _makeEvent ( ) <EOL> self . _callFUT ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_moved ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = _makeEvent ( ) <EOL> event . moving = True <EOL> event . duplicating = None <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:10> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:object_name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> '<STR_LIT>' : <NUM_LIT:5> <EOL> } <EOL> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_duplicated ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = _makeEvent ( ) <EOL> event . moving = None <EOL> event . duplicating = True <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:10> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:object_name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> '<STR_LIT>' : <NUM_LIT:5> <EOL> } <EOL> ) <EOL> class Test_content_removed ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request = testing . DummyRequest ( ) <EOL> self . config = testing . setUp ( request = self . request ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import content_removed <EOL> return content_removed ( event ) <EOL> def test_it_moving ( self ) : <EOL> event = Dummy ( ) <EOL> event . moving = True <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = _makeEvent ( ) <EOL> event . moving = None <EOL> event . duplicating = None <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:10> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:object_name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> '<STR_LIT>' : <NUM_LIT:5> <EOL> } <EOL> ) <EOL> class Test_content_modified ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request = testing . DummyRequest ( ) <EOL> self . config = testing . setUp ( request = self . request ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import content_modified <EOL> return content_modified ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_noscribe ( self , mock_get_auditlog ) : <EOL> mock_get_auditlog . side_effect = lambda c : None <EOL> event = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> event . object = context <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> self . request . user = Dummy ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> event = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> context . __oid__ = <NUM_LIT:5> <EOL> event . registry = _makeRegistry ( ) <EOL> event . object = context <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , <NUM_LIT:5> ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> } , <EOL> ) <EOL> class Test_logged_in ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request = testing . DummyRequest ( ) <EOL> self . config = testing . setUp ( request = self . request ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import logged_in <EOL> return logged_in ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_noscribe ( self , mock_get_auditlog ) : <EOL> mock_get_auditlog . side_effect = lambda c : None <EOL> event = Dummy ( ) <EOL> event . request = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> event . request . context = context <EOL> self . assertEqual ( self . _callFUT ( event ) , None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_user_has_oid ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> event = Dummy ( ) <EOL> event . request = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> event . request . context = context <EOL> user = Dummy ( ) <EOL> user . __oid__ = <NUM_LIT:5> <EOL> event . user = user <EOL> event . login = '<STR_LIT>' <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , None ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> } , <EOL> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it_user_has_no_oid ( self , mock_get_auditlog ) : <EOL> auditlog = _makeAuditLog ( ) <EOL> mock_get_auditlog . side_effect = lambda c : auditlog <EOL> event = Dummy ( ) <EOL> event . request = Dummy ( ) <EOL> context = testing . DummyResource ( ) <EOL> event . request . context = context <EOL> user = Dummy ( ) <EOL> event . user = user <EOL> event . login = '<STR_LIT>' <EOL> self . _callFUT ( event ) <EOL> self . assertEqual ( len ( auditlog ) , <NUM_LIT:1> ) <EOL> entries = list ( auditlog . entries ) <EOL> entry = entries [ <NUM_LIT:0> ] <EOL> self . assertEqual ( entry [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( entry [ <NUM_LIT:2> ] . oid , None ) <EOL> self . assertEqual ( <EOL> json . loads ( entry [ <NUM_LIT:2> ] . payload ) , <EOL> { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : entry [ <NUM_LIT:2> ] . timestamp , <EOL> } , <EOL> ) <EOL> class Test_root_added ( unittest . TestCase ) : <EOL> def _callFUT ( self , event ) : <EOL> from . . subscribers import root_added <EOL> return root_added ( event ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_it ( self , mock_set_auditlog ) : <EOL> event = Dummy ( ) <EOL> root = Dummy ( ) <EOL> def is_set ( _root ) : <EOL> self . assertEqual ( _root , root ) <EOL> mock_set_auditlog . side_effect = is_set <EOL> event . object = root <EOL> self . _callFUT ( event ) <EOL> class Dummy ( object ) : <EOL> def __init__ ( self , kw = None ) : <EOL> if kw : <EOL> self . __dict__ . update ( kw ) <EOL> class DummyContentRegistry ( object ) : <EOL> def typeof ( self , content ) : <EOL> return '<STR_LIT>' <EOL> def _makeAuditLog ( ) : <EOL> from substanced . audit import AuditLog <EOL> auditlog = AuditLog ( ) <EOL> return auditlog <EOL> def _makeRegistry ( ) : <EOL> registry = Dummy ( ) <EOL> registry . content = DummyContentRegistry ( ) <EOL> return registry <EOL> def _makeEvent ( ) : <EOL> event = Dummy ( ) <EOL> event . moving = None <EOL> event . duplicating = None <EOL> event . parent = testing . DummyResource ( ) <EOL> event . parent . __oid__ = <NUM_LIT:10> <EOL> event . name = '<STR_LIT>' <EOL> context = testing . DummyResource ( ) <EOL> context . __oid__ = <NUM_LIT:5> <EOL> context . __parent__ = event . parent <EOL> event . registry = _makeRegistry ( ) <EOL> event . object = context <EOL> event . old_acl = '<STR_LIT>' <EOL> event . new_acl = '<STR_LIT>' <EOL> return event </s>
