Reputation: 2962
I have a code that looks up an iterface with get multi adapter. One of the element's members that get passed to multi adapter is providing that interface but not the element itself.
I have no control about what gets passed to multi adapter but I have control over the element that contains one of the elements in it. How do I mark it? to notify multi-adapter that there's something in there that could be useful, is there something like provideAdapterFactory(cls, interface)?
Code example:
declarations
class ImplementsInterface(object):
implements(IMarker)
class Parent(object)
child = ImplementsInterface()
lookup
some_members = zope.component.getMultiAdapter(((Parent()), IMarker)
Now, if I run the code like this, it will produce ComponentLookupError, at the same time I cannot modify lookup code or for multi adapter or for that matter I cannot assign 'implements(IMarker) to Parent because parent already implements a different interface and will break lots of other things.
Update:
I think I've found an explanation that I can makes sense out of Chapter 6.1 Multi Adapter
Update 2: I think I'm not initializing zca correctly in my unit testing code, here's a snippet
import unittest2 as unittest
from zope.traversing.adapters import DefaultTraversable
from z3c.form.testing import TestRequest
from z3c.form import testing, field
from zope import component
class TestFunctionalForm(unittest.TestCase):
def setUp(self):
testing.setUp(self)
component.provideAdapter(field.FieldWidgets)
component.provideAdapter(DefaultTraversable, [None])
self.context = self.globs['root']
def tearDown(self):
testing.tearDown(self)
Upvotes: 0
Views: 273