[Zope3-checkins] CVS: Zope3/src/zope/app/index/text/tests - test_index.py:1.5

Steve Alexander steve@cat-box.net
Mon, 30 Dec 2002 09:03:42 -0500


Update of /cvs-repository/Zope3/src/zope/app/index/text/tests
In directory cvs.zope.org:/tmp/cvs-serv23914/src/zope/app/index/text/tests

Modified Files:
	test_index.py 
Log Message:
Large refactoring of the event service.


=== Zope3/src/zope/app/index/text/tests/test_index.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/index/text/tests/test_index.py:1.4	Sat Dec 28 12:49:27 2002
+++ Zope3/src/zope/app/index/text/tests/test_index.py	Mon Dec 30 09:03:08 2002
@@ -21,12 +21,11 @@
 from zope.component.adapter import provideAdapter
 from zope.app.event.objectevent import ObjectModifiedEvent
 
-from zope.app.services.tests.placefulsetup import \
-     PlacefulSetup
+from zope.app.services.tests.placefulsetup import PlacefulSetup
 
 from zope.app.interfaces.traversing import ITraverser
-from zope.app.traversing import locationAsUnicode
-
+from zope.app.traversing import locationAsUnicode, traverse
+from zope.component import getService
 from zope.app.interfaces.services.hub import \
      IRegistrationHubEvent, IObjectModifiedHubEvent
 from zope.app.services.hub import \
@@ -45,17 +44,6 @@
     def getSearchableText(self):
         return self.texts
 
-class FakeTraverser:
-    __implements__ = ITraverser
-    def __init__(self, object, location):
-        self.__object = object
-        self.__location = location
-    def traverse(self, path):
-        canonical_path = locationAsUnicode(path)
-        if canonical_path == self.__location:
-            return self.__object
-        raise KeyError, (path, canonical_path)
-
 Bruce = u"Bruce"
 Sheila = u"Sheila"
 
@@ -63,8 +51,11 @@
 
     def setUp(self):
         PlacefulSetup.setUp(self)
+        self.buildFolders()
         self.index = TextIndex()
+        self.rootFolder.setObject('myIndex', self.index)
         self.object = FakeSearchableObject()
+        self.rootFolder.setObject('bruce', self.object)
 
     def assertPresent(self, word, docid):
         results, total = self.index.query(word)
@@ -102,12 +93,14 @@
 
     def testHubMachinery(self):
         # Technically this is a functional test
-        hub = ObjectHub()
-        hub.subscribe(self.index, IRegistrationHubEvent)
-        hub.subscribe(self.index, IObjectModifiedHubEvent)
+        self.createStandardServices()
+        index = traverse(self.rootFolder, '/myIndex')
+        hub = getService(self.rootFolder, 'HubIds')
+        
+        hub.subscribe(index, IRegistrationHubEvent)
+        hub.subscribe(index, IObjectModifiedHubEvent)
         location = "/bruce"
-        traverser = FakeTraverser(self.object, location)
-        provideAdapter(None, ITraverser, lambda dummy: traverser)
+        self.rootFolder.setObject(location, self.object)
 
         hubid = hub.register(location)
         self.assertPresent(Bruce, hubid)
@@ -123,21 +116,23 @@
         self.assertAbsent(Sheila)
 
     def testBootstrap(self):
-        self.assertEqual(self.index.isSubscribed(), False)
+        # Need to set up a HubIds service because the standard subscription
+        # mix-ins expect to see one.
+        self.createStandardServices()
+    
+        index = traverse(self.rootFolder, '/myIndex')
+        self.assertEqual(index.isSubscribed(), False)
         self.assertAbsent(Bruce)
         self.assertAbsent(Sheila)
-
-        hub = ObjectHub()
-        location = "/bruce"
-        traverser = FakeTraverser(self.object, location)
-        provideAdapter(None, ITraverser, lambda dummy: traverser)
+        location = '/bruce'
+        hub = getService(self.rootFolder, 'HubIds')
         hubid = hub.register(location)
-        self.index.subscribe(hub)
-        self.assertEqual(self.index.isSubscribed(), True)
+        index.subscribe(hub)
+        self.assertEqual(index.isSubscribed(), True)
         self.assertPresent(Bruce, hubid)
 
-        self.index.unsubscribe(hub)
-        self.assertEqual(self.index.isSubscribed(), False)
+        index.unsubscribe(hub)
+        self.assertEqual(index.isSubscribed(), False)
         self.assertPresent(Bruce, hubid)
 
         self.object.texts = [Sheila]