[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Event/tests - __init__.py:1.1 testDirectives.py:1.1

Jim Fulton jim@zope.com
Wed, 18 Dec 2002 18:37:00 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv25839/lib/python/Zope/App/Event/tests

Added Files:
	__init__.py testDirectives.py 
Log Message:
Cleaned up after some other checkins.

- Fixed some zcml files that weren't fixed in a refactoring.
  This prevented Zope from starting.

- Renamed some modules that had invalid module names.
  Created some packages for these as well. Moved some tests around
  Fixed up file references to reflect changes.




=== Added File Zope3/lib/python/Zope/App/Event/tests/__init__.py ===
#


=== Added File Zope3/lib/python/Zope/App/Event/tests/testDirectives.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

Revision information:
$Id: testDirectives.py,v 1.1 2002/12/18 23:36:58 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from StringIO import StringIO

from Zope.Configuration.xmlconfig import xmlconfig

from Zope.Exceptions import NotFoundError
from Zope.Event import subscribe, unsubscribe, publish
from Zope.Event.ObjectEvent import ObjectAddedEvent
from Zope.Event.ObjectEvent import ObjectRemovedEvent
from Zope.Event.ObjectEvent import ObjectModifiedEvent
from Zope.Event.tests.testEventService \
     import DummySubscriber, DummyFilter, DummyEvent
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture import getServiceManager, getService
from Zope.Configuration.tests.BaseTestDirectivesXML import makeconfig


class Test(PlacelessSetup, TestCase):
    
    def setUp(self):
        PlacelessSetup.setUp(self)
        from Zope.Event.IEventService import IEventService
        getServiceManager(None).defineService("Events", IEventService)
        from Zope.Event.GlobalEventService import eventService
        getServiceManager(None).provideService("Events", eventService)

    def testSubscribe(self):
        from Zope.Event.tests.subscriber import subscriber
        # This should fail, since we're not subscribed
        self.assertRaises(NotFoundError,unsubscribe,None,subscriber)
            
        xmlconfig(makeconfig(
            '''<directive
                   name="subscribe"
                   attributes="subscriber event_types filter"
                   handler="Zope.App.Event.metaConfigure.subscribe" />''',
            '''<test:subscribe
                   subscriber="Zope.Event.tests.subscriber.subscriber"
                   event_types=
                       "Zope.Event.IObjectEvent.IObjectAddedEvent
                        Zope.Event.IObjectEvent.IObjectRemovedEvent"
                   filter="Zope.Event.tests.subscriber.filter" />'''
            ))

        publish(None,ObjectAddedEvent(None, 'foo'))
        self.assertEqual(subscriber.notified,1)
        publish(None,ObjectRemovedEvent(object(), 'foo'))
        self.assertEqual(subscriber.notified,2)
        publish(None,ObjectModifiedEvent(None, 'foo'))
        self.assertEqual(subscriber.notified,2) # NB: no increase ;-)
        publish(None,DummyEvent())
        self.assertEqual(subscriber.notified,4) # NB: increased by 2 ;-)
        
        unsubscribe(subscriber)

def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')