Reputation: 2876
I' writing a behavior for a Dexterity-based content type; it is working but I don't know what's the right way to enable it on tests.
I was using the following:
def _enable_background_image_behavior(self):
fti = queryUtility(IDexterityFTI, name='collective.cover.content')
behaviors = list(fti.behaviors)
behaviors.append(self.name)
fti.behaviors = tuple(behaviors)
def _disable_background_image_behavior(self):
fti = queryUtility(IDexterityFTI, name='collective.cover.content')
behaviors = list(fti.behaviors)
behaviors.remove(self.name)
fti.behaviors = tuple(behaviors)
but the behavior seems not be be disabled or enabled in certain Plone versions (it behaves differently in Plone 4.2 and Plone 4.3, pobably because of Dexterity moving from 1.x to 2.x).
the full code for the tests is in: https://github.com/collective/collective.cover/blob/background-image-behavior/src/collective/cover/tests/test_behaviors.py
the result of tests in Plone 4.2 in: https://travis-ci.org/collective/collective.cover/jobs/33327495
what should be the right way of enabling and disabling the behavior on Integration tests?
Upvotes: 1
Views: 93
Reputation: 2876
Thanks, Asko, for pointing me in the right direction: I ended up invalidating the schema cache the following way:
from plone.dexterity.schema import SchemaInvalidatedEvent
from zope.event import notify
# invalidate schema cache
notify(SchemaInvalidatedEvent('collective.cover.content'))
Upvotes: 2
Reputation: 1793
I believe that you are doing it correctly, but the issue is related to caching fixes between dx 1.x and 2.x. I have managed to clear dx caches in test setups with:
def testSetUp(self):
import plone.dexterity.schema
for name in dir(plone.dexterity.schema.generated):
if name.startswith("plone"):
delattr(plone.dexterity.schema.generated, name)
plone.dexterity.schema.SCHEMA_CACHE.clear()
Upvotes: 1