My package overrides the EventOccurrenceAccessor provided by plone.app.event
<adapter factory=".recurrence.EventOccurrenceAccessor" />
and adapter defined in https://github.com/plone/plone.app.event/blob/1.2.7/plone/app/event/recurrence.py#L137
class EventOccurrenceAccessor(object): implements(IEventAccessor) adapts(IOccurrence) ...
plone.app.event [archetypes] is listed as install_requires and pulled in by z3c.autoinclude
on my development instance it is enought to simply subclass the original class
and register the new adapater via my.package/overrides.zcml
class ProxyEventOccurrenceAccessor(EventOccurrenceAccessor): """override default adapter to handle proxyevents differently""" @property def url(self): return 'foo'
<configure xmlns="http://namespaces.zope.org/zope"> <!-- override plone.app.event.recurrence.EventOccurrenceAccessor --> <adapter factory=".adapters.ProxyEventOccurrenceAccessor" /> </configure>
in the unit-test setup overriding the adapter needs extra work as z3c.autoinclude is deactivated in unittests
and overrides.zcml is not loaded automatically.
so i load overrides.zcml explicitly in the layer setup (using xmlconfig.includeOverrides):
layer definition and test-class
class MyLayer(PloneSandboxLayer): # use ptc_fixture as base to make sure everything is setup properly to mimik # products.plonetestcase infrastructure defaultBases = (PTC_FIXTURE,) def setUpZope(self, app, configurationContext): # Configure ZCML xmlconfig.file('testing.zcml', my.package.tests, context=configurationContext) # EXTRA WORK to load overrides, found on # https://blog.niteo.co/load-overrides-zcml-in-plone-app-testing/ xmlconfig.includeOverrides(configurationContext, file='overrides.zcml', package=my.package) z2.installProduct(app, 'my.package') MY_FIXTURE = MyLayer() MY_INTEGRATION_TESTING = IntegrationTesting( bases=(MY_FIXTURE,), name="my.package:Integration") class TestProxyEventListing(ProxyEventBase, unittest.TestCase): layer = MY_INTEGRATION_TESTING def test_adapter(self): acc = IEventAccessor(occurrence) # fails because module still is 'plone.app.event' self.assertTrue(acc.__module__.startswith('my.package'))
testing.zcml looks like this
<configure xmlns="http://namespaces.zope.org/zope"> <!-- load dependencies manually for testing environment that elsewise get pulled in by z3c.autocinclude --> <include package="z3c.jbot" /> <include package="my.types" /> <include package="plone.app.event" /> <include package="plone.rest" /> <include package="Products.AddRemoveWidget" /> <include package="Products.AutocompleteWidget" /> <include package="Products.CMFPlacefulWorkflow" /> <include package="Products.TextIndexNG3" /> </configure>
the overrides.zcml is loaded when the tests are run (if i use a wrong classname i get a ConfigurationError)
however, in unittests I still get the adapter defined in plone.app.event, whereas the custom version is used when running bin/instance