/
testing.py
137 lines (112 loc) · 4.87 KB
/
testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
from plone.app.contenttypes.interfaces import IPloneAppContenttypesLayer
from plone.app.event.testing import PAEvent_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import applyProfile
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import IntegrationTesting
from plone.app.testing import FunctionalTesting
from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles
from plone.app.testing import login
from plone.testing import z2
from zope.configuration import xmlconfig
from zope.interface import alsoProvides
import pkg_resources
def set_browserlayer(request):
"""Set the BrowserLayer for the request.
We have to set the browserlayer manually, since importing the profile alone
doesn't do it in tests.
"""
alsoProvides(request, IPloneAppContenttypesLayer)
class PloneAppContenttypes(PloneSandboxLayer):
defaultBases = (PAEvent_FIXTURE, PLONE_FIXTURE,)
def setUpZope(self, app, configurationContext):
import plone.app.contenttypes
xmlconfig.file(
'configure.zcml',
plone.app.contenttypes,
context=configurationContext
)
import plone.app.event.dx
self.loadZCML(package=plone.app.event.dx,
context=configurationContext)
def setUpPloneSite(self, portal):
applyProfile(portal, 'plone.app.contenttypes:default')
mtr = portal.mimetypes_registry
mime_doc = mtr.lookup('application/msword')[0]
mime_doc.icon_path = 'custom.png'
portal.acl_users.userFolderAddUser('admin',
'secret',
['Manager'],
[])
login(portal, 'admin')
portal.portal_workflow.setDefaultChain("simple_publication_workflow")
setRoles(portal, TEST_USER_ID, ['Manager'])
portal.invokeFactory(
"Folder",
id="robot-test-folder",
title=u"Test Folder"
)
def tearDownPloneSite(self, portal):
applyProfile(portal, 'plone.app.contenttypes:uninstall')
class PloneAppContenttypesMigration(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
def setUpZope(self, app, configurationContext):
# prepare installing Products.ATContentTypes
import Products.ATContentTypes
self.loadZCML(package=Products.ATContentTypes)
z2.installProduct(app, 'Products.Archetypes')
z2.installProduct(app, 'Products.ATContentTypes')
z2.installProduct(app, 'plone.app.blob')
# prepare installing plone.app.collection
try:
pkg_resources.get_distribution('plone.app.collection')
z2.installProduct(app, 'plone.app.collection')
except pkg_resources.DistributionNotFound:
pass
# prepare installing plone.app.contenttypes
z2.installProduct(app, 'Products.DateRecurringIndex')
import plone.app.contenttypes
xmlconfig.file(
'configure.zcml',
plone.app.contenttypes,
context=configurationContext
)
def tearDownZope(self, app):
try:
pkg_resources.get_distribution('plone.app.collection')
z2.uninstallProduct(app, 'plone.app.collection')
except pkg_resources.DistributionNotFound:
pass
z2.uninstallProduct(app, 'plone.app.blob')
z2.uninstallProduct(app, 'Products.ATContentTypes')
z2.uninstallProduct(app, 'Products.Archetypes')
def setUpPloneSite(self, portal):
# install Products.ATContentTypes manually if profile is available
# (this is only needed for Plone >= 5)
profiles = [x['id'] for x in portal.portal_setup.listProfileInfo()]
if 'Products.ATContentTypes:default' in profiles:
applyProfile(portal, 'Products.ATContentTypes:default')
# install plone.app.collections manually if profile is available
# (this is only needed for Plone >= 5)
if 'plone.app.collection:default' in profiles:
applyProfile(portal, 'plone.app.collection:default')
PLONE_APP_CONTENTTYPES_FIXTURE = PloneAppContenttypes()
PLONE_APP_CONTENTTYPES_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_CONTENTTYPES_FIXTURE,),
name="PloneAppContenttypes:Integration"
)
PLONE_APP_CONTENTTYPES_MIGRATION_FIXTURE = PloneAppContenttypesMigration()
PLONE_APP_CONTENTTYPES_MIGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_CONTENTTYPES_MIGRATION_FIXTURE,),
name="PloneAppContenttypes:Migration"
)
PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(PLONE_APP_CONTENTTYPES_FIXTURE,),
name="PloneAppContenttypes:Functional"
)
PLONE_APP_CONTENTTYPES_ROBOT_TESTING = FunctionalTesting(
bases=(PLONE_APP_CONTENTTYPES_FIXTURE, z2.ZSERVER_FIXTURE),
name="PloneAppContenttypes:Robot"
)