[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_connectionservice.py:1.13 test_connectionregistration.py:NONE

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 04:10:05 EDT 2003


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

Modified Files:
	test_connectionservice.py 
Removed Files:
	test_connectionregistration.py 
Log Message:
Heads up, this is the beginning of Servicegeddon. We noticed that named 
components are a pain in the butt and that we can simpluify our code a lot
by making these named components local utilities. 

So I started with the SQL Connection service and database adapters and 
simplified the code greatly. Database Adaptors are now just simple 
utilities.

I also took the oppurtunity and updated all database adapters. 

This change is not backward compatible and you will have to toss your ZODB.
Although all tests pass, I expect there to be some hickups, so feel free to 
fix or report these. 

Next I will fix up the front screen a bit and try to factor some other 
pieces. I also still miss some functionality in the Utilities, which I plan
to add.




=== Zope3/src/zope/app/services/tests/test_connectionservice.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/services/tests/test_connectionservice.py:1.12	Sat Jun 21 17:22:13 2003
+++ Zope3/src/zope/app/services/tests/test_connectionservice.py	Tue Aug 19 03:09:57 2003
@@ -17,22 +17,20 @@
 
 import unittest
 
+from zope.app import zapi
 from zope.app.interfaces.annotation import IAttributeAnnotatable
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
-from zope.app.interfaces.services.registration import RegisteredStatus
-from zope.app.interfaces.services.registration import ActiveStatus
-from zope.app.interfaces.services.registration import IAttributeRegisterable
-from zope.app.services.connection import ConnectionRegistration
+from zope.app.interfaces.services.connection import ILocalConnectionService
+from zope.app.interfaces.services.registration import \
+     ActiveStatus, RegisteredStatus
+from zope.app.interfaces.services.utility import ILocalUtility
 from zope.app.services.connection import ConnectionService
-from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.app.services.servicenames import SQLDatabaseConnections, Utilities
+from zope.app.services.utility import LocalUtilityService, UtilityRegistration
 from zope.app.tests import setup
-from zope.app import zapi
+from zope.component import getServiceManager
 from zope.interface import implements
 
-class ConnectionServiceForTests(ConnectionService):
-
-    implements(IAttributeRegisterable)
-
 class DAStub:
 
     implements(IZopeDatabaseAdapter, IAttributeAnnotatable)
@@ -49,75 +47,73 @@
     return list
 
 
-class TestConnectionService(unittest.TestCase, PlacefulSetup):
+def addConnection(servicemanager, name, connection, status=ActiveStatus):
+    """Add a menu to the service manager's default package."""
+    default = zapi.traverse(servicemanager, 'default')
+    default.setObject(name, connection)
+    path = "%s/default/%s" % (zapi.getPath(servicemanager), name)
+    registration = UtilityRegistration(name, IZopeDatabaseAdapter, path)
+    key = default.getRegistrationManager().setObject("", registration)
+    zapi.traverse(default.getRegistrationManager(), key).status = status
+    return zapi.traverse(default, name)    
+
+
+class TestConnectionService(unittest.TestCase):
 
     def setUp(self):
-        sm = PlacefulSetup.setUp(self, site=True)
-        self.service = setup.addService(sm, 'SQLDatabaseConnections',
-                                        ConnectionServiceForTests())
-        self.default = zapi.traverse(sm, 'default')
-
-        self.default.setObject('da1', DAStub(1))
-        self.default.setObject('da2', DAStub(2))
-
-        self.cm = self.default.getRegistrationManager()
-
-        k = self.cm.setObject('', ConnectionRegistration('conn1',
-                                '/++etc++site/default/da1'))
-        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
-        k = self.cm.setObject('', ConnectionRegistration('conn2',
-                                '/++etc++site/default/da2'))
-        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
-        k = self.cm.setObject('', ConnectionRegistration('conn3',
-                                '/++etc++site/default/da1'))
-        zapi.traverse(self.default.getRegistrationManager(),
-                 k).status = RegisteredStatus
-        # Now self.service has conn1 and conn2 available and knows about conn3
-
-        sm = self.makeSite('folder1')
-        self.service1 = setup.addService(sm, 'SQLDatabaseConnections',
-                                         ConnectionServiceForTests())
-
-        default1 = zapi.traverse(sm, 'default')
-        default1.setObject('da3', DAStub(3))
-        default1.setObject('da4', DAStub(4))
-
-        cm1 = default1.getRegistrationManager()
-
-        k = cm1.setObject('', ConnectionRegistration('conn1',
-                            '/folder1/++etc++site/default/da3'))
-        zapi.traverse(default1.getRegistrationManager(), k).status = ActiveStatus
-        k = cm1.setObject('', ConnectionRegistration('conn4',
-                            '/folder1/++etc++site/default/da4'))
-        zapi.traverse(default1.getRegistrationManager(), k).status = ActiveStatus
-        # Now self.service1 overrides conn1, adds new conn4 available, and
-        # inherits conn2 from self.service
+        setup.placefulSetUp()
+        self.rootFolder = setup.buildSampleFolderTree()
+
+        # Define Connection Service
+        sm=getServiceManager(None)
+        sm.defineService(SQLDatabaseConnections, ILocalConnectionService)
+
+        # Create Components in root folder
+        mgr = setup.createServiceManager(self.rootFolder)
+        setup.addService(mgr, Utilities, LocalUtilityService())
+
+        self.service = setup.addService(mgr, SQLDatabaseConnections,
+                                        ConnectionService())
+
+        conn = addConnection(mgr, 'conn1', DAStub(1))
+        conn = addConnection(mgr, 'conn2', DAStub(2))
+        conn = addConnection(mgr, 'conn3', DAStub(3), RegisteredStatus)
+
+        mgr = setup.createServiceManager(
+            zapi.traverse(self.rootFolder, 'folder1'))
+        setup.addService(mgr, Utilities, LocalUtilityService())
+
+        self.service1 = setup.addService(mgr, SQLDatabaseConnections,
+                                         ConnectionService())
+
+        conn = addConnection(mgr, 'conn1', DAStub(3))
+        conn = addConnection(mgr, 'conn4', DAStub(4))
 
     def testGetConnection(self):
-        self.assertEqual('DA #1', self.service.getConnection('conn1'))
-        self.assertEqual('DA #2', self.service.getConnection('conn2'))
+        self.assertEqual('DA #1', self.service.getConnection('conn1')())
+        self.assertEqual('DA #2', self.service.getConnection('conn2')())
         self.assertRaises(KeyError, self.service.getConnection, 'conn3')
         self.assertRaises(KeyError, self.service.getConnection, 'conn4')
 
-        self.assertEqual('DA #3', self.service1.getConnection('conn1'))
-        self.assertEqual('DA #2', self.service1.getConnection('conn2'))
+        self.assertEqual('DA #3', self.service1.getConnection('conn1')())
+        self.assertEqual('DA #2', self.service1.getConnection('conn2')())
         self.assertRaises(KeyError, self.service1.getConnection, 'conn3')
-        self.assertEqual('DA #4', self.service1.getConnection('conn4'))
+        self.assertEqual('DA #4', self.service1.getConnection('conn4')())
         self.assertRaises(KeyError, self.service1.getConnection, 'conn5')
 
     def testQueryConnection(self):
-        self.assertEqual('DA #1', self.service.queryConnection('conn1'))
-        self.assertEqual('DA #2', self.service.queryConnection('conn2'))
+        self.assertEqual('DA #1', self.service.queryConnection('conn1')())
+        self.assertEqual('DA #2', self.service.queryConnection('conn2')())
         self.assertEqual(None, self.service.queryConnection('conn3'))
         self.assertEqual('xx', self.service.queryConnection('conn3', 'xx'))
         self.assertEqual(None, self.service.queryConnection('conn4'))
         self.assertEqual('xx', self.service.queryConnection('conn4', 'xx'))
 
-        self.assertEqual('DA #3', self.service1.queryConnection('conn1'))
-        self.assertEqual('DA #2', self.service1.queryConnection('conn2'))
+        self.assertEqual('DA #3', self.service1.queryConnection('conn1')())
+        self.assertEqual('DA #2', self.service1.queryConnection('conn2')())
         self.assertEqual(None, self.service1.queryConnection('conn3'))
         self.assertEqual('xx', self.service1.queryConnection('conn3', 'xx'))
-        self.assertEqual('DA #4', self.service1.queryConnection('conn4'))
+        self.assertEqual('DA #4', self.service1.queryConnection('conn4')())
         self.assertEqual(None, self.service1.queryConnection('conn5'))
         self.assertEqual('xx', self.service1.queryConnection('conn5', 'xx'))
 

=== Removed File Zope3/src/zope/app/services/tests/test_connectionregistration.py ===




More information about the Zope3-Checkins mailing list