[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests - testConnectionService.py:1.5.2.2

Marius Gedminas mgedmin@codeworks.lt
Wed, 11 Dec 2002 07:20:38 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests
In directory cvs.zope.org:/tmp/cvs-serv28934/lib/python/Zope/App/OFS/Services/ConnectionService/tests

Modified Files:
      Tag: named-component-configuration-branch
	testConnectionService.py 
Log Message:
ConnectionService refactoring and bugfixes
Removed a bunch of decoys from Zope.App.OFS.Services subtree


=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py 1.5.2.1 => 1.5.2.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py:1.5.2.1	Tue Dec 10 14:16:01 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py	Wed Dec 11 07:20:08 2002
@@ -52,8 +52,11 @@
 
     __implements__ = IZopeDatabaseAdapter, IAttributeAnnotatable
 
+    def __init__(self, n):
+        self.n = n
+
     def __call__(self):
-        return 'Connection'
+        return 'DA #%d' % self.n
 
 
 def sort(list):
@@ -70,46 +73,92 @@
                        IAnnotations, AttributeAnnotations)
         provideAdapter(IAnnotatable, IDependable, Dependable)
 
+        # Set up a local connection service
         self.buildFolders()
         self.rootFolder.setServiceManager(ServiceManager())
-        sm = self.rootFolder.getServiceManager()
 
         self.default = traverse(self.rootFolder,
-                           '++etc++Services/Packages/default')
+                                '++etc++Services/Packages/default')
         self.default.setObject('conn_srv', ConnectionServiceForTests())
         self.service = traverse(self.default, 'conn_srv')
 
         self.cm = ZopeContainerAdapter(traverse(self.default, "configure"))
         self.cm.setObject('', ServiceConfiguration('SQLDatabaseConnections',
-                            '/++etc++Services/Packages/default/conn_srv'))
+                                '/++etc++Services/Packages/default/conn_srv'))
         traverse(self.default, 'configure/1').status = Active
 
-        self.default.setObject('da1', DAStub())
-        self.default.setObject('da2', DAStub())
+        self.default.setObject('da1', DAStub(1))
+        self.default.setObject('da2', DAStub(2))
 
         self.cm.setObject('', ConnectionConfiguration('conn1',
-                            '/++etc++Services/Packages/default/da1'))
+                                '/++etc++Services/Packages/default/da1'))
         traverse(self.default, 'configure/2').status = Active
         self.cm.setObject('', ConnectionConfiguration('conn2',
-                            '/++etc++Services/Packages/default/da2'))
+                                '/++etc++Services/Packages/default/da2'))
         traverse(self.default, 'configure/3').status = Active
+        self.cm.setObject('', ConnectionConfiguration('conn3',
+                                '/++etc++Services/Packages/default/da1'))
+        traverse(self.default, 'configure/4').status = Registered
+        # Now self.service has conn1 and conn2 available and knows about conn3
+
+        # Set up a more local connection service
+        folder1 = traverse(self.rootFolder, 'folder1')
+        folder1.setServiceManager(ServiceManager())
+
+        default1 = traverse(folder1, '++etc++Services/Packages/default')
+        default1.setObject('conn_srv1', ConnectionServiceForTests())
+        self.service1 = traverse(default1, 'conn_srv1')
+
+        cm1 = ZopeContainerAdapter(traverse(default1, "configure"))
+        cm1.setObject('', ServiceConfiguration('SQLDatabaseConnections',
+                '/folder1/++etc++Services/Packages/default/conn_srv1'))
+        traverse(default1, 'configure/1').status = Active
+
+        default1.setObject('da3', DAStub(3))
+        default1.setObject('da4', DAStub(4))
+
+        cm1.setObject('', ConnectionConfiguration('conn1',
+                            '/folder1/++etc++Services/Packages/default/da3'))
+        traverse(default1, 'configure/2').status = Active
+        cm1.setObject('', ConnectionConfiguration('conn4',
+                            '/folder1/++etc++Services/Packages/default/da4'))
+        traverse(default1, 'configure/3').status = Active
+        # Now self.service1 overrides conn1, adds new conn4 available, and
+        # inherits conn2 from self.service
 
     def testGetConnection(self):
-        self.assertEqual('Connection',
-                         self.service.getConnection('conn1'))
+        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.assertRaises(KeyError, self.service1.getConnection, 'conn3')
+        self.assertEqual('DA #4', self.service1.getConnection('conn4'))
+        self.assertRaises(KeyError, self.service1.getConnection, 'conn5')
 
     def testQueryConnection(self):
-        self.assertEqual('Connection',
-                         self.service.queryConnection('conn1'))
-        self.assertEqual(None,
-                         self.service.queryConnection('conn3'))
-        self.assertEqual('Error',
-                         self.service.queryConnection('conn3', 'Error'))
+        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(None, self.service1.queryConnection('conn3'))
+        self.assertEqual('xx', self.service1.queryConnection('conn3', 'xx'))
+        self.assertEqual('DA #4', self.service1.queryConnection('conn4'))
+        self.assertEqual(None, self.service1.queryConnection('conn5'))
+        self.assertEqual('xx', self.service1.queryConnection('conn5', 'xx'))
 
     def testGetAvailableConnections(self):
         self.assertEqual(['conn1', 'conn2'],
                          sort(self.service.getAvailableConnections()))
+        self.assertEqual(['conn1', 'conn2', 'conn4'],
+                         sort(self.service1.getAvailableConnections()))
 
 
 def test_suite():