[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_registration.py:1.1

Anthony Baxter anthony@interlink.com.au
Fri, 11 Jul 2003 01:50:54 -0400


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv13561/src/zope/app/services/tests

Added Files:
	test_registration.py 
Log Message:
Moved the Registration object from zope.app.index to zope.app.services.hub,
and changed the bootstrap code to add a Registration object if there is not
already one installed. This means that by default the ObjectHub is now 
actually doing something, rather than sitting by itself feeling lonely.

When a Registration object is added by bootstrap, it's subscribed by
default.


=== Added File Zope3/src/zope/app/services/tests/test_registration.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.
##############################################################################
"""
$Id: test_registration.py,v 1.1 2003/07/11 05:50:50 anthony Exp $
"""

from unittest import makeSuite, main, TestCase

from zope.app.services.hub import Registration
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.traversing import traverse, canonicalPath
from zope.app.event.objectevent import ObjectAddedEvent
from zope.component import getService
from zope.app.services.servicenames import EventPublication, HubIds

class TestRegistration(PlacefulSetup, TestCase):
    def setUp(self):
        PlacefulSetup.setUp(self, site=True)
        self.createStandardServices()
        r = Registration()
        default = traverse(self.rootFolder, '++etc++site/default')
        default.setObject('registrar', r)
        self.registrar = traverse(default, 'registrar')
        self.hub = getService(self.rootFolder, HubIds)
        self.events = getService(self.rootFolder, EventPublication)

    def testSubscribeUnsubscribe(self):
        r = self.registrar
        self.assertEqual(r.isSubscribed(), False)
        r.subscribe()
        self.assertEqual(r.isSubscribed(), True)
        self.assertRaises(RuntimeError, r.subscribe)
        r.unsubscribe()
        self.assertEqual(r.isSubscribed(), False)
        self.assertRaises(RuntimeError, r.unsubscribe)

    def testRegister(self):
        self.registrar.subscribe()
        self.assertEqual(self.hub.numRegistrations(), 0)
        content = object()
        name = 'blah'

        event = ObjectAddedEvent(content, canonicalPath('/%s' % name))
        self.events.publish(event)
        self.assertEqual(self.hub.numRegistrations(), 1)

    def testRegisterExisting(self):
        self.registrar.subscribe()
        self.registrar.registerExisting()
        # there are ten folders set up by PlacefulSetup that
        # should get registered
        self.assertEqual(self.hub.numRegistrations(), 10)

def test_suite():
    return makeSuite(TestRegistration)

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