[Zope-CVS] CVS: Products/EventListenerTool/tests - testListenerTool.py:1.3

Chris McDonough chrism@zope.com
Wed, 8 Jan 2003 14:37:40 -0500


Update of /cvs-repository/Products/EventListenerTool/tests
In directory cvs.zope.org:/tmp/cvs-serv32763/tests

Modified Files:
	testListenerTool.py 
Log Message:
Merge changes from Tres into public package.


=== Products/EventListenerTool/tests/testListenerTool.py 1.2 => 1.3 ===
--- Products/EventListenerTool/tests/testListenerTool.py:1.2	Tue Jan  7 13:26:37 2003
+++ Products/EventListenerTool/tests/testListenerTool.py	Wed Jan  8 14:37:07 2003
@@ -37,6 +37,7 @@
 class EventSetupTestBase:
 
     _old_event_registry_lookup = None
+    _old_event_registry_enumeration = None
     _old_logger = None
     _logged = None
 
@@ -46,21 +47,35 @@
         def _lookup( moniker, _MONIKER=_MONIKER ):
             return moniker == _MONIKER and IDummyEvent or None
 
+        def _enumeration( with_metadata=0 ):
+            if not with_metadata:
+                return [ 'IDummyEvent' ]
+
+            return [ ( 'IDummyEvent'
+                     , 'Dummy Event'
+                     , 'Dummy Event Description'
+                     ) ]
+
         from Products.EventListenerTool.ListenerTool import \
-             _setEventRegistryLookup
+             _setEventRegistryLookup, _setEventRegistryEnumeration
 
         self._old_event_registry_lookup = _setEventRegistryLookup( _lookup )
+        self._old_event_registry_enumeration = _setEventRegistryEnumeration(
+                                                                _enumeration )
 
         return _MONIKER
 
     def _restoreEventRegistry( self ):
 
         from Products.EventListenerTool.ListenerTool import \
-             _setEventRegistryLookup
+             _setEventRegistryLookup, _setEventRegistryEnumeration
 
         if self._old_event_registry_lookup is not None:
             _setEventRegistryLookup( self._old_event_registry_lookup )
 
+        if self._old_event_registry_enumeration is not None:
+            _setEventRegistryEnumeration( self._old_event_registry_enumeration )
+
     def _prepLogger( self ):
 
         from Products.EventListenerTool.ListenerTool import _setLogger
@@ -159,6 +174,7 @@
         self.assertEqual( rule.getMoniker(), MONIKER )
         self.assertEqual( rule.getCondition(), PASSALL )
         self.assertEqual( rule.listActions(), ACTIONS )
+        self.failUnless( rule.isEnabled() )
 
     def test_notify_passall( self ):
 
@@ -177,6 +193,33 @@
         self.assertEqual( event.handled_by.get( 'second_action', 0 ), 1 )
         self.assertEqual( event.handled_by.get( 'other_action', 0 ), 0 )
 
+    def test_setEnabled( self ):
+
+        MONIKER = self._prepEventRegistry()
+        root = self._prepRootObject()
+        event = DummyEvent()
+
+        rule = self._makeOne( moniker=MONIKER
+                            , condition='python: 1'
+                            , actions=( 'first_action', 'second_action' )
+                            ).__of__( root )
+
+        rule.setEnabled( 0 )
+        self.failIf( rule.isEnabled() )
+
+        rule.notify( event )
+
+        self.assertEqual( event.handled_by.get( 'first_action', 0 ), 0 )
+        self.assertEqual( event.handled_by.get( 'second_action', 0 ), 0 )
+
+        rule.setEnabled( 1 )
+        self.failUnless( rule.isEnabled() )
+
+        rule.notify( event )
+
+        self.assertEqual( event.handled_by.get( 'first_action', 0 ), 1 )
+        self.assertEqual( event.handled_by.get( 'second_action', 0 ), 1 )
+
     def test_notify_passnone( self ):
 
         MONIKER = self._prepEventRegistry()
@@ -392,6 +435,28 @@
 
         self.assertEqual( foo_counter.getCount(), 2 )
         self.assertEqual( bar_counter.getCount(), 1 )
+
+    def test_getEventTypeInfo( self ):
+
+        tool = self._makeOne()
+        MONIKER = self._prepEventRegistry()
+        UNKNOWN = 'UNKNOWN'
+
+        info = tool.getEventTypeInfo( MONIKER )
+
+        self.assertEqual( info[ 'moniker' ], MONIKER )
+        self.assertEqual( info[ 'name' ], MONIKER.split( '.' )[ -1 ] )
+        self.assertEqual( info[ 'title' ], 'Dummy Event' )
+        self.assertEqual( info[ 'description' ], 'Dummy Event Description' )
+
+        self.assertRaises( KeyError, tool.getEventTypeInfo, UNKNOWN )
+
+        broken = tool.getEventTypeInfo( UNKNOWN, 0 )
+
+        self.assertEqual( broken[ 'moniker' ], UNKNOWN )
+        self.assertEqual( broken[ 'name' ], 'Broken!' )
+        self.assertEqual( broken[ 'title' ], UNKNOWN )
+        self.assertEqual( broken[ 'description' ], 'Broken Event' )
 
 
 class DummyEventsTool( SimpleItem ):