[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/appsetup/tests.py Refactore tests with the use of the new subscriber. This module still lakes of tests. We should test all the functions provided by the boostap module

Julien Anguenot ja at nuxeo.com
Tue Oct 12 14:10:23 EDT 2004


Log message for revision 28022:
  Refactore tests with the use of the new subscriber. This module still lakes of tests. We should test all the functions provided by the boostap module


Changed:
  U   Zope3/trunk/src/zope/app/appsetup/tests.py


-=-
Modified: Zope3/trunk/src/zope/app/appsetup/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/appsetup/tests.py	2004-10-12 18:09:23 UTC (rev 28021)
+++ Zope3/trunk/src/zope/app/appsetup/tests.py	2004-10-12 18:10:21 UTC (rev 28022)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2003 Zope Corporation and Contributors.
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -22,22 +22,30 @@
 
 from zope.app.folder import rootFolder
 from zope.app.folder.interfaces import IRootFolder
+from zope.app.traversing.api import traverse
 from zope.app.errorservice.interfaces import IErrorReportingService
 from zope.app.principalannotation.interfaces import IPrincipalAnnotationService
 from zope.app.publication.zopepublication import ZopePublication
 from zope.app.site.tests.placefulsetup import PlacefulSetup
+from zope.app.servicenames import ErrorLogging, Utilities
 from zope.app.errorservice import ErrorReportingService
-from zope.app.servicenames import ErrorLogging
 from zope.app.traversing.api import traverse
 from zope.app.site.service import ServiceManager
 
+from zope.app.appsetup.bootstrap import bootStrapSubscriber
+from zope.app.appsetup.bootstrap import addService, configureService, \
+     ensureService, getInformationFromEvent, getServiceManager, ensureObject
+
 class EventStub(object):
 
     def __init__(self, db):
         self.database = db
 
+#
+# XXX some methods from the boostap modue are not tested
+#
 
-class TestBootstrapSubscriberBase(PlacefulSetup, unittest.TestCase):
+class TestBootstrapSubscriber(PlacefulSetup, unittest.TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self)
@@ -65,36 +73,33 @@
         get_transaction().commit()
         cx.close()
 
-
     def test_notify(self):
-        from zope.app.appsetup.bootstrap import BootstrapSubscriberBase
-
         for setup in (lambda: None), self.createRootFolder, self.createRFAndSM:
-
             setup()
+        bootStrapSubscriber(EventStub(self.db))
+        cx = self.db.open()
+        root = cx.root()
+        root_folder = root.get(ZopePublication.root_name, None)
+        self.assert_(IRootFolder.providedBy(root_folder))
+        package_name = '/++etc++site/default'
+        package = traverse(root_folder, package_name)
+        cx.close()
 
-            BootstrapSubscriberBase()(EventStub(self.db))
-
-            cx = self.db.open()
-            root = cx.root()
-            root_folder = root.get(ZopePublication.root_name, None)
-            self.assert_(IRootFolder.providedBy(root_folder))
-
-            package_name = '/++etc++site/default'
-            package = traverse(root_folder, package_name)
-
-            cx.close()
-
     def test_ensureService(self):
-        from zope.app.appsetup.bootstrap import BootstrapSubscriberBase
-
         self.createRFAndSM()
-        bs = BootstrapSubscriberBase()
-        bs(EventStub(self.db))
+        self.createRootFolder()
+
+        db, connection ,root, root_folder = getInformationFromEvent(
+            EventStub(self.db))
+
+        # XXX check EventSub
+        root_folder = self.root_folder
+        service_manager = getServiceManager(root_folder)
         for i in range(2):
             cx = self.db.open()
-            name = bs.ensureService(ErrorLogging, ErrorReportingService)
-
+            name = ensureService(service_manager, root_folder,
+                                 ErrorLogging,
+                                 ErrorReportingService)
             if i == 0:
                 self.assertEqual(name, 'ErrorLogging')
             else:
@@ -104,72 +109,17 @@
             root_folder = root[ZopePublication.root_name]
 
             package_name = '/++etc++site/default'
-            package = traverse(root_folder, package_name)
+            package = traverse(self.root_folder, package_name)
 
             self.assert_(IErrorReportingService.providedBy(
                 traverse(package, 'ErrorLogging')))
             get_transaction().commit()
             cx.close()
 
-class TestBootstrapInstance(TestBootstrapSubscriberBase):
-
-    def test_bootstrapInstance(self):
-        from zope.app.appsetup.bootstrap import bootstrapInstance
-
-        bootstrapInstance(EventStub(self.db))
-
-        cx = self.db.open()
-        root = cx.root()
-        root_folder = root[ZopePublication.root_name]
-
-        package_name = '/++etc++site/default'
-        package = traverse(root_folder, package_name)
-
-        self.assert_(IErrorReportingService.providedBy(
-            traverse(package, 'ErrorLogging')))
-
-        self.assert_(IPrincipalAnnotationService.providedBy(
-            traverse(package, 'PrincipalAnnotation')))
-
-        cx.close()
-
-    def test_bootstrapInstance_withServices(self):
-        from zope.app.appsetup.bootstrap import bootstrapInstance
-        from zope.app.appsetup.bootstrap import addService, configureService
-
-        self.createRFAndSM()
-
-        name = addService(self.root_folder, 'Errors',
-                          ErrorReportingService, copy_to_zlog=True)
-        configureService(self.root_folder, ErrorLogging, name)
-
-        bootstrapInstance(EventStub(self.db))
-
-        cx = self.db.open()
-        root = cx.root()
-        root_folder = root[ZopePublication.root_name]
-
-        package_name = '/++etc++site/default'
-        package = traverse(root_folder, package_name)
-
-        self.assertRaises(NotFoundError, traverse, root_folder,
-                          '/++etc++site/default/ErrorLogging')
-
-        self.assert_(IErrorReportingService.providedBy(
-            traverse(package, 'Errors')))
-
-        self.assert_(IPrincipalAnnotationService.providedBy(
-            traverse(package, 'PrincipalAnnotation')))
-
-        cx.close()
-
-
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TestBootstrapSubscriberBase))
-    suite.addTest(unittest.makeSuite(TestBootstrapInstance))
+    suite.addTest(unittest.makeSuite(TestBootstrapSubscriber))
     return suite
 
-
 if __name__ == '__main__':
     unittest.main()



More information about the Zope3-Checkins mailing list