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?
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'))