luke
(Luke )
December 3, 2018, 9:58pm
1
Attempting to test a product that adds schema to a dexterity type. I've enabled the behavior via the instructions found on Testing a dexterity type with a behavior . When I access the content type, I see that my behavior interface is providedBy the object, but the attributes supplied by the schema do not exist. The behavior appears to work fine in a bare site when applied to the type through the web, just not in testing. I am applying the code in the setUp of my tests.
fti = queryUtility(IDexterityFTI, name='pre.existing.contenttype')
behaviors = list(fti.behaviors)
behaviors.append(INewBehavior.__identifier__)
fti.behaviors = tuple(behaviors)
notify(SchemaInvalidatedEvent('pre.existing.contenttype'))
Am I missing a step? The documentation above is straight forward.
rodfersou
(Rodrigo Ferreira de Souza)
December 4, 2018, 7:58pm
2
We do something similar here:
# -*- coding: utf-8 -*-
from plone.dexterity.interfaces import IDexterityFTI
from plone.formwidget.namedfile.converter import b64encode_file
from zope.component import queryUtility
import os
def enable_amp_behavior(portal_type):
"""Enable AMP behavior on the specified portal type."""
fti = queryUtility(IDexterityFTI, name=portal_type)
behavior = 'collective.behavior.amp.behaviors.IAMP'
if behavior in fti.behaviors:
return
behaviors = list(fti.behaviors)
behaviors.append(behavior)
fti.behaviors = tuple(behaviors)
self.loadZCML(package=sc.social.like)
import collective.behavior.amp
self.loadZCML(package=collective.behavior.amp)
def setUpPloneSite(self, portal):
if HAS_SOCIALLIKE:
self.applyProfile(portal, 'sc.social.like:default')
self.applyProfile(portal, 'collective.behavior.amp:default')
enable_amp_behavior('News Item')
portal.portal_workflow.setDefaultChain('one_state_workflow')
FIXTURE = Fixture()
INTEGRATION_TESTING = IntegrationTesting(
bases=(FIXTURE,), name='collective.behavior.amp:Integration')
FUNCTIONAL_TESTING = FunctionalTesting(
bases=(FIXTURE,), name='collective.behavior.amp:Functional')