在 Plone 5 的测试中自动安装默认内容类型

Automatically install default content types in tests on Plone 5

我一直在尝试在我们的一些附加组件中添加与 Plone 5 的兼容性,但我发现了一种我想避免的模式:似乎我必须像这样在测试装置上手动安装默认内容类型:

...
PLONE_VERSION = api.env.plone_version()


class Fixture(PloneSandboxLayer):

    defaultBases = (PLONE_FIXTURE,)

    def setUpZope(self, app, configurationContext):
        if PLONE_VERSION >= '5.0':
            import plone.app.contenttypes
            self.loadZCML(package=plone.app.contenttypes)
        ...

    def setUpPloneSite(self, portal):
        if PLONE_VERSION >= '5.0':
            self.applyProfile(portal, 'plone.app.contenttypes:default')
        ...

FIXTURE = Fixture()
...

有什么办法可以避免这种情况吗?

据我记忆,靠PLONE_APP_CONTENTTYPES_FIXTURE就够了。 像这样(未经测试):

try:
    from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
except ImportError:
    PLONE_APP_CONTENTTYPES_FIXTURE = None


class Fixture(PloneSandboxLayer):
    if PLONE_VERSION >= '5.0':
        defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
    else:
        defaultBases = (PLONE_FIXTURE,)