def testView_w_provided(self): from zope.component import getView, queryView, getService from zope.component.exceptions import ComponentLookupError self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I1), providing=I3) self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I2), providing=I3) self.assertEquals( queryView(ob, 'foo', Request(I2), Test, providing=I3), Test) getService(Adapters).register([I1, I2], Interface, 'foo', Comp) self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I1), providing=I3) self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I2), providing=I3) self.assertEquals( queryView(ob, 'foo', Request(I2), Test, providing=I3), Test) getService(Adapters).register([I1, I2], I3, 'foo', Comp) c = getView(ob, 'foo', Request(I2), providing=I3) self.assertEquals(c.__class__, Comp) self.assertEquals(c.context, ob)
def testViewWithContextArgument(self): # Basically the same as testView, but exercising the context # argument. As this only tests global views, the context # argument is pretty much a no-operation. from zope.component import getView, queryView, getService from zope.component.exceptions import ComponentLookupError self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I1), context=ob) self.assertRaises(ComponentLookupError, getView, ob, 'foo', Request(I2), context=ob) self.assertEquals(queryView(ob, 'foo', Request(I2), Test, context=ob), Test) getService(Adapters, ob).register((I1, I2), Interface, 'foo', Comp) c = getView(ob, 'foo', Request(I2), context=ob) self.assertEquals(c.__class__, Comp) self.assertEquals(c.context, ob) self.assertRaises(ComponentLookupError, getView, ob, 'foo2', Request(I1), context=ob) self.assertRaises(ComponentLookupError, getView, ob, 'foo2', Request(I2), context=ob) self.assertEquals(queryView(ob, 'foo2', Request(I2), Test, context=ob), Test) self.assertEquals(queryView(ob, 'foo2', Request(I1), None, context=ob), None)
def __before_publishing_traverse__(self, arg1, arg2=None): """ Pre-traversal hook. """ # XXX hack around a bug(?) in BeforeTraverse.MultiHook REQUEST = arg2 or arg1 if REQUEST['REQUEST_METHOD'] not in ('GET', 'POST'): return stack = REQUEST['TraversalRequestNameStack'] key = stack and stack[-1] or '(Default)' # if there's a Zope3-style default view name set and the # corresponding view exists, take that in favour of the FTI's # default view if key == '(Default)': viewname = queryDefaultViewName(self, REQUEST) if (viewname and queryView(self, viewname, REQUEST) is not None): stack.append(viewname) REQUEST._hacked_path = 1 return ti = self.getTypeInfo() method_id = ti and ti.queryMethodID(key, context=self) if method_id: if key != '(Default)': stack.pop() if method_id != '(Default)': stack.append(method_id) REQUEST._hacked_path = 1