[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests - testConnectionConfiguration.py:1.2 testConnectionService.py:1.6
Marius Gedminas
mgedmin@codeworks.lt
Thu, 12 Dec 2002 06:33:02 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests
In directory cvs.zope.org:/tmp/cvs-serv21266/lib/python/Zope/App/OFS/Services/ConnectionService/tests
Modified Files:
testConnectionConfiguration.py testConnectionService.py
Log Message:
Merge named-component-configuration-branch
=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionConfiguration.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionConfiguration.py:1.1 Mon Dec 9 10:26:42 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionConfiguration.py Thu Dec 12 06:32:32 2002
@@ -68,7 +68,7 @@
self.bindings = {}
def queryConfigurationsFor(self, cfg, default=None):
- return self.queryConfigurations(cfg.connectionName)
+ return self.queryConfigurations(cfg.name)
queryConfigurationsFor = ContextMethod(queryConfigurationsFor)
def queryConfigurations(self, name, default=None):
@@ -77,7 +77,7 @@
queryConfigurations = ContextMethod(queryConfigurations)
def createConfigurationsFor(self, cfg):
- return self.createConfigurations(cfg.connectionName)
+ return self.createConfigurations(cfg.name)
createConfigurationsFor = ContextMethod(createConfigurationsFor)
def createConfigurations(self, name):
@@ -95,7 +95,6 @@
PlacefulSetup.setUp(self)
self.buildFolders()
self.rootFolder.setServiceManager(ServiceManager())
- sm = self.rootFolder.getServiceManager()
self.default = traverse(self.rootFolder,
'++etc++Services/Packages/default')
@@ -118,6 +117,8 @@
PlacefulSetup.tearDown(self)
def test_getComponent(self):
+ # This should be already tested by ComponentConfiguration tests, but
+ # let's doublecheck
self.assertEqual(self.config.getComponent(), self.da)
def test_status(self):
@@ -126,10 +127,6 @@
self.assertEqual(self.config.status, Active)
cr = self.service.queryConfigurations('conn_name')
self.assertEqual(cr.active(), self.config)
-
- # Unit tests for ComponentConfiguration should take care
- # of test_manage_afterAdd, test_manage_beforeDelete_and_unregistered,
- # test_disallow_delete_when_active
def test_suite():
=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py:1.5 Mon Dec 9 10:26:42 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/tests/testConnectionService.py Thu Dec 12 06:32:32 2002
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 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
-#
+#
##############################################################################
"""DT_SQLVar Tests
@@ -16,8 +16,6 @@
"""
import unittest
-from Zope.ComponentArchitecture.GlobalServiceManager import \
- serviceManager as sm
from Zope.App.Traversing import traverse
from Zope.App.RDB.IZopeConnection import IZopeConnection
from Zope.App.RDB.IZopeDatabaseAdapter import IZopeDatabaseAdapter
@@ -46,12 +44,19 @@
import ConnectionConfiguration
+class ConnectionServiceForTests(ConnectionService):
+
+ __implements__ = ConnectionService.__implements__, IAttributeAnnotatable
+
class DAStub:
__implements__ = IZopeDatabaseAdapter, IAttributeAnnotatable
+ def __init__(self, n):
+ self.n = n
+
def __call__(self):
- return 'Connection'
+ return 'DA #%d' % self.n
def sort(list):
@@ -68,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')
- self.default.setObject('conn_srv', ConnectionService())
+ '++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():