gpt4 book ai didi

testing - 如何在测试中启用敏捷行为?

转载 作者:行者123 更新时间:2023-11-28 20:23:31 26 4
gpt4 key购买 nike

我正在为基于敏捷的内容类型编写行为;它正在运行,但我不知道在测试中启用它的正确方法是什么。

我正在使用以下内容:

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)

但该行为在某些 Plone 版本中似乎没有被禁用或启用(它在 Plone 4.2 和 Plone 4.3 中的行为不同,可能是因为 Dexterity 从 1.x 移动到 2.x)。

测试的完整代码在:https://github.com/collective/collective.cover/blob/background-image-behavior/src/collective/cover/tests/test_behaviors.py

Plone 4.2 中的测试结果:https://travis-ci.org/collective/collective.cover/jobs/33327495

启用和禁用集成测试行为的正确方法应该是什么?

最佳答案

谢谢 Asko,为我指明了正确的方向:我最终通过以下方式使模式缓存失效:

from plone.dexterity.schema import SchemaInvalidatedEvent
from zope.event import notify

# invalidate schema cache
notify(SchemaInvalidatedEvent('collective.cover.content'))

关于testing - 如何在测试中启用敏捷行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25462765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com