/
test_content_profile.py
178 lines (146 loc) · 6.83 KB
/
test_content_profile.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
from plone.portlets.interfaces import ILocalPortletAssignmentManager
from plone.portlets.interfaces import IPortletManager
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces.constrains import ISelectableConstrainTypes
from Products.PythonScripts.PythonScript import PythonScript
from zope.component import getMultiAdapter
from zope.component import getUtility
import pkg_resources
import unittest
try:
pkg_resources.get_distribution('plone.app.dexterity.behaviors.constraints')
except pkg_resources.DistributionNotFound:
DEXTERITY_WITH_CONSTRAINS = False
else:
DEXTERITY_WITH_CONSTRAINS = True
class PloneAppContenttypesContent(PloneSandboxLayer):
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
def setUpPloneSite(self, portal):
# Necessary to set up some Plone stuff, such as Workflow.
self.applyProfile(portal, 'plone.app.contenttypes:plone-content')
PLONE_APP_CONTENTTYPES_CONTENT_FIXTURE = PloneAppContenttypesContent()
PLONE_APP_CONTENTTYPES_CONTENT_INTEGRATION_TESTING = \
IntegrationTesting(bases=(PLONE_APP_CONTENTTYPES_CONTENT_FIXTURE,),
name='PloneAppContenttypesContent:Integration')
# TODO Test for content translation.
class ContentProfileTestCase(unittest.TestCase):
layer = PLONE_APP_CONTENTTYPES_CONTENT_INTEGRATION_TESTING
def setUp(self):
self.portal = self.layer['portal']
self.portal_workflow = getToolByName(self.portal, 'portal_workflow')
# #################### #
# front-page tests #
# #################### #
def test_frontpage_was_created(self):
# Was the object created?
obj = self.portal['front-page']
self.assertEqual(obj.portal_type, 'Document')
def test_frontpage_is_default_page(self):
# Has the object been set on the container as the default page?
self.assertEqual(self.portal.default_page, 'front-page')
def test_frontpage_is_published(self):
# Has the content object been published?
front_page = self.portal['front-page']
current_state = self.portal_workflow.getInfoFor(
front_page,
'review_state')
self.assertEqual(current_state, 'published')
# ################# #
# Members tests #
# ################# #
def test_Members_was_created(self):
# Was the object created?
obj = self.portal['Members']
self.assertEqual(obj.portal_type, 'Folder')
@unittest.skip('Replaced by new members-search-form')
def test_Members__index_html(self):
# Was the index_html script created?
obj = self.portal['Members']['index_html']
self.assertTrue(isinstance(obj, PythonScript))
# It's outside the scope of this test to verify the contents of
# the script are correct. Simply checking for existence should
# be enough.
def test_Members_portlets(self):
# Have the right column portlet manager setting been added?
members = self.portal['Members']
manager = getUtility(IPortletManager, name='plone.rightcolumn')
assignable_manager = getMultiAdapter((members, manager),
ILocalPortletAssignmentManager)
self.assertTrue(assignable_manager.getBlacklistStatus('context'))
self.assertTrue(assignable_manager.getBlacklistStatus('group'))
self.assertTrue(assignable_manager.getBlacklistStatus('content_type'))
def test_Members_is_private(self):
# Is the content object public?
obj = self.portal['Members']
current_state = self.portal_workflow.getInfoFor(obj, 'review_state')
self.assertEqual(current_state, 'private')
# ################ #
# events tests #
# ################ #
def test_events_was_created(self):
# Was the object created?
events = self.portal['events']
self.assertEqual(events.portal_type, 'Folder')
# Was the contained collection created?
collection = events['aggregator']
self.assertEqual(collection.portal_type, 'Collection')
def test_events_default_page(self):
# Has the object been set on the container as the default page?
self.assertEqual(self.portal['events'].default_page, 'aggregator')
def test_events_is_published(self):
# Has the content object been published?
events = self.portal['events']
current_state = self.portal_workflow.getInfoFor(events, 'review_state')
self.assertEqual(current_state, 'published')
@unittest.skipUnless(
DEXTERITY_WITH_CONSTRAINS,
'Dexterity constraints are not present')
def test_events_allowable_types(self):
events = self.portal['events']
behavior = ISelectableConstrainTypes(events)
types = ['Event']
self.assertEqual(types, behavior.getImmediatelyAddableTypes())
# ############## #
# news tests #
# ############## #
def test_news_was_created(self):
# Was the object created?
news = self.portal['news']
self.assertEqual(news.portal_type, 'Folder')
# Was the contained collection created?
collection = news['aggregator']
self.assertEqual(collection.portal_type, 'Collection')
def test_news_default_page(self):
# Has the object been set on the container as the default page?
self.assertEqual(self.portal['news'].default_page, 'aggregator')
def test_news_is_published(self):
# Has the content object been published?
news = self.portal['news']
current_state = self.portal_workflow.getInfoFor(news, 'review_state')
self.assertEqual(current_state, 'published')
@unittest.skipUnless(
DEXTERITY_WITH_CONSTRAINS,
'Dexterity constraints are not present')
def test_news_allowable_types(self):
news = self.portal['news']
behavior = ISelectableConstrainTypes(news)
types = ['News Item']
self.assertEqual(types, behavior.getImmediatelyAddableTypes())
def test_news_aggregator_settings(self):
# Has the news aggregator (Collection) been set up?
query = [dict(i=u'portal_type',
o=u'plone.app.querystring.operation.selection.any',
v=[u'News Item']),
dict(i=u'review_state',
o=u'plone.app.querystring.operation.selection.any',
v=[u'published']),
]
collection = self.portal['news']['aggregator']
self.assertEqual(collection.sort_on, u'effective')
self.assertEqual(collection.sort_reversed, True)
self.assertItemsEqual(collection.query, query)
self.assertEqual(collection.getLayout(), 'summary_view')