[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_adapter.py:1.4
Albertas Agejevas
alga@codeworks.lt
Wed, 15 Jan 2003 11:24:04 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv27247/zope/app/services/tests
Modified Files:
test_adapter.py
Log Message:
Added named adapter support in AdapterService.
=== Zope3/src/zope/app/services/tests/test_adapter.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/tests/test_adapter.py:1.3 Wed Jan 15 10:15:21 2003
+++ Zope3/src/zope/app/services/tests/test_adapter.py Wed Jan 15 11:24:01 2003
@@ -53,6 +53,7 @@
class Configuration:
forInterface = I1
providedInterface = I2
+ adapterName = ''
def getAdapter(self, object):
return self.factory(object)
@@ -136,7 +137,7 @@
o = O()
o.__implements__ = r
- adapter = getattr(service, m)(o, p)
+ adapter = getattr(service, m)(o, p,)
self.assertEqual(adapter.__class__, A)
self.assertEqual(adapter.context, o)
@@ -145,6 +146,56 @@
self.assertEqual(service.queryAdapter(o, I3), None)
self.assertEqual(service.queryAdapter(o, I3, 42), 42)
self.assertRaises(ComponentLookupError, service.getAdapter, O(), I3)
+
+ def test_getAdapter_with_name(self):
+ # The same as above, but with a named adapter
+ service = self._service
+
+ sm = traverse(self.rootFolder, '++etc++Services')
+
+ configure = traverse(sm, 'Packages/default/configure')
+ configuration = Configuration()
+ configuration.adapterName = u"Yatta!"
+ configure.setObject('', configuration)
+ configuration = traverse(configure, '1')
+
+ class O:
+ __implements__ = I1
+
+ configuration.factory = A
+
+ registry = service.createConfigurationsFor(configuration)
+ registry.register(configuration)
+ registry.activate(configuration)
+
+ o = O()
+
+ for r in I1, I1E:
+ for p in I2B, I2:
+ o = O()
+ o.__implements__ = r
+
+ adapter = service.getAdapter(o, p, u"Yatta!")
+ self.assertEqual(adapter.__class__, A)
+ self.assertEqual(adapter.context, o)
+
+ self.assertEqual(service.getAdapter(o, I1, u"Yatta!"), o)
+
+ for r in I1, I1E:
+ for p in I2B, I2:
+ o = O()
+ o.__implements__ = r
+
+ adapter = service.queryAdapter(o, p, None, u"Yatta!")
+ self.assertEqual(adapter.__class__, A)
+ self.assertEqual(adapter.context, o)
+
+ self.assertEqual(service.queryAdapter(o, I1, None, u"Yatta!"), o)
+
+ self.assertRaises(ComponentLookupError, service.getAdapter,
+ O(), I3, "Yatta!")
+ self.assertEqual(service.queryAdapter(o, I3, name=u"Yatta!"), None)
+ self.assertEqual(service.queryAdapter(o, I3, 42, u"Yatta!"), 42)
def test_queryAdapter_delegation(self):
service = self._service