[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_configurationstatusproperty.py:1.3 test_servicemanager.py:1.7
Jim Fulton
jim@zope.com
Mon, 24 Mar 2003 06:09:41 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv21429/src/zope/app/services/tests
Modified Files:
test_configurationstatusproperty.py test_servicemanager.py
Log Message:
Fixed a bug in configuration handling.
You should (and now do) get an error if you try to register a
configuration and there is no *local*, meaning in this site, service
to register with. You now get an understandable (I hope) error
telling you to add a local service.
=== Zope3/src/zope/app/services/tests/test_configurationstatusproperty.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/services/tests/test_configurationstatusproperty.py:1.2 Wed Dec 25 09:13:20 2002
+++ Zope3/src/zope/app/services/tests/test_configurationstatusproperty.py Mon Mar 24 06:09:40 2003
@@ -30,7 +30,7 @@
import Active, Unregistered, Registered
from zope.proxy.context import ContextWrapper
from zope.component.exceptions import ComponentLookupError
-
+from zope.app.interfaces.services.configuration import NoLocalServiceError
class TestingConfiguration(TestingConfiguration):
status = ConfigurationStatusProperty("Services")
@@ -39,6 +39,9 @@
class PassiveConfiguration(TestingConfiguration):
status = ConfigurationStatusProperty("NoSuchService")
+class UtilityConfiguration(TestingConfiguration):
+ status = ConfigurationStatusProperty("Utilities")
+
class TestingConfigurationRegistry(TestingConfigurationRegistry):
class_ = TestingConfiguration
@@ -49,11 +52,17 @@
registry = None
def getService(self, name):
- if name == "Services":
+ if name in ("Services", "Utilities"):
return self
raise ComponentLookupError("Wrong service name", name)
def queryService(self, name, default=None):
+ if name in ("Services", "Utilities"):
+ return self
+ else:
+ return default
+
+ def queryLocalService(self, name, default=None):
if name == "Services":
return self
else:
@@ -131,18 +140,39 @@
try:
configa.status = Registered
- except ComponentLookupError:
+ except NoLocalServiceError:
self.assertEqual(configa.status, Unregistered)
else:
self.fail("should complain about missing service")
try:
configa.status = Active
- except ComponentLookupError:
+ except NoLocalServiceError:
+ self.assertEqual(configa.status, Unregistered)
+ else:
+ self.fail("should complain about missing service")
+
+
+ # we should also get an error if there *is a matching service,
+ # not it is non-local
+
+ configa = ContextWrapper(UtilityConfiguration('a'), self.rootFolder)
+ self.assertEqual(configa.status, Unregistered)
+
+ try:
+ configa.status = Registered
+ except NoLocalServiceError:
self.assertEqual(configa.status, Unregistered)
else:
self.fail("should complain about missing service")
+ try:
+ configa.status = Active
+ except NoLocalServiceError:
+ self.assertEqual(configa.status, Unregistered)
+ else:
+ self.fail("should complain about missing service")
+
def test_suite():
return TestSuite((
=== Zope3/src/zope/app/services/tests/test_servicemanager.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/services/tests/test_servicemanager.py:1.6 Sun Mar 23 17:35:42 2003
+++ Zope3/src/zope/app/services/tests/test_servicemanager.py Mon Mar 24 06:09:40 2003
@@ -72,6 +72,33 @@
self.assertEqual(c(c(c(testOb))), self.rootFolder)
self.assertEqual(testOb, ts)
+ def test_queryLocalService(self):
+ self.createServiceManager()
+ sm = traverse(self.rootFolder, '++etc++site')
+
+ # Test no service case
+ self.assertEqual(sm.queryLocalService('test_service'), None)
+ self.assertEqual(sm.queryLocalService('test_service', 42), 42)
+
+ # Test Services special case
+ self.assertEqual(sm.queryLocalService('Services', 42), sm)
+
+ # Test found local
+ default = traverse(sm, 'default')
+ ts = TestService()
+ default.setObject('test_service1', ts)
+ configuration = ServiceConfiguration(
+ 'test_service',
+ '/++etc++site/default/test_service1')
+ default.getConfigurationManager().setObject('', configuration)
+ traverse(default.getConfigurationManager(), '1').status = Active
+
+ testOb = sm.queryLocalService('test_service')
+ c = getWrapperContainer
+ self.assertEqual(c(c(c(testOb))), self.rootFolder)
+ self.assertEqual(testOb, ts)
+
+
def test_get(self):
self.createServiceManager()
sm = traverse(self.rootFolder, '++etc++site')