collective.documentgenerator 3.46__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. collective/documentgenerator/AT_renderer.py +98 -0
  2. collective/documentgenerator/DX_renderer.py +52 -0
  3. collective/documentgenerator/__init__.py +17 -0
  4. collective/documentgenerator/adapters.py +23 -0
  5. collective/documentgenerator/browser/__init__.py +0 -0
  6. collective/documentgenerator/browser/actionspanel.py +19 -0
  7. collective/documentgenerator/browser/check_pod_templates.pt +63 -0
  8. collective/documentgenerator/browser/children_pod_template.pt +16 -0
  9. collective/documentgenerator/browser/configure.zcml +220 -0
  10. collective/documentgenerator/browser/controlpanel.py +159 -0
  11. collective/documentgenerator/browser/converter.py +43 -0
  12. collective/documentgenerator/browser/generation_view.py +532 -0
  13. collective/documentgenerator/browser/overrides.py +9 -0
  14. collective/documentgenerator/browser/resources/css/documentgenerator.css +133 -0
  15. collective/documentgenerator/browser/static/.gitkeep +0 -0
  16. collective/documentgenerator/browser/static/configurable.svg +1232 -0
  17. collective/documentgenerator/browser/static/csv.svg +521 -0
  18. collective/documentgenerator/browser/static/doc.svg +23 -0
  19. collective/documentgenerator/browser/static/docx.svg +20 -0
  20. collective/documentgenerator/browser/static/download_icon.svg +54 -0
  21. collective/documentgenerator/browser/static/libreoffice-blanck.svg +481 -0
  22. collective/documentgenerator/browser/static/mailinglooptemplate.svg +1207 -0
  23. collective/documentgenerator/browser/static/missing_use.svg +42 -0
  24. collective/documentgenerator/browser/static/nok.svg +38 -0
  25. collective/documentgenerator/browser/static/nok_use.svg +38 -0
  26. collective/documentgenerator/browser/static/nok_used.svg +38 -0
  27. collective/documentgenerator/browser/static/odp.svg +1264 -0
  28. collective/documentgenerator/browser/static/ods.svg +1354 -0
  29. collective/documentgenerator/browser/static/odt.svg +1347 -0
  30. collective/documentgenerator/browser/static/ok.svg +38 -0
  31. collective/documentgenerator/browser/static/ok_use.svg +38 -0
  32. collective/documentgenerator/browser/static/ok_used.svg +38 -0
  33. collective/documentgenerator/browser/static/pdf.svg +557 -0
  34. collective/documentgenerator/browser/static/podtemplate.svg +1197 -0
  35. collective/documentgenerator/browser/static/rtf.svg +521 -0
  36. collective/documentgenerator/browser/static/style.svg +1207 -0
  37. collective/documentgenerator/browser/static/subtemplate.svg +1250 -0
  38. collective/documentgenerator/browser/static/xls.svg +159 -0
  39. collective/documentgenerator/browser/static/xlsx.svg +48 -0
  40. collective/documentgenerator/browser/table.py +277 -0
  41. collective/documentgenerator/browser/templates_listing.pt +23 -0
  42. collective/documentgenerator/browser/views.py +365 -0
  43. collective/documentgenerator/config.py +162 -0
  44. collective/documentgenerator/configure.zcml +41 -0
  45. collective/documentgenerator/content/__init__.py +0 -0
  46. collective/documentgenerator/content/condition.py +60 -0
  47. collective/documentgenerator/content/conditions.zcml +29 -0
  48. collective/documentgenerator/content/configure.zcml +25 -0
  49. collective/documentgenerator/content/document_factory.py +73 -0
  50. collective/documentgenerator/content/file_representation.py +73 -0
  51. collective/documentgenerator/content/file_representation.zcml +28 -0
  52. collective/documentgenerator/content/merge_templates.py +15 -0
  53. collective/documentgenerator/content/merge_templates.zcml +10 -0
  54. collective/documentgenerator/content/pod_template.py +547 -0
  55. collective/documentgenerator/content/style_template.py +52 -0
  56. collective/documentgenerator/content/vocabulary.py +315 -0
  57. collective/documentgenerator/content/vocabulary.zcml +104 -0
  58. collective/documentgenerator/demo/__init__.py +0 -0
  59. collective/documentgenerator/demo/archetypes.zcml +10 -0
  60. collective/documentgenerator/demo/configure.zcml +19 -0
  61. collective/documentgenerator/demo/helper.py +198 -0
  62. collective/documentgenerator/events/__init__.py +0 -0
  63. collective/documentgenerator/events/configure.zcml +30 -0
  64. collective/documentgenerator/events/pod_templates_events.py +66 -0
  65. collective/documentgenerator/events/styles_events.py +122 -0
  66. collective/documentgenerator/helper/__init__.py +9 -0
  67. collective/documentgenerator/helper/archetypes-adapter.zcml +10 -0
  68. collective/documentgenerator/helper/archetypes-page.zcml +9 -0
  69. collective/documentgenerator/helper/archetypes.py +67 -0
  70. collective/documentgenerator/helper/base.py +266 -0
  71. collective/documentgenerator/helper/configure.zcml +38 -0
  72. collective/documentgenerator/helper/dexterity.py +174 -0
  73. collective/documentgenerator/interfaces.py +165 -0
  74. collective/documentgenerator/locales/collective.documentgenerator.pot +564 -0
  75. collective/documentgenerator/locales/es/LC_MESSAGES/collective.documentgenerator.po +572 -0
  76. collective/documentgenerator/locales/es/LC_MESSAGES/plone.po +32 -0
  77. collective/documentgenerator/locales/fr/LC_MESSAGES/collective.documentgenerator.po +566 -0
  78. collective/documentgenerator/locales/fr/LC_MESSAGES/plone.po +27 -0
  79. collective/documentgenerator/locales/manual.pot +30 -0
  80. collective/documentgenerator/locales/plone-manual.pot +22 -0
  81. collective/documentgenerator/locales/plone.pot +30 -0
  82. collective/documentgenerator/locales/update.sh +22 -0
  83. collective/documentgenerator/migrations/__init__.py +0 -0
  84. collective/documentgenerator/migrations/migrate_to_11.py +53 -0
  85. collective/documentgenerator/migrations/migrate_to_12.py +30 -0
  86. collective/documentgenerator/migrations/migrate_to_13.py +37 -0
  87. collective/documentgenerator/migrations/migrate_to_3.py +36 -0
  88. collective/documentgenerator/migrations/migrate_to_5.py +30 -0
  89. collective/documentgenerator/migrations/migrate_to_6.py +27 -0
  90. collective/documentgenerator/migrations/migrate_to_7.py +32 -0
  91. collective/documentgenerator/migrations/migrate_to_8.py +34 -0
  92. collective/documentgenerator/migrations/migrate_to_9.py +48 -0
  93. collective/documentgenerator/profiles/base/browserlayer.xml +7 -0
  94. collective/documentgenerator/profiles/base/controlpanel.xml +20 -0
  95. collective/documentgenerator/profiles/base/metadata.xml +7 -0
  96. collective/documentgenerator/profiles/base/types/ConfigurablePODTemplate.xml +43 -0
  97. collective/documentgenerator/profiles/base/types/MailingLoopTemplate.xml +42 -0
  98. collective/documentgenerator/profiles/base/types/PODTemplate.xml +42 -0
  99. collective/documentgenerator/profiles/base/types/StyleTemplate.xml +42 -0
  100. collective/documentgenerator/profiles/base/types/SubTemplate.xml +42 -0
  101. collective/documentgenerator/profiles/base/types.xml +10 -0
  102. collective/documentgenerator/profiles/base/viewlets.xml +6 -0
  103. collective/documentgenerator/profiles/demo/browserlayer.xml +7 -0
  104. collective/documentgenerator/profiles/demo/collectivedocumentgenerator_demo_marker.txt +0 -0
  105. collective/documentgenerator/profiles/demo/import_steps.xml +11 -0
  106. collective/documentgenerator/profiles/demo/metadata.xml +7 -0
  107. collective/documentgenerator/profiles/demo/registry.xml +13 -0
  108. collective/documentgenerator/profiles/demo/templates/mailing.odt +0 -0
  109. collective/documentgenerator/profiles/demo/templates/modele_general.ods +0 -0
  110. collective/documentgenerator/profiles/demo/templates/modele_general.odt +0 -0
  111. collective/documentgenerator/profiles/demo/templates/mod/303/250le_collection.odt +0 -0
  112. collective/documentgenerator/profiles/demo/templates/possibly_mailed_model.odt +0 -0
  113. collective/documentgenerator/profiles/demo/templates/styles.odt +0 -0
  114. collective/documentgenerator/profiles/demo/templates/styles_2.odt +0 -0
  115. collective/documentgenerator/profiles/demo/templates/sub_template.odt +0 -0
  116. collective/documentgenerator/profiles/demo/viewlets.xml +3 -0
  117. collective/documentgenerator/profiles/plone4/collectivedocumentgenerator_marker.txt +0 -0
  118. collective/documentgenerator/profiles/plone4/cssregistry.xml +11 -0
  119. collective/documentgenerator/profiles/plone4/metadata.xml +7 -0
  120. collective/documentgenerator/profiles/plone4/registry.xml +6 -0
  121. collective/documentgenerator/profiles/plone5/metadata.xml +7 -0
  122. collective/documentgenerator/profiles/plone5/registry.xml +15 -0
  123. collective/documentgenerator/profiles/testing/metadata.xml +7 -0
  124. collective/documentgenerator/profiles/testing/propertiestool.xml +5 -0
  125. collective/documentgenerator/profiles/testing/types/member.xml +85 -0
  126. collective/documentgenerator/profiles/testing/types.xml +5 -0
  127. collective/documentgenerator/profiles.zcml +186 -0
  128. collective/documentgenerator/renderer.zcml +145 -0
  129. collective/documentgenerator/search_replace/__init__.py +0 -0
  130. collective/documentgenerator/search_replace/configure.zcml +19 -0
  131. collective/documentgenerator/search_replace/pod_template.py +146 -0
  132. collective/documentgenerator/search_replace/search_result_form.pt +48 -0
  133. collective/documentgenerator/search_replace/searchreplace_panel.pt +22 -0
  134. collective/documentgenerator/search_replace/searchreplace_panel.py +261 -0
  135. collective/documentgenerator/setuphandlers.py +287 -0
  136. collective/documentgenerator/testing.py +324 -0
  137. collective/documentgenerator/testing.zcml +16 -0
  138. collective/documentgenerator/tests/__init__.py +0 -0
  139. collective/documentgenerator/tests/failing_template.odt +0 -0
  140. collective/documentgenerator/tests/robot/.gitkeep +0 -0
  141. collective/documentgenerator/tests/template_to_clean.odt +0 -0
  142. collective/documentgenerator/tests/template_without_style_page.odt +0 -0
  143. collective/documentgenerator/tests/test_AT_helper_view.py +276 -0
  144. collective/documentgenerator/tests/test_DX_helper_view.py +355 -0
  145. collective/documentgenerator/tests/test_base_helper_view.py +128 -0
  146. collective/documentgenerator/tests/test_check_podtemplates_view.py +138 -0
  147. collective/documentgenerator/tests/test_config.py +106 -0
  148. collective/documentgenerator/tests/test_configurable_pod_template.py +383 -0
  149. collective/documentgenerator/tests/test_demo_profile.py +115 -0
  150. collective/documentgenerator/tests/test_events.py +169 -0
  151. collective/documentgenerator/tests/test_file.odt +0 -0
  152. collective/documentgenerator/tests/test_generation_view.py +652 -0
  153. collective/documentgenerator/tests/test_mailing.odt +0 -0
  154. collective/documentgenerator/tests/test_mailing_loop_template.py +48 -0
  155. collective/documentgenerator/tests/test_pod_template.py +178 -0
  156. collective/documentgenerator/tests/test_robot.py +26 -0
  157. collective/documentgenerator/tests/test_search_replace.py +419 -0
  158. collective/documentgenerator/tests/test_setup.py +49 -0
  159. collective/documentgenerator/tests/test_style_template.py +19 -0
  160. collective/documentgenerator/tests/test_sub_template.py +49 -0
  161. collective/documentgenerator/tests/test_templates_listing_view.py +91 -0
  162. collective/documentgenerator/tests/test_utils.py +244 -0
  163. collective/documentgenerator/tests/test_vocabulary.py +154 -0
  164. collective/documentgenerator/utils.py +396 -0
  165. collective/documentgenerator/viewlets/__init__.py +0 -0
  166. collective/documentgenerator/viewlets/batchactions.py +14 -0
  167. collective/documentgenerator/viewlets/configure.zcml +16 -0
  168. collective/documentgenerator/viewlets/generationlinks.pt +28 -0
  169. collective/documentgenerator/viewlets/generationlinks.py +58 -0
  170. collective.documentgenerator-3.46-py3.13-nspkg.pth +1 -0
  171. collective_documentgenerator-3.46.dist-info/METADATA +1142 -0
  172. collective_documentgenerator-3.46.dist-info/RECORD +176 -0
  173. collective_documentgenerator-3.46.dist-info/WHEEL +5 -0
  174. collective_documentgenerator-3.46.dist-info/entry_points.txt +5 -0
  175. collective_documentgenerator-3.46.dist-info/namespace_packages.txt +1 -0
  176. collective_documentgenerator-3.46.dist-info/top_level.txt +1 -0
@@ -0,0 +1,287 @@
1
+ # -*- coding: utf-8 -*-
2
+ from collective.documentgenerator.config import DEFAULT_OO_PORT
3
+ from collective.documentgenerator.config import set_use_stream
4
+ from collective.documentgenerator.content.pod_template import POD_TEMPLATE_TYPES
5
+ from collective.documentgenerator.utils import translate as _
6
+ from plone import api
7
+ from plone.namedfile.file import NamedBlobFile
8
+ from Products.CMFPlone import interfaces as Plone
9
+ from Products.CMFPlone.utils import safe_unicode
10
+ from Products.CMFQuickInstallerTool import interfaces as QuickInstaller
11
+ from zope.interface import implementer
12
+
13
+ import logging
14
+ import os
15
+
16
+
17
+ try:
18
+ from Products.CMFPlone.interfaces.constrains import IConstrainTypes
19
+ except ImportError:
20
+ # BBB Plone 4
21
+ from Products.CMFPlone.interfaces import IConstrainTypes
22
+
23
+ logger = logging.getLogger('collective.documentgenerator')
24
+
25
+
26
+ def isNotCurrentProfile(context):
27
+ return context.readDataFile('collectivedocumentgenerator_marker.txt') is None
28
+
29
+
30
+ def post_install(context):
31
+ """Post install script"""
32
+ if isNotCurrentProfile(context):
33
+ return
34
+
35
+
36
+ def install_demo(context):
37
+ """ """
38
+ if context.readDataFile('collectivedocumentgenerator_demo_marker.txt') is None:
39
+ return
40
+
41
+ portal = api.portal.get()
42
+ use_stream = os.getenv('USE_STREAM', False) == 'True'
43
+ set_use_stream(use_stream)
44
+
45
+ default_oo_port_list = unicode(os.getenv('OO_PORT', DEFAULT_OO_PORT))
46
+ api.portal.set_registry_record('collective.documentgenerator.browser.controlpanel.'
47
+ 'IDocumentGeneratorControlPanelSchema.oo_port_list',
48
+ default_oo_port_list)
49
+
50
+ if not hasattr(portal, 'podtemplates'):
51
+ templates_folder = api.content.create(
52
+ type='Folder',
53
+ title=_(u'POD Templates'),
54
+ id='podtemplates',
55
+ container=portal,
56
+ exclude_from_nav=True
57
+ )
58
+ templates_folder.setTitle('POD Templates')
59
+ templates_folder.reindexObject()
60
+
61
+ pod_folder = getattr(portal, 'podtemplates')
62
+ constrain_types = IConstrainTypes(pod_folder)
63
+ constrain_types.setConstrainTypesMode(1)
64
+ constrain_types.setLocallyAllowedTypes(POD_TEMPLATE_TYPES.keys())
65
+ constrain_types.setImmediatelyAddableTypes(POD_TEMPLATE_TYPES.keys())
66
+
67
+ # Create some test content
68
+ style_template_id = 'test_style_template'
69
+ if not hasattr(pod_folder, style_template_id):
70
+ api.content.create(
71
+ type='StyleTemplate',
72
+ id=style_template_id,
73
+ title='Styles',
74
+ odt_file=NamedBlobFile(
75
+ data=context.readDataFile('templates/styles.odt'),
76
+ contentType='application/vnd.oasis.opendocument.text',
77
+ filename=u'styles.odt',
78
+ ),
79
+ container=pod_folder,
80
+ exclude_from_nav=True
81
+ )
82
+ style_template = getattr(pod_folder, style_template_id)
83
+
84
+ style_template_id = 'test_style_template_2'
85
+ if not hasattr(pod_folder, style_template_id):
86
+ api.content.create(
87
+ type='StyleTemplate',
88
+ id=style_template_id,
89
+ title=_(u'Styles n°2'),
90
+ odt_file=NamedBlobFile(
91
+ data=context.readDataFile('templates/styles_2.odt'),
92
+ contentType='application/vnd.oasis.opendocument.text',
93
+ filename=u'styles_2.odt',
94
+ ),
95
+ container=pod_folder,
96
+ exclude_from_nav=True
97
+ )
98
+
99
+ sub_template_id = 'sub_template'
100
+ if not hasattr(pod_folder, sub_template_id):
101
+ api.content.create(
102
+ type='SubTemplate',
103
+ id=sub_template_id,
104
+ title=_(u'Header'),
105
+ odt_file=NamedBlobFile(
106
+ data=context.readDataFile('templates/sub_template.odt'),
107
+ contentType='application/vnd.oasis.opendocument.text',
108
+ filename=u'sub_template.odt',
109
+ ),
110
+ container=pod_folder,
111
+ exclude_from_nav=True,
112
+ style_template=[style_template.UID()],
113
+ )
114
+ sub_template = getattr(pod_folder, sub_template_id)
115
+
116
+ if not hasattr(pod_folder, 'loop_template'):
117
+ api.content.create(
118
+ type='MailingLoopTemplate',
119
+ id='loop_template',
120
+ title=_(u'Mailing loop template'),
121
+ odt_file=NamedBlobFile(
122
+ data=context.readDataFile('templates/mailing.odt'),
123
+ contentType='application/vnd.oasis.opendocument.text',
124
+ filename=u'mailing.odt',
125
+ ),
126
+ container=pod_folder,
127
+ exclude_from_nav=True,
128
+ style_template=[style_template.UID()],
129
+ )
130
+ loop_template = getattr(pod_folder, 'loop_template')
131
+
132
+ if not hasattr(pod_folder, 'test_template'):
133
+ api.content.create(
134
+ type='PODTemplate',
135
+ id='test_template',
136
+ title=_(u'General template'),
137
+ odt_file=NamedBlobFile(
138
+ data=context.readDataFile('templates/modele_general.odt'),
139
+ contentType='application/vnd.oasis.opendocument.text',
140
+ filename=u'modele_general.odt',
141
+ ),
142
+ container=pod_folder,
143
+ exclude_from_nav=True,
144
+ )
145
+
146
+ if not hasattr(pod_folder, 'test_template_multiple'):
147
+ api.content.create(
148
+ type='ConfigurablePODTemplate',
149
+ id='test_template_multiple',
150
+ title=_(u'Multiple format template'),
151
+ odt_file=NamedBlobFile(
152
+ data=context.readDataFile('templates/modele_general.odt'),
153
+ contentType='application/vnd.oasis.opendocument.text',
154
+ filename=u'modele_general.odt',
155
+ ),
156
+ container=pod_folder,
157
+ exclude_from_nav=True,
158
+ pod_formats=['odt', 'pdf', 'doc', 'docx'],
159
+ pod_portal_types=['Document'],
160
+ style_template=[style_template.UID()],
161
+ merge_templates=[
162
+ {
163
+ 'template': sub_template.UID(),
164
+ 'pod_context_name': 'header',
165
+ 'do_rendering': True,
166
+ }
167
+ ],
168
+ )
169
+
170
+ if not hasattr(pod_folder, 'test_template_bis'):
171
+ api.content.create(
172
+ type='ConfigurablePODTemplate',
173
+ id='test_template_bis',
174
+ title=_(u'Collection template'),
175
+ odt_file=NamedBlobFile(
176
+ data=context.readDataFile(safe_unicode('templates/modèle_collection.odt')),
177
+ contentType='application/vnd.oasis.opendocument.text',
178
+ filename=u'modèle_collection.odt',
179
+ ),
180
+ container=pod_folder,
181
+ exclude_from_nav=True,
182
+ pod_formats=['odt', 'pdf', ],
183
+ pod_portal_types=['Collection', 'Folder'],
184
+ style_template=[style_template.UID()],
185
+ merge_templates=[
186
+ {
187
+ 'template': sub_template.UID(),
188
+ 'pod_context_name': 'header',
189
+ 'do_rendering': False,
190
+ }
191
+ ],
192
+ context_variables=[
193
+ {
194
+ 'name': 'details',
195
+ 'value': '1',
196
+ }
197
+ ],
198
+ )
199
+
200
+ if not hasattr(pod_folder, 'test_ods_template'):
201
+ api.content.create(
202
+ type='ConfigurablePODTemplate',
203
+ id='test_ods_template',
204
+ title=_(u'Spreadsheet template'),
205
+ odt_file=NamedBlobFile(
206
+ data=context.readDataFile('templates/modele_general.ods'),
207
+ contentType='application/vnd.oasis.opendocument.spreadsheet',
208
+ filename=u'modele_general.ods',
209
+ ),
210
+ container=pod_folder,
211
+ exclude_from_nav=True,
212
+ pod_formats=['ods', 'xls', ],
213
+ pod_portal_types=['Collection', 'Folder'],
214
+ style_template=[style_template.UID()],
215
+ )
216
+
217
+ if not hasattr(pod_folder, 'test_template_possibly_mailed'):
218
+ api.content.create(
219
+ type='ConfigurablePODTemplate',
220
+ id='test_template_possibly_mailed',
221
+ title=_(u'Possibly mailed template'),
222
+ odt_file=NamedBlobFile(
223
+ data=context.readDataFile('templates/possibly_mailed_model.odt'),
224
+ contentType='application/vnd.oasis.opendocument.text',
225
+ filename=u'possibly_mailed_model.odt',
226
+ ),
227
+ container=pod_folder,
228
+ exclude_from_nav=True,
229
+ pod_formats=['odt'],
230
+ pod_portal_types=['Folder'],
231
+ mailing_loop_template=loop_template.UID(),
232
+ context_variables=[
233
+ {
234
+ 'name': 'details',
235
+ 'value': '1',
236
+ }
237
+ ],
238
+ )
239
+
240
+ if not hasattr(pod_folder, 'test_template_reusable'):
241
+ api.content.create(
242
+ type='ConfigurablePODTemplate',
243
+ id='test_template_reusable',
244
+ title=_(u'Reusable template'),
245
+ odt_file=NamedBlobFile(
246
+ data=context.readDataFile('templates/modele_general.odt'),
247
+ contentType='application/vnd.oasis.opendocument.text',
248
+ filename=u'modele_general.odt',
249
+ ),
250
+ is_reusable=True,
251
+ container=pod_folder,
252
+ pod_formats=['odt'],
253
+ pod_portal_types=['Folder'],
254
+ exclude_from_nav=True
255
+ )
256
+
257
+ reusable_template = getattr(pod_folder, 'test_template_reusable')
258
+
259
+ if not hasattr(pod_folder, 'test_template_reuse'):
260
+ api.content.create(
261
+ type='ConfigurablePODTemplate',
262
+ id='test_template_reuse',
263
+ title=_(u'Reuse Test Template'),
264
+ container=pod_folder,
265
+ exclude_from_nav=True,
266
+ pod_formats=['odt', 'pdf', 'doc', 'docx'],
267
+ pod_portal_types=['Document'],
268
+ pod_template_to_use=reusable_template.UID()
269
+ )
270
+
271
+
272
+ @implementer(Plone.INonInstallable)
273
+ class HiddenProfiles(object):
274
+ def getNonInstallableProfiles(self):
275
+ """Do not show on Plone's list of installable profiles."""
276
+ return [
277
+ u'collective.documentgenerator:install-base',
278
+ ]
279
+
280
+
281
+ @implementer(QuickInstaller.INonInstallable)
282
+ class HiddenProducts(object):
283
+ def getNonInstallableProducts(self):
284
+ """Do not show on QuickInstaller's list of installable products."""
285
+ return [
286
+ u'collective.documentgenerator:install-base',
287
+ ]
@@ -0,0 +1,324 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Base module for unittesting."""
3
+
4
+ from imio.helpers import HAS_PLONE_5
5
+ from imio.helpers import HAS_PLONE_5_2
6
+ from imio.pyutils.system import runCommand
7
+ from plone import api
8
+ from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
9
+ from plone.app.testing import applyProfile
10
+ from plone.app.testing import FunctionalTesting
11
+ from plone.app.testing import IntegrationTesting
12
+ from plone.app.testing import login
13
+ from plone.app.testing import PLONE_FIXTURE
14
+ from plone.app.testing import PloneSandboxLayer
15
+ from plone.app.testing import setRoles
16
+ from plone.app.testing import TEST_USER_ID
17
+ from plone.app.testing import TEST_USER_NAME
18
+ from plone.app.testing import TEST_USER_PASSWORD
19
+ from plone.protect.authenticator import createToken
20
+ from plone.testing import z2
21
+ from zope.globalrequest import setLocal
22
+
23
+ import collective.documentgenerator
24
+ import os
25
+ import tempfile
26
+ import transaction
27
+ import unittest
28
+ import zipfile
29
+
30
+
31
+ if HAS_PLONE_5_2:
32
+ import sys
33
+ from zope.deprecation import deprecation
34
+ sys.modules['collective.documentgenerator.tests.ArchetypesIntegrationTests'] = \
35
+ deprecation.deprecated(deprecation, 'Archetypes was removed from Plone 5.2.')
36
+ sys.modules['collective.documentgenerator.tests.ArchetypesFunctionnalTests'] = \
37
+ deprecation.deprecated(deprecation, 'Archetypes was removed from Plone 5.2.')
38
+
39
+
40
+ class NakedPloneLayer(PloneSandboxLayer):
41
+
42
+ defaultBases = (PLONE_FIXTURE,)
43
+
44
+ def setUpZope(self, app, configurationContext):
45
+ """Set up Zope."""
46
+ # Load ZCML
47
+ self.loadZCML(package=collective.documentgenerator,
48
+ name='testing.zcml')
49
+ (stdout, stderr, st) = runCommand('%s/bin/soffice.sh restart' % os.getenv('PWD'))
50
+
51
+ def setUpPloneSite(self, portal):
52
+ """ Setup Plone
53
+ """
54
+
55
+ # Default workflow
56
+ wftool = portal['portal_workflow']
57
+ wftool.setDefaultChain('simple_publication_workflow')
58
+
59
+ # Add default Plone content
60
+ try:
61
+ applyProfile(portal, 'plone.app.contenttypes:plone-content')
62
+ # portal.portal_workflow.setDefaultChain(
63
+ # 'simple_publication_workflow')
64
+ except KeyError:
65
+ # BBB Plone 4
66
+ # Products.ATContentTypes is installed by default in Plone4's tests
67
+ pass
68
+
69
+ def tearDownZope(self, app):
70
+ """Tear down Zope."""
71
+ if HAS_PLONE_5_2:
72
+ from plone.testing import zope
73
+ zope.uninstallProduct(app, 'collective.documentgenerator')
74
+ else:
75
+ z2.uninstallProduct(app, 'collective.documentgenerator')
76
+ (stdout, stderr, st) = runCommand('%s/bin/soffice.sh stop' % os.getenv('PWD'))
77
+
78
+
79
+ NAKED_PLONE_FIXTURE = NakedPloneLayer(
80
+ name='NAKED_PLONE_FIXTURE'
81
+ )
82
+
83
+ NAKED_PLONE_INTEGRATION = IntegrationTesting(
84
+ bases=(NAKED_PLONE_FIXTURE,),
85
+ name='NAKED_PLONE_INTEGRATION'
86
+ )
87
+
88
+
89
+ class DocumentgeneratorLayer(NakedPloneLayer):
90
+
91
+ def setUpPloneSite(self, portal):
92
+ """Set up Plone."""
93
+ super(DocumentgeneratorLayer, self).setUpPloneSite(portal)
94
+
95
+ # Set tests in 'fr'
96
+ if HAS_PLONE_5:
97
+ api.portal.set_registry_record('plone.available_languages', ['en', 'fr'])
98
+ api.portal.set_registry_record('plone.default_language', 'fr')
99
+
100
+ # Install into Plone site using portal_setup
101
+ applyProfile(portal, 'collective.documentgenerator:testing')
102
+ setLocal('request', portal.REQUEST)
103
+
104
+ # Install plone-content for Plone 4 so front-page is available
105
+ if not HAS_PLONE_5:
106
+ applyProfile(portal, 'Products.CMFPlone:plone-content')
107
+
108
+ # Login and create some test content
109
+ setRoles(portal, TEST_USER_ID, ['Manager'])
110
+ login(portal, TEST_USER_NAME)
111
+
112
+ # Commit so that the test browser sees these objects
113
+ transaction.commit()
114
+
115
+
116
+ TEST_INSTALL_FIXTURE = DocumentgeneratorLayer(
117
+ name='TEST_INSTALL_FIXTURE'
118
+ )
119
+
120
+ TEST_INSTALL_INTEGRATION = IntegrationTesting(
121
+ bases=(TEST_INSTALL_FIXTURE,),
122
+ name='TEST_INSTALL_INTEGRATION'
123
+ )
124
+
125
+
126
+ TEST_INSTALL_FUNCTIONAL = FunctionalTesting(
127
+ bases=(TEST_INSTALL_FIXTURE,),
128
+ name='TEST_INSTALL_FUNCTIONAL'
129
+ )
130
+
131
+
132
+ class ExamplePODTemplateLayer(DocumentgeneratorLayer):
133
+
134
+ def setUpPloneSite(self, portal):
135
+ super(ExamplePODTemplateLayer, self).setUpPloneSite(portal)
136
+
137
+ applyProfile(portal, 'collective.documentgenerator:demo')
138
+ applyProfile(portal, 'collective.documentgenerator:testing')
139
+
140
+ # Commit so that the test browser sees these objects
141
+ transaction.commit()
142
+
143
+
144
+ POD_TEMPLATE_FIXTURE = ExamplePODTemplateLayer(
145
+ name='POD_TEMPLATE_FIXTURE'
146
+ )
147
+
148
+ POD_TEMPLATE_INTEGRATION = IntegrationTesting(
149
+ bases=(POD_TEMPLATE_FIXTURE,),
150
+ name='POD_TEMPLATE_INTEGRATION'
151
+ )
152
+
153
+ POD_TEMPLATE_FUNCTIONAL = FunctionalTesting(
154
+ bases=(POD_TEMPLATE_FIXTURE,),
155
+ name='POD_TEMPLATE_FUNCTIONAL'
156
+ )
157
+
158
+
159
+ ACCEPTANCE = FunctionalTesting(
160
+ bases=(
161
+ POD_TEMPLATE_FIXTURE,
162
+ REMOTE_LIBRARY_BUNDLE_FIXTURE,
163
+ z2.ZSERVER_FIXTURE
164
+ ),
165
+ name='ACCEPTANCE'
166
+ )
167
+
168
+
169
+ class BaseTest(unittest.TestCase):
170
+ """
171
+ Helper class for tests.
172
+ """
173
+
174
+ def setUp(self):
175
+ self.portal = self.layer['portal']
176
+ if not HAS_PLONE_5:
177
+ ltool = self.portal.portal_languages
178
+ defaultLanguage = 'fr'
179
+ supportedLanguages = ['en', 'fr']
180
+ ltool.manage_setLanguageSettings(defaultLanguage, supportedLanguages,
181
+ setUseCombinedLanguageCodes=False)
182
+ self.portal.portal_languages.setLanguageBindings()
183
+
184
+ def get_odt_content_xml(self, generated_doc):
185
+ """Return content.xml from a generated doc binary."""
186
+ tmp_dir = tempfile.gettempdir()
187
+ tmp_file = open(os.path.join(tmp_dir, 'tmp_file.zip'), 'w')
188
+ tmp_file.write(generated_doc)
189
+ tmp_file.close()
190
+ zfile = zipfile.ZipFile(tmp_file.name, 'r')
191
+ content_xml = zfile.read('content.xml')
192
+ zfile.close()
193
+ os.remove(tmp_file.name)
194
+ return content_xml
195
+
196
+
197
+ class BrowserTest(BaseTest):
198
+ """
199
+ Helper class for Browser tests.
200
+ """
201
+
202
+ def setUp(self):
203
+ super(BrowserTest, self).setUp()
204
+ if HAS_PLONE_5_2:
205
+ from plone.testing import zope
206
+ self.browser = zope.Browser(self.portal)
207
+ else:
208
+ self.browser = z2.Browser(self.portal)
209
+ self.browser.handleErrors = False
210
+
211
+ def browser_login(self, user, password):
212
+ login(self.portal, user)
213
+ self.browser.open(self.portal.absolute_url() + '/logout')
214
+ self.browser.open(self.portal.absolute_url() + '/login_form')
215
+ self.browser.getControl(name='__ac_name').value = user
216
+ self.browser.getControl(name='__ac_password').value = password
217
+ if HAS_PLONE_5_2:
218
+ self.browser.getControl(name='buttons.login').click()
219
+ else:
220
+ self.browser.getControl(name='submit').click()
221
+
222
+ def _edit_object(self, obj):
223
+ token = createToken()
224
+ self.browser.open('{}/?_authenticator={}'.format(obj.absolute_url(), token))
225
+ contents = self.browser.contents
226
+ return contents
227
+
228
+
229
+ class PODTemplateIntegrationTest(BrowserTest):
230
+ """Base class for integration browser tests."""
231
+
232
+ layer = POD_TEMPLATE_INTEGRATION
233
+
234
+ def setUp(self):
235
+ super(PODTemplateIntegrationTest, self).setUp()
236
+ self.test_podtemplate = self.portal.podtemplates.get('test_template')
237
+ self.browser_login(TEST_USER_NAME, TEST_USER_PASSWORD)
238
+ setLocal('request', self.portal.REQUEST)
239
+
240
+
241
+ class PODTemplateFunctionalTest(BrowserTest):
242
+ """Base class for functional browser tests."""
243
+
244
+ layer = POD_TEMPLATE_FUNCTIONAL
245
+
246
+ def setUp(self):
247
+ super(PODTemplateFunctionalTest, self).setUp()
248
+ self.test_podtemplate = self.portal.podtemplates.get('test_template_bis')
249
+ self.browser_login(TEST_USER_NAME, TEST_USER_PASSWORD)
250
+ setLocal('request', self.portal.REQUEST)
251
+
252
+
253
+ class ConfigurablePODTemplateIntegrationTest(BrowserTest):
254
+ """Base class for integration tests."""
255
+
256
+ layer = POD_TEMPLATE_INTEGRATION
257
+
258
+ def setUp(self):
259
+ super(ConfigurablePODTemplateIntegrationTest, self).setUp()
260
+ self.test_podtemplate = self.portal.podtemplates.get('test_template_bis')
261
+ self.browser_login(TEST_USER_NAME, TEST_USER_PASSWORD)
262
+ setLocal('request', self.portal.REQUEST)
263
+
264
+
265
+ class ArchetypesIntegrationTests(BaseTest):
266
+ """Base class for Archetypes implementation tests."""
267
+
268
+ layer = POD_TEMPLATE_INTEGRATION
269
+
270
+ def setUp(self):
271
+ super(ArchetypesIntegrationTests, self).setUp()
272
+
273
+ # allow AT Topic creation anywhere on the site
274
+ portal_types = api.portal.get_tool('portal_types')
275
+ portal_types.Topic.global_allow = True
276
+
277
+ # create our AT test object: a Topic
278
+ AT_topic = api.content.create(
279
+ type='Topic',
280
+ id='AT_topic',
281
+ container=self.portal
282
+ )
283
+ self.AT_topic = AT_topic
284
+
285
+ AT_doc = api.content.create(
286
+ type='Document',
287
+ id='AT_doc',
288
+ container=self.portal
289
+ )
290
+ self.AT_doc = AT_doc
291
+ setLocal('request', self.portal.REQUEST)
292
+
293
+
294
+ class ArchetypesFunctionnalTests(ArchetypesIntegrationTests):
295
+ """Base class for Archetypes functional tests."""
296
+
297
+ layer = POD_TEMPLATE_FUNCTIONAL
298
+
299
+
300
+ class DexterityIntegrationTests(BaseTest):
301
+
302
+ """Base class for Dexterity implementation tests."""
303
+
304
+ layer = POD_TEMPLATE_INTEGRATION
305
+
306
+ def setUp(self):
307
+ super(DexterityIntegrationTests, self).setUp()
308
+
309
+ # create a test content type
310
+ self.content = api.content.create(
311
+ container=self.portal, id='johndoe', type='member')
312
+
313
+ doc = api.content.create(
314
+ type='Document',
315
+ id='doc',
316
+ container=self.portal
317
+ )
318
+ self.doc = doc
319
+
320
+
321
+ class DexterityFunctionnalTests(DexterityIntegrationTests):
322
+ """Base class for Dexterity functional tests."""
323
+
324
+ layer = POD_TEMPLATE_FUNCTIONAL
@@ -0,0 +1,16 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
4
+ i18n_domain="collective.documentgenerator">
5
+
6
+ <include file="configure.zcml" />
7
+
8
+ <genericsetup:registerProfile
9
+ name="testing"
10
+ title="collective.documentgenerator tests"
11
+ directory="profiles/testing"
12
+ description="Steps to ease tests of collective.documentgenerator"
13
+ provides="Products.GenericSetup.interfaces.EXTENSION"
14
+ />
15
+
16
+ </configure>
File without changes
File without changes