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.
- collective/documentgenerator/AT_renderer.py +98 -0
- collective/documentgenerator/DX_renderer.py +52 -0
- collective/documentgenerator/__init__.py +17 -0
- collective/documentgenerator/adapters.py +23 -0
- collective/documentgenerator/browser/__init__.py +0 -0
- collective/documentgenerator/browser/actionspanel.py +19 -0
- collective/documentgenerator/browser/check_pod_templates.pt +63 -0
- collective/documentgenerator/browser/children_pod_template.pt +16 -0
- collective/documentgenerator/browser/configure.zcml +220 -0
- collective/documentgenerator/browser/controlpanel.py +159 -0
- collective/documentgenerator/browser/converter.py +43 -0
- collective/documentgenerator/browser/generation_view.py +532 -0
- collective/documentgenerator/browser/overrides.py +9 -0
- collective/documentgenerator/browser/resources/css/documentgenerator.css +133 -0
- collective/documentgenerator/browser/static/.gitkeep +0 -0
- collective/documentgenerator/browser/static/configurable.svg +1232 -0
- collective/documentgenerator/browser/static/csv.svg +521 -0
- collective/documentgenerator/browser/static/doc.svg +23 -0
- collective/documentgenerator/browser/static/docx.svg +20 -0
- collective/documentgenerator/browser/static/download_icon.svg +54 -0
- collective/documentgenerator/browser/static/libreoffice-blanck.svg +481 -0
- collective/documentgenerator/browser/static/mailinglooptemplate.svg +1207 -0
- collective/documentgenerator/browser/static/missing_use.svg +42 -0
- collective/documentgenerator/browser/static/nok.svg +38 -0
- collective/documentgenerator/browser/static/nok_use.svg +38 -0
- collective/documentgenerator/browser/static/nok_used.svg +38 -0
- collective/documentgenerator/browser/static/odp.svg +1264 -0
- collective/documentgenerator/browser/static/ods.svg +1354 -0
- collective/documentgenerator/browser/static/odt.svg +1347 -0
- collective/documentgenerator/browser/static/ok.svg +38 -0
- collective/documentgenerator/browser/static/ok_use.svg +38 -0
- collective/documentgenerator/browser/static/ok_used.svg +38 -0
- collective/documentgenerator/browser/static/pdf.svg +557 -0
- collective/documentgenerator/browser/static/podtemplate.svg +1197 -0
- collective/documentgenerator/browser/static/rtf.svg +521 -0
- collective/documentgenerator/browser/static/style.svg +1207 -0
- collective/documentgenerator/browser/static/subtemplate.svg +1250 -0
- collective/documentgenerator/browser/static/xls.svg +159 -0
- collective/documentgenerator/browser/static/xlsx.svg +48 -0
- collective/documentgenerator/browser/table.py +277 -0
- collective/documentgenerator/browser/templates_listing.pt +23 -0
- collective/documentgenerator/browser/views.py +365 -0
- collective/documentgenerator/config.py +162 -0
- collective/documentgenerator/configure.zcml +41 -0
- collective/documentgenerator/content/__init__.py +0 -0
- collective/documentgenerator/content/condition.py +60 -0
- collective/documentgenerator/content/conditions.zcml +29 -0
- collective/documentgenerator/content/configure.zcml +25 -0
- collective/documentgenerator/content/document_factory.py +73 -0
- collective/documentgenerator/content/file_representation.py +73 -0
- collective/documentgenerator/content/file_representation.zcml +28 -0
- collective/documentgenerator/content/merge_templates.py +15 -0
- collective/documentgenerator/content/merge_templates.zcml +10 -0
- collective/documentgenerator/content/pod_template.py +547 -0
- collective/documentgenerator/content/style_template.py +52 -0
- collective/documentgenerator/content/vocabulary.py +315 -0
- collective/documentgenerator/content/vocabulary.zcml +104 -0
- collective/documentgenerator/demo/__init__.py +0 -0
- collective/documentgenerator/demo/archetypes.zcml +10 -0
- collective/documentgenerator/demo/configure.zcml +19 -0
- collective/documentgenerator/demo/helper.py +198 -0
- collective/documentgenerator/events/__init__.py +0 -0
- collective/documentgenerator/events/configure.zcml +30 -0
- collective/documentgenerator/events/pod_templates_events.py +66 -0
- collective/documentgenerator/events/styles_events.py +122 -0
- collective/documentgenerator/helper/__init__.py +9 -0
- collective/documentgenerator/helper/archetypes-adapter.zcml +10 -0
- collective/documentgenerator/helper/archetypes-page.zcml +9 -0
- collective/documentgenerator/helper/archetypes.py +67 -0
- collective/documentgenerator/helper/base.py +266 -0
- collective/documentgenerator/helper/configure.zcml +38 -0
- collective/documentgenerator/helper/dexterity.py +174 -0
- collective/documentgenerator/interfaces.py +165 -0
- collective/documentgenerator/locales/collective.documentgenerator.pot +564 -0
- collective/documentgenerator/locales/es/LC_MESSAGES/collective.documentgenerator.po +572 -0
- collective/documentgenerator/locales/es/LC_MESSAGES/plone.po +32 -0
- collective/documentgenerator/locales/fr/LC_MESSAGES/collective.documentgenerator.po +566 -0
- collective/documentgenerator/locales/fr/LC_MESSAGES/plone.po +27 -0
- collective/documentgenerator/locales/manual.pot +30 -0
- collective/documentgenerator/locales/plone-manual.pot +22 -0
- collective/documentgenerator/locales/plone.pot +30 -0
- collective/documentgenerator/locales/update.sh +22 -0
- collective/documentgenerator/migrations/__init__.py +0 -0
- collective/documentgenerator/migrations/migrate_to_11.py +53 -0
- collective/documentgenerator/migrations/migrate_to_12.py +30 -0
- collective/documentgenerator/migrations/migrate_to_13.py +37 -0
- collective/documentgenerator/migrations/migrate_to_3.py +36 -0
- collective/documentgenerator/migrations/migrate_to_5.py +30 -0
- collective/documentgenerator/migrations/migrate_to_6.py +27 -0
- collective/documentgenerator/migrations/migrate_to_7.py +32 -0
- collective/documentgenerator/migrations/migrate_to_8.py +34 -0
- collective/documentgenerator/migrations/migrate_to_9.py +48 -0
- collective/documentgenerator/profiles/base/browserlayer.xml +7 -0
- collective/documentgenerator/profiles/base/controlpanel.xml +20 -0
- collective/documentgenerator/profiles/base/metadata.xml +7 -0
- collective/documentgenerator/profiles/base/types/ConfigurablePODTemplate.xml +43 -0
- collective/documentgenerator/profiles/base/types/MailingLoopTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/PODTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/StyleTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types/SubTemplate.xml +42 -0
- collective/documentgenerator/profiles/base/types.xml +10 -0
- collective/documentgenerator/profiles/base/viewlets.xml +6 -0
- collective/documentgenerator/profiles/demo/browserlayer.xml +7 -0
- collective/documentgenerator/profiles/demo/collectivedocumentgenerator_demo_marker.txt +0 -0
- collective/documentgenerator/profiles/demo/import_steps.xml +11 -0
- collective/documentgenerator/profiles/demo/metadata.xml +7 -0
- collective/documentgenerator/profiles/demo/registry.xml +13 -0
- collective/documentgenerator/profiles/demo/templates/mailing.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/modele_general.ods +0 -0
- collective/documentgenerator/profiles/demo/templates/modele_general.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/mod/303/250le_collection.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/possibly_mailed_model.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/styles.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/styles_2.odt +0 -0
- collective/documentgenerator/profiles/demo/templates/sub_template.odt +0 -0
- collective/documentgenerator/profiles/demo/viewlets.xml +3 -0
- collective/documentgenerator/profiles/plone4/collectivedocumentgenerator_marker.txt +0 -0
- collective/documentgenerator/profiles/plone4/cssregistry.xml +11 -0
- collective/documentgenerator/profiles/plone4/metadata.xml +7 -0
- collective/documentgenerator/profiles/plone4/registry.xml +6 -0
- collective/documentgenerator/profiles/plone5/metadata.xml +7 -0
- collective/documentgenerator/profiles/plone5/registry.xml +15 -0
- collective/documentgenerator/profiles/testing/metadata.xml +7 -0
- collective/documentgenerator/profiles/testing/propertiestool.xml +5 -0
- collective/documentgenerator/profiles/testing/types/member.xml +85 -0
- collective/documentgenerator/profiles/testing/types.xml +5 -0
- collective/documentgenerator/profiles.zcml +186 -0
- collective/documentgenerator/renderer.zcml +145 -0
- collective/documentgenerator/search_replace/__init__.py +0 -0
- collective/documentgenerator/search_replace/configure.zcml +19 -0
- collective/documentgenerator/search_replace/pod_template.py +146 -0
- collective/documentgenerator/search_replace/search_result_form.pt +48 -0
- collective/documentgenerator/search_replace/searchreplace_panel.pt +22 -0
- collective/documentgenerator/search_replace/searchreplace_panel.py +261 -0
- collective/documentgenerator/setuphandlers.py +287 -0
- collective/documentgenerator/testing.py +324 -0
- collective/documentgenerator/testing.zcml +16 -0
- collective/documentgenerator/tests/__init__.py +0 -0
- collective/documentgenerator/tests/failing_template.odt +0 -0
- collective/documentgenerator/tests/robot/.gitkeep +0 -0
- collective/documentgenerator/tests/template_to_clean.odt +0 -0
- collective/documentgenerator/tests/template_without_style_page.odt +0 -0
- collective/documentgenerator/tests/test_AT_helper_view.py +276 -0
- collective/documentgenerator/tests/test_DX_helper_view.py +355 -0
- collective/documentgenerator/tests/test_base_helper_view.py +128 -0
- collective/documentgenerator/tests/test_check_podtemplates_view.py +138 -0
- collective/documentgenerator/tests/test_config.py +106 -0
- collective/documentgenerator/tests/test_configurable_pod_template.py +383 -0
- collective/documentgenerator/tests/test_demo_profile.py +115 -0
- collective/documentgenerator/tests/test_events.py +169 -0
- collective/documentgenerator/tests/test_file.odt +0 -0
- collective/documentgenerator/tests/test_generation_view.py +652 -0
- collective/documentgenerator/tests/test_mailing.odt +0 -0
- collective/documentgenerator/tests/test_mailing_loop_template.py +48 -0
- collective/documentgenerator/tests/test_pod_template.py +178 -0
- collective/documentgenerator/tests/test_robot.py +26 -0
- collective/documentgenerator/tests/test_search_replace.py +419 -0
- collective/documentgenerator/tests/test_setup.py +49 -0
- collective/documentgenerator/tests/test_style_template.py +19 -0
- collective/documentgenerator/tests/test_sub_template.py +49 -0
- collective/documentgenerator/tests/test_templates_listing_view.py +91 -0
- collective/documentgenerator/tests/test_utils.py +244 -0
- collective/documentgenerator/tests/test_vocabulary.py +154 -0
- collective/documentgenerator/utils.py +396 -0
- collective/documentgenerator/viewlets/__init__.py +0 -0
- collective/documentgenerator/viewlets/batchactions.py +14 -0
- collective/documentgenerator/viewlets/configure.zcml +16 -0
- collective/documentgenerator/viewlets/generationlinks.pt +28 -0
- collective/documentgenerator/viewlets/generationlinks.py +58 -0
- collective.documentgenerator-3.46-py3.13-nspkg.pth +1 -0
- collective_documentgenerator-3.46.dist-info/METADATA +1142 -0
- collective_documentgenerator-3.46.dist-info/RECORD +176 -0
- collective_documentgenerator-3.46.dist-info/WHEEL +5 -0
- collective_documentgenerator-3.46.dist-info/entry_points.txt +5 -0
- collective_documentgenerator-3.46.dist-info/namespace_packages.txt +1 -0
- collective_documentgenerator-3.46.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from AccessControl import Unauthorized
|
|
4
|
+
from appy.shared.zip import unzip
|
|
5
|
+
from collective.documentgenerator.config import get_column_modifier
|
|
6
|
+
from collective.documentgenerator.config import get_raiseOnError_for_non_managers
|
|
7
|
+
from collective.documentgenerator.config import set_column_modifier
|
|
8
|
+
from collective.documentgenerator.content.pod_template import MailingLoopTemplate
|
|
9
|
+
from collective.documentgenerator.content.pod_template import SubTemplate
|
|
10
|
+
from collective.documentgenerator.interfaces import CyclicMergeTemplatesException
|
|
11
|
+
from collective.documentgenerator.interfaces import PODTemplateNotFoundError
|
|
12
|
+
from collective.documentgenerator.testing import POD_TEMPLATE_INTEGRATION
|
|
13
|
+
from collective.documentgenerator.testing import PODTemplateIntegrationTest
|
|
14
|
+
from collective.documentgenerator.testing import TEST_INSTALL_INTEGRATION
|
|
15
|
+
from collective.documentgenerator.utils import create_temporary_file
|
|
16
|
+
from collective.documentgenerator.utils import translate as _
|
|
17
|
+
from imio.helpers import HAS_PLONE_5
|
|
18
|
+
from plone import api
|
|
19
|
+
from plone.app.testing import login
|
|
20
|
+
from plone.app.testing import TEST_USER_NAME
|
|
21
|
+
from plone.app.textfield.value import RichTextValue
|
|
22
|
+
from plone.namedfile.file import NamedBlobFile
|
|
23
|
+
from Products.CMFPlone.utils import base_hasattr
|
|
24
|
+
from zope.annotation.interfaces import IAnnotations
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import tempfile
|
|
28
|
+
import unittest
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TestGenerationView(unittest.TestCase):
|
|
32
|
+
"""
|
|
33
|
+
Test document generation view.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
layer = TEST_INSTALL_INTEGRATION
|
|
37
|
+
|
|
38
|
+
def test_view_registration(self):
|
|
39
|
+
from collective.documentgenerator.browser.generation_view import DocumentGenerationView
|
|
40
|
+
|
|
41
|
+
portal = api.portal.getSite()
|
|
42
|
+
generation_view = portal.restrictedTraverse('@@document-generation')
|
|
43
|
+
self.assertTrue(generation_view)
|
|
44
|
+
self.assertTrue(isinstance(generation_view, DocumentGenerationView))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestGenerationViewMethods(PODTemplateIntegrationTest):
|
|
48
|
+
"""
|
|
49
|
+
"""
|
|
50
|
+
def test_get_pod_template_uid(self):
|
|
51
|
+
"""
|
|
52
|
+
By default, this will get the 'template_uid' from the request.
|
|
53
|
+
"""
|
|
54
|
+
test_UID = '12345'
|
|
55
|
+
view = self.portal.restrictedTraverse('@@document-generation')
|
|
56
|
+
view.request.set('template_uid', test_UID)
|
|
57
|
+
self.assertTrue(view.get_pod_template_uid() == test_UID)
|
|
58
|
+
|
|
59
|
+
def test_get_generation_format(self):
|
|
60
|
+
"""
|
|
61
|
+
By default, this will get the 'output_format' from the request.
|
|
62
|
+
"""
|
|
63
|
+
output_format = 'odt'
|
|
64
|
+
view = self.portal.restrictedTraverse('@@document-generation')
|
|
65
|
+
view.request.set('output_format', output_format)
|
|
66
|
+
self.assertTrue(view.get_generation_format() == output_format)
|
|
67
|
+
|
|
68
|
+
def test__call__params_not_given(self):
|
|
69
|
+
"""
|
|
70
|
+
__call__ receives 'template_uid' and 'output_format' as params, if it is None,
|
|
71
|
+
it tries to get it using 'get_pod_template_uid' and 'get_generation_format' methods.
|
|
72
|
+
"""
|
|
73
|
+
pod_template = self.test_podtemplate
|
|
74
|
+
template_uid = pod_template.UID()
|
|
75
|
+
view = self.portal.podtemplates.restrictedTraverse('@@document-generation')
|
|
76
|
+
self.assertRaises(PODTemplateNotFoundError, view, template_uid=None, output_format=None)
|
|
77
|
+
# set parameters in REQUEST as it is default implementation of
|
|
78
|
+
# 'get_pod_template_uid' and 'get_generation_format' methods
|
|
79
|
+
view.request.set('template_uid', template_uid)
|
|
80
|
+
view.request.set('output_format', 'odt')
|
|
81
|
+
self.assertTrue(view())
|
|
82
|
+
|
|
83
|
+
def test_get_pod_template(self):
|
|
84
|
+
"""
|
|
85
|
+
When passing a real template UID, get_pod_template() should return this
|
|
86
|
+
template.
|
|
87
|
+
"""
|
|
88
|
+
pod_template = self.test_podtemplate
|
|
89
|
+
template_uid = pod_template.UID()
|
|
90
|
+
view = self.portal.restrictedTraverse('@@document-generation')
|
|
91
|
+
self.assertTrue(view.get_pod_template(template_uid) == pod_template)
|
|
92
|
+
|
|
93
|
+
def test_get_pod_template_not_found(self):
|
|
94
|
+
"""
|
|
95
|
+
When a template cannot be found, a PODTemplateNotFoundError should be raised.
|
|
96
|
+
"""
|
|
97
|
+
from collective.documentgenerator.interfaces import PODTemplateNotFoundError
|
|
98
|
+
|
|
99
|
+
template_uid = 'TROLOLO'
|
|
100
|
+
view = self.portal.restrictedTraverse('@@document-generation')
|
|
101
|
+
error_raised = False
|
|
102
|
+
try:
|
|
103
|
+
view.get_pod_template(template_uid)
|
|
104
|
+
except PODTemplateNotFoundError:
|
|
105
|
+
error_raised = True
|
|
106
|
+
self.assertTrue(error_raised)
|
|
107
|
+
|
|
108
|
+
def test_document_generation_call(self):
|
|
109
|
+
"""
|
|
110
|
+
Check if documents are rendered correctly.
|
|
111
|
+
"""
|
|
112
|
+
pod_template = self.test_podtemplate
|
|
113
|
+
template_uid = pod_template.UID()
|
|
114
|
+
view = self.portal.podtemplates.restrictedTraverse('@@document-generation')
|
|
115
|
+
# an 'output_format' must be given or it raises an Exception
|
|
116
|
+
with self.assertRaises(Exception) as cm:
|
|
117
|
+
view(template_uid, output_format='')
|
|
118
|
+
self.assertEqual(
|
|
119
|
+
str(cm.exception),
|
|
120
|
+
"No 'output_format' found to generate this document"
|
|
121
|
+
)
|
|
122
|
+
# if 'output_format' is not in available pod_formats of template, it raises an Exception
|
|
123
|
+
self.assertNotIn('pdf', pod_template.get_available_formats())
|
|
124
|
+
self.assertRaises(Exception, view)
|
|
125
|
+
with self.assertRaises(Exception) as cm:
|
|
126
|
+
view(template_uid, 'pdf')
|
|
127
|
+
self.assertEqual(
|
|
128
|
+
str(cm.exception),
|
|
129
|
+
"Asked output format 'pdf' is not available for template 'test_template'!"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
# right, ask available format
|
|
133
|
+
self.assertIn('odt', pod_template.get_available_formats())
|
|
134
|
+
generated_doc = view(template_uid, 'odt')
|
|
135
|
+
|
|
136
|
+
self.assertIn('application/vnd.oasis.opendocument.text', generated_doc)
|
|
137
|
+
|
|
138
|
+
def test_unauthorized_generation(self):
|
|
139
|
+
"""
|
|
140
|
+
If a template generation condition is not matched, an Unauthorized
|
|
141
|
+
exception should be raised when trying to generate that document.
|
|
142
|
+
"""
|
|
143
|
+
pod_template = self.test_podtemplate
|
|
144
|
+
template_uid = pod_template.UID()
|
|
145
|
+
# Make sure can_be_generated will return False.
|
|
146
|
+
pod_template.can_be_generated = lambda x: False
|
|
147
|
+
self.assertTrue(not pod_template.can_be_generated(self.portal))
|
|
148
|
+
|
|
149
|
+
view = self.portal.restrictedTraverse('@@document-generation')
|
|
150
|
+
unauthorized_raised = False
|
|
151
|
+
try:
|
|
152
|
+
view(template_uid, 'odt')
|
|
153
|
+
except Unauthorized:
|
|
154
|
+
unauthorized_raised = True
|
|
155
|
+
self.assertTrue(unauthorized_raised)
|
|
156
|
+
|
|
157
|
+
def test_persistent_document_generation_call(self):
|
|
158
|
+
"""
|
|
159
|
+
Check if documents are rendered correctly.
|
|
160
|
+
"""
|
|
161
|
+
pod_template = self.test_podtemplate
|
|
162
|
+
template_uid = pod_template.UID()
|
|
163
|
+
generation_context = api.content.create(
|
|
164
|
+
type='Folder',
|
|
165
|
+
title=u'Folder title > 200m² to test – filename generation 1.2.3.4 with accent héhé '
|
|
166
|
+
u'actually we test with a title that is longer than 120 characters so we may '
|
|
167
|
+
u'evaluate cropText method that is sensitive to some characters like -',
|
|
168
|
+
id='test_folder',
|
|
169
|
+
container=self.portal,
|
|
170
|
+
)
|
|
171
|
+
generation_view = generation_context.restrictedTraverse('@@persistent-document-generation')
|
|
172
|
+
generation_view(template_uid, 'odt')
|
|
173
|
+
generated_id = 'general-template'
|
|
174
|
+
msg = "File {0} should have been created in folder.".format(generated_id)
|
|
175
|
+
self.assertTrue(generated_id in generation_context.objectIds(), msg)
|
|
176
|
+
|
|
177
|
+
persistent_doc = generation_context.get(generated_id)
|
|
178
|
+
if HAS_PLONE_5:
|
|
179
|
+
generated_doc = persistent_doc.file
|
|
180
|
+
filename = persistent_doc.file.filename
|
|
181
|
+
content_type = persistent_doc.file.contentType
|
|
182
|
+
else:
|
|
183
|
+
generated_doc = persistent_doc.getFile()
|
|
184
|
+
filename = generated_doc.getFilename()
|
|
185
|
+
content_type = generated_doc.getContentType()
|
|
186
|
+
self.assertIn('application/vnd.oasis.opendocument.text', generated_doc.data)
|
|
187
|
+
|
|
188
|
+
self.assertEqual(
|
|
189
|
+
filename,
|
|
190
|
+
u'General template.odt')
|
|
191
|
+
self.assertEqual(content_type, 'application/vnd.oasis.opendocument.text')
|
|
192
|
+
self.assertEqual(persistent_doc.Title(), pod_template.Title())
|
|
193
|
+
|
|
194
|
+
# customize the title
|
|
195
|
+
custom_title = 'my awesome title'
|
|
196
|
+
generation_view(template_uid=template_uid, output_format='odt', generated_doc_title=custom_title)
|
|
197
|
+
docgen_file = generation_context.objectValues()[1]
|
|
198
|
+
self.assertEqual(docgen_file.Title(), custom_title)
|
|
199
|
+
|
|
200
|
+
def test_persistent_document_generation_on_non_folderish_context(self):
|
|
201
|
+
"""
|
|
202
|
+
If the generation view is called on a non folderish the document file should be created
|
|
203
|
+
on the parent.
|
|
204
|
+
"""
|
|
205
|
+
from collective.documentgenerator.interfaces import isNotFolderishError
|
|
206
|
+
|
|
207
|
+
pod_template = self.test_podtemplate
|
|
208
|
+
template_uid = pod_template.UID()
|
|
209
|
+
non_folderish = api.content.create(type='Document', id='doc', container=self.portal)
|
|
210
|
+
generation_view = non_folderish.restrictedTraverse('@@persistent-document-generation')
|
|
211
|
+
|
|
212
|
+
error_raised = False
|
|
213
|
+
try:
|
|
214
|
+
generation_view(template_uid, 'odt')
|
|
215
|
+
except isNotFolderishError:
|
|
216
|
+
error_raised = True
|
|
217
|
+
|
|
218
|
+
msg = "A 'isNotFolderishError' exception should have been raised."
|
|
219
|
+
self.assertTrue(error_raised, msg)
|
|
220
|
+
|
|
221
|
+
def test__get_generation_context(self):
|
|
222
|
+
pod_template = self.portal.podtemplates['test_template_bis']
|
|
223
|
+
view = self.portal.podtemplates.restrictedTraverse('@@document-generation')
|
|
224
|
+
view(template_uid=pod_template.UID(), output_format='odt')
|
|
225
|
+
hpv = view.get_generation_context_helper()
|
|
226
|
+
# Check context variables
|
|
227
|
+
self.assertDictEqual(view._get_generation_context(hpv, pod_template),
|
|
228
|
+
{'details': '1',
|
|
229
|
+
'portal': self.portal,
|
|
230
|
+
'context': hpv.context,
|
|
231
|
+
'view': hpv})
|
|
232
|
+
# Check configurable pod template
|
|
233
|
+
self.assertDictEqual(view._get_generation_context(hpv, self.test_podtemplate),
|
|
234
|
+
{'context': hpv.context,
|
|
235
|
+
'portal': self.portal,
|
|
236
|
+
'view': hpv})
|
|
237
|
+
|
|
238
|
+
rendered, filename, gen_context = view._generate_doc(pod_template, 'odt')
|
|
239
|
+
|
|
240
|
+
# The gotten helper view (hpv) is not the used one at generation
|
|
241
|
+
self.assertNotEquals(hpv, gen_context['view'])
|
|
242
|
+
|
|
243
|
+
# Check generation context subtemplates without pre-rendering
|
|
244
|
+
self.assertEqual(pod_template.merge_templates[0]['do_rendering'], False)
|
|
245
|
+
self.assertIn('header', gen_context)
|
|
246
|
+
self.assertIsInstance(gen_context['header'], SubTemplate)
|
|
247
|
+
|
|
248
|
+
# Check generation context subtemplates with pre-rendering
|
|
249
|
+
mt_conf = pod_template.merge_templates
|
|
250
|
+
mt_conf[0]['do_rendering'] = True
|
|
251
|
+
pod_template.merge_templates = mt_conf
|
|
252
|
+
self.assertEqual(pod_template.merge_templates[0]['do_rendering'], True)
|
|
253
|
+
# We call rendering to get new gen_context
|
|
254
|
+
rendered, filename, gen_context = view._generate_doc(pod_template, 'odt')
|
|
255
|
+
self.assertIsInstance(gen_context['header'], str)
|
|
256
|
+
self.assertRegexpMatches(gen_context['header'], r'.+(\.odt)$')
|
|
257
|
+
|
|
258
|
+
def test_raiseOnError_for_non_managers(self):
|
|
259
|
+
# create a POD template that will fail in every case
|
|
260
|
+
current_path = os.path.dirname(__file__)
|
|
261
|
+
failing_template_data = open(os.path.join(current_path, 'failing_template.odt'), 'r').read()
|
|
262
|
+
failing_template = api.content.create(
|
|
263
|
+
type='ConfigurablePODTemplate',
|
|
264
|
+
id='failing_template',
|
|
265
|
+
title=_(u'Failing template'),
|
|
266
|
+
odt_file=NamedBlobFile(
|
|
267
|
+
data=failing_template_data,
|
|
268
|
+
contentType='application/vnd.oasis.opendocument.text',
|
|
269
|
+
filename=u'modele_general.odt',
|
|
270
|
+
),
|
|
271
|
+
pod_formats=['odt'],
|
|
272
|
+
container=self.portal.podtemplates,
|
|
273
|
+
exclude_from_nav=True
|
|
274
|
+
)
|
|
275
|
+
# create a user that is not Manager
|
|
276
|
+
api.user.create(
|
|
277
|
+
email='test@test.be',
|
|
278
|
+
username='user',
|
|
279
|
+
password='12345',
|
|
280
|
+
roles=['Member'],
|
|
281
|
+
properties={})
|
|
282
|
+
|
|
283
|
+
# disabled by default
|
|
284
|
+
self.assertFalse(get_raiseOnError_for_non_managers())
|
|
285
|
+
# when disabled, generating by anybody will always produce a document
|
|
286
|
+
view = failing_template.restrictedTraverse('@@document-generation')
|
|
287
|
+
template_UID = failing_template.UID()
|
|
288
|
+
# generated for 'Manager'
|
|
289
|
+
self.assertTrue('Manager' in api.user.get_current().getRoles())
|
|
290
|
+
self.assertTrue(
|
|
291
|
+
'mimetypeapplication/vnd.oasis.opendocument.text' in
|
|
292
|
+
view(template_uid=template_UID, output_format='odt'))
|
|
293
|
+
# generated for non 'Manager'
|
|
294
|
+
login(self.portal, 'user')
|
|
295
|
+
self.assertFalse('Manager' in api.user.get_current().getRoles())
|
|
296
|
+
self.assertTrue(
|
|
297
|
+
'mimetypeapplication/vnd.oasis.opendocument.text' in
|
|
298
|
+
view(template_uid=template_UID, output_format='odt'))
|
|
299
|
+
|
|
300
|
+
# enable raiseOnError_for_non_managers and test again
|
|
301
|
+
login(self.portal, TEST_USER_NAME)
|
|
302
|
+
api.portal.set_registry_record(
|
|
303
|
+
'collective.documentgenerator.browser.controlpanel.'
|
|
304
|
+
'IDocumentGeneratorControlPanelSchema.raiseOnError_for_non_managers',
|
|
305
|
+
True)
|
|
306
|
+
self.assertTrue(
|
|
307
|
+
'mimetypeapplication/vnd.oasis.opendocument.text' in
|
|
308
|
+
view(template_uid=template_UID, output_format='odt'))
|
|
309
|
+
login(self.portal, 'user')
|
|
310
|
+
# raises an error instead generating the document
|
|
311
|
+
with self.assertRaises(Exception) as cm:
|
|
312
|
+
view(template_uid=template_UID, output_format='odt')
|
|
313
|
+
self.assertTrue(
|
|
314
|
+
'Error while evaluating expression "view.unknown_method()".' in str(cm.exception))
|
|
315
|
+
|
|
316
|
+
def test_mailing_loop_persistent_document_generation(self):
|
|
317
|
+
pod_template = self.portal.podtemplates.get('test_template_possibly_mailed')
|
|
318
|
+
template_uid = pod_template.UID()
|
|
319
|
+
folder = api.content.create(type='Folder', title=u'Folder', id='test_folder', container=self.portal)
|
|
320
|
+
# Check dexterity values
|
|
321
|
+
orig_registry = api.portal.get_registry_record('collective.documentgenerator.mailing_list')
|
|
322
|
+
|
|
323
|
+
def get_content(blob_file):
|
|
324
|
+
tmpdir = tempfile.mkdtemp()
|
|
325
|
+
temp_file = create_temporary_file(blob_file)
|
|
326
|
+
info = unzip(temp_file.name, tmpdir, odf=True)
|
|
327
|
+
os.remove(temp_file.name)
|
|
328
|
+
return info
|
|
329
|
+
|
|
330
|
+
# First we generate a persistent document with only one element in mailing list
|
|
331
|
+
api.portal.set_registry_record('collective.documentgenerator.mailing_list', orig_registry[0:1])
|
|
332
|
+
generation_view = folder.restrictedTraverse('@@persistent-document-generation')
|
|
333
|
+
generation_view(template_uid, 'odt')
|
|
334
|
+
generated_id = 'possibly-mailed-template'
|
|
335
|
+
msg = "File {0} should have been created in folder.".format(generated_id)
|
|
336
|
+
self.assertTrue(generated_id in folder.objectIds(), msg)
|
|
337
|
+
persistent_doc = folder.get(generated_id)
|
|
338
|
+
annot = IAnnotations(persistent_doc)
|
|
339
|
+
self.assertIn('documentgenerator', annot)
|
|
340
|
+
self.assertIn('template_uid', annot['documentgenerator'])
|
|
341
|
+
self.assertNotIn('context_uid', annot['documentgenerator'])
|
|
342
|
+
self.assertEqual(annot['documentgenerator']['need_mailing'], False)
|
|
343
|
+
if HAS_PLONE_5:
|
|
344
|
+
generated_doc = persistent_doc.file
|
|
345
|
+
else:
|
|
346
|
+
generated_doc = persistent_doc.getFile()
|
|
347
|
+
info = get_content(generated_doc)
|
|
348
|
+
self.assertNotIn('mailed_data', info['content.xml'])
|
|
349
|
+
self.assertIn('General template', info['content.xml'])
|
|
350
|
+
self.assertIn('test_template', info['content.xml'])
|
|
351
|
+
|
|
352
|
+
# Secondly we generate a persistent document with multiple element in mailing list
|
|
353
|
+
api.portal.set_registry_record('collective.documentgenerator.mailing_list', orig_registry)
|
|
354
|
+
generation_view = folder.restrictedTraverse('@@persistent-document-generation')
|
|
355
|
+
generation_view(template_uid, 'odt')
|
|
356
|
+
generated_id = 'possibly-mailed-template-1'
|
|
357
|
+
msg = "File {0} should have been created in folder.".format(generated_id)
|
|
358
|
+
self.assertTrue(generated_id in folder.objectIds(), msg)
|
|
359
|
+
persistent_doc = folder.get(generated_id)
|
|
360
|
+
annot = IAnnotations(persistent_doc)
|
|
361
|
+
self.assertIn('documentgenerator', annot)
|
|
362
|
+
self.assertIn('template_uid', annot['documentgenerator'])
|
|
363
|
+
self.assertIn('context_uid', annot['documentgenerator'])
|
|
364
|
+
self.assertEqual(annot['documentgenerator']['need_mailing'], True)
|
|
365
|
+
if HAS_PLONE_5:
|
|
366
|
+
generated_doc = persistent_doc.file
|
|
367
|
+
else:
|
|
368
|
+
generated_doc = persistent_doc.getFile()
|
|
369
|
+
info = get_content(generated_doc)
|
|
370
|
+
self.assertNotIn('General template', info['content.xml'])
|
|
371
|
+
self.assertNotIn('test_template', info['content.xml'])
|
|
372
|
+
self.assertIn('mailed_data.title', info['content.xml'])
|
|
373
|
+
self.assertIn('mailed_data.id', info['content.xml'])
|
|
374
|
+
# check context variables
|
|
375
|
+
gen_context = generation_view._get_generation_context(generation_view.get_generation_context_helper(),
|
|
376
|
+
pod_template)
|
|
377
|
+
self.assertIn('details', gen_context)
|
|
378
|
+
self.assertEqual(gen_context['details'], '1')
|
|
379
|
+
|
|
380
|
+
# the mailing loop view is called on the folder context !
|
|
381
|
+
generation_view = folder.restrictedTraverse('@@mailing-loop-persistent-document-generation')
|
|
382
|
+
generation_view(document_uid=persistent_doc.UID())
|
|
383
|
+
generation_view(document_url_path=persistent_doc.absolute_url_path())
|
|
384
|
+
generated_id = 'mailing-loop-template'
|
|
385
|
+
generated_id_2 = 'mailing-loop-template-1'
|
|
386
|
+
msg = "File {0} should have been created in folder.".format(generated_id)
|
|
387
|
+
self.assertTrue(generated_id in folder.objectIds(), msg)
|
|
388
|
+
msg = "File {0} should have been created in folder.".format(generated_id_2)
|
|
389
|
+
self.assertTrue(generated_id_2 in folder.objectIds(), msg)
|
|
390
|
+
persistent_doc = folder.get(generated_id)
|
|
391
|
+
annot = IAnnotations(persistent_doc)
|
|
392
|
+
self.assertIn('documentgenerator', annot)
|
|
393
|
+
self.assertIn('template_uid', annot['documentgenerator'])
|
|
394
|
+
self.assertNotIn('context_uid', annot['documentgenerator'])
|
|
395
|
+
self.assertEqual(annot['documentgenerator']['need_mailing'], False)
|
|
396
|
+
if HAS_PLONE_5:
|
|
397
|
+
generated_doc = persistent_doc.file
|
|
398
|
+
else:
|
|
399
|
+
generated_doc = persistent_doc.getFile()
|
|
400
|
+
info = get_content(generated_doc)
|
|
401
|
+
self.assertNotIn('mailed_data', info['content.xml'])
|
|
402
|
+
self.assertIn('General template', info['content.xml'])
|
|
403
|
+
self.assertIn('test_template', info['content.xml'])
|
|
404
|
+
self.assertIn('Multiple format template', info['content.xml'])
|
|
405
|
+
self.assertIn('test_template_multiple', info['content.xml'])
|
|
406
|
+
self.assertIn('Collection template', info['content.xml'])
|
|
407
|
+
self.assertIn('test_template_bis', info['content.xml'])
|
|
408
|
+
# check that context variables from original template are also in mailing generation context
|
|
409
|
+
self.assertTrue(isinstance(generation_view.pod_template, MailingLoopTemplate))
|
|
410
|
+
gen_context = generation_view._get_generation_context(generation_view.get_generation_context_helper(),
|
|
411
|
+
generation_view.pod_template)
|
|
412
|
+
self.assertIn('details', gen_context)
|
|
413
|
+
self.assertEqual(gen_context['details'], '1')
|
|
414
|
+
|
|
415
|
+
def test_table_column_modifier(self):
|
|
416
|
+
""" """
|
|
417
|
+
pod_template = self.portal.podtemplates.get('test_template_multiple')
|
|
418
|
+
# do not limit portal_type the POD template is generatable on
|
|
419
|
+
pod_template.pod_portal_types = []
|
|
420
|
+
template_uid = pod_template.UID()
|
|
421
|
+
doc = self.portal.get('front-page')
|
|
422
|
+
# add a table to check if it is optimized or not
|
|
423
|
+
text = u'<table><tr><td>Text1</td><td>Text2</td></tr><tr><td>Text3</td><td>Text4</td></tr></table>'
|
|
424
|
+
textNone = u'<table style="table-layout:none"><tr><td>Text1</td><td>Text2</td></tr>' \
|
|
425
|
+
u'<tr><td>Text3</td><td>Text4</td></tr></table>'
|
|
426
|
+
textAuto = u'<table style="table-layout:auto"><tr><td>Text1</td><td>Text2</td></tr>' \
|
|
427
|
+
u'<tr><td>Text3</td><td>Text4</td></tr></table>'
|
|
428
|
+
textFixed = u'<table style="table-layout:fixed"><tr><td>Text1</td><td>Text2</td></tr>' \
|
|
429
|
+
u'<tr><td>Text3</td><td>Text4</td></tr></table>'
|
|
430
|
+
|
|
431
|
+
generation_view = doc.restrictedTraverse('@@document-generation')
|
|
432
|
+
|
|
433
|
+
def set_text(text):
|
|
434
|
+
if base_hasattr(doc, 'setText'):
|
|
435
|
+
# Archetypes
|
|
436
|
+
doc.setText(text)
|
|
437
|
+
else:
|
|
438
|
+
# Dexterity
|
|
439
|
+
doc.text = RichTextValue(text)
|
|
440
|
+
|
|
441
|
+
def assert_result(ocw_in_xml, dc_in_xml):
|
|
442
|
+
generated_doc = generation_view(template_uid, 'odt')
|
|
443
|
+
content_xml = self.get_odt_content_xml(generated_doc)
|
|
444
|
+
self.assertEquals(ocw_in_xml, 'OCW' in content_xml, 'OCW not in content_xml')
|
|
445
|
+
self.assertEquals(dc_in_xml, 'DC' in content_xml, 'DC not in content_xml')
|
|
446
|
+
|
|
447
|
+
# By default : column_modifier disabled globally, CSS override enabled globally
|
|
448
|
+
# and pod_template using global parameter
|
|
449
|
+
self.assertEquals(get_column_modifier(), 'nothing')
|
|
450
|
+
self.assertEquals(pod_template.get_column_modifier(), -1)
|
|
451
|
+
|
|
452
|
+
set_text(text)
|
|
453
|
+
assert_result(False, False)
|
|
454
|
+
set_text(textNone)
|
|
455
|
+
assert_result(False, False)
|
|
456
|
+
set_text(textAuto)
|
|
457
|
+
assert_result(True, False)
|
|
458
|
+
set_text(textFixed)
|
|
459
|
+
assert_result(False, True)
|
|
460
|
+
|
|
461
|
+
# disable optimize locally, still disabled globally
|
|
462
|
+
pod_template.column_modifier = 'disabled'
|
|
463
|
+
set_text(text)
|
|
464
|
+
assert_result(False, False)
|
|
465
|
+
set_text(textNone)
|
|
466
|
+
assert_result(False, False)
|
|
467
|
+
set_text(textAuto)
|
|
468
|
+
assert_result(False, False)
|
|
469
|
+
set_text(textFixed)
|
|
470
|
+
assert_result(False, False)
|
|
471
|
+
|
|
472
|
+
# enable optimize locally, still disabled globally
|
|
473
|
+
pod_template.column_modifier = 'optimize'
|
|
474
|
+
set_text(text)
|
|
475
|
+
assert_result(True, False)
|
|
476
|
+
set_text(textNone)
|
|
477
|
+
assert_result(False, False)
|
|
478
|
+
set_text(textAuto)
|
|
479
|
+
assert_result(True, False)
|
|
480
|
+
set_text(textFixed)
|
|
481
|
+
assert_result(False, True)
|
|
482
|
+
|
|
483
|
+
# enable distribute locally, still disabled globally
|
|
484
|
+
pod_template.column_modifier = 'distribute'
|
|
485
|
+
set_text(text)
|
|
486
|
+
assert_result(False, True)
|
|
487
|
+
set_text(textNone)
|
|
488
|
+
assert_result(False, False)
|
|
489
|
+
set_text(textAuto)
|
|
490
|
+
assert_result(True, False)
|
|
491
|
+
set_text(textFixed)
|
|
492
|
+
assert_result(False, True)
|
|
493
|
+
|
|
494
|
+
# reset local parameter
|
|
495
|
+
pod_template.column_modifier = -1
|
|
496
|
+
|
|
497
|
+
# CSS override enabled
|
|
498
|
+
set_column_modifier('nothing')
|
|
499
|
+
set_text(text)
|
|
500
|
+
assert_result(False, False)
|
|
501
|
+
set_text(textNone)
|
|
502
|
+
assert_result(False, False)
|
|
503
|
+
set_text(textAuto)
|
|
504
|
+
assert_result(True, False)
|
|
505
|
+
set_text(textFixed)
|
|
506
|
+
assert_result(False, True)
|
|
507
|
+
|
|
508
|
+
# disable all column modifier globally
|
|
509
|
+
set_column_modifier('disabled')
|
|
510
|
+
set_text(text)
|
|
511
|
+
assert_result(False, False)
|
|
512
|
+
set_text(textNone)
|
|
513
|
+
assert_result(False, False)
|
|
514
|
+
set_text(textAuto)
|
|
515
|
+
assert_result(False, False)
|
|
516
|
+
set_text(textFixed)
|
|
517
|
+
assert_result(False, False)
|
|
518
|
+
|
|
519
|
+
# optimize column_modifier enabled globally and pod_template using global parameter
|
|
520
|
+
set_column_modifier('optimize')
|
|
521
|
+
set_text(text)
|
|
522
|
+
assert_result(True, False)
|
|
523
|
+
set_text(textNone)
|
|
524
|
+
assert_result(False, False)
|
|
525
|
+
set_text(textAuto)
|
|
526
|
+
assert_result(True, False)
|
|
527
|
+
set_text(textFixed)
|
|
528
|
+
assert_result(False, True)
|
|
529
|
+
|
|
530
|
+
# distribute column_modifier enabled globally and pod_template using global parameter
|
|
531
|
+
set_column_modifier('distribute')
|
|
532
|
+
set_text(text)
|
|
533
|
+
assert_result(False, True)
|
|
534
|
+
set_text(textNone)
|
|
535
|
+
assert_result(False, False)
|
|
536
|
+
set_text(textAuto)
|
|
537
|
+
assert_result(True, False)
|
|
538
|
+
set_text(textFixed)
|
|
539
|
+
assert_result(False, True)
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
class TestCyclicMergesDetection(unittest.TestCase):
|
|
543
|
+
"""
|
|
544
|
+
"""
|
|
545
|
+
|
|
546
|
+
layer = POD_TEMPLATE_INTEGRATION
|
|
547
|
+
|
|
548
|
+
def setUp(self):
|
|
549
|
+
super(TestCyclicMergesDetection, self).setUp()
|
|
550
|
+
|
|
551
|
+
portal = api.portal.get()
|
|
552
|
+
self.generation_view = portal.restrictedTraverse('@@document-generation')
|
|
553
|
+
|
|
554
|
+
self.template_a = api.content.create(
|
|
555
|
+
type='ConfigurablePODTemplate',
|
|
556
|
+
id='template_a',
|
|
557
|
+
title='Modèle A',
|
|
558
|
+
container=portal.podtemplates,
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
self.template_b = api.content.create(
|
|
562
|
+
type='ConfigurablePODTemplate',
|
|
563
|
+
id='template_b',
|
|
564
|
+
title='Modèle B',
|
|
565
|
+
container=portal.podtemplates,
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
self.template_c = api.content.create(
|
|
569
|
+
type='ConfigurablePODTemplate',
|
|
570
|
+
id='template_c',
|
|
571
|
+
title='Modèle C',
|
|
572
|
+
container=portal.podtemplates,
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
self.template_d = api.content.create(
|
|
576
|
+
type='ConfigurablePODTemplate',
|
|
577
|
+
id='template_d',
|
|
578
|
+
title='Modèle D',
|
|
579
|
+
container=portal.podtemplates,
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
def _test_detect_cycle(self, template, should_raise, msg=''):
|
|
583
|
+
exception_raised = False
|
|
584
|
+
try:
|
|
585
|
+
self.generation_view._check_cyclic_merges(template)
|
|
586
|
+
except CyclicMergeTemplatesException:
|
|
587
|
+
exception_raised = True
|
|
588
|
+
|
|
589
|
+
self.assertTrue(exception_raised == should_raise, msg)
|
|
590
|
+
|
|
591
|
+
def test_detect_cycle_when_no_merge(self):
|
|
592
|
+
template = self.template_a
|
|
593
|
+
self.assertTrue(template.merge_templates == [])
|
|
594
|
+
|
|
595
|
+
msg = 'Cyclic merge detection should not raise anything when no subtemplates to merge.'
|
|
596
|
+
self._test_detect_cycle(template, should_raise=False, msg=msg)
|
|
597
|
+
|
|
598
|
+
def test_detect_cycle_on_linear_merge(self):
|
|
599
|
+
template_a = self.template_a
|
|
600
|
+
template_b = self.template_b
|
|
601
|
+
template_c = self.template_c
|
|
602
|
+
# set a chain such as template_a -> template_b -> template_c
|
|
603
|
+
template_a.set_merge_templates(template_b, 'pod_b')
|
|
604
|
+
template_b.set_merge_templates(template_c, 'pod_c')
|
|
605
|
+
|
|
606
|
+
msg = 'Cyclic merge detection should not raise anything when import chain is not cyclic.'
|
|
607
|
+
self._test_detect_cycle(template_a, should_raise=False, msg=msg)
|
|
608
|
+
|
|
609
|
+
def test_detect_cycle_on_linear_merge_with_duplicates(self):
|
|
610
|
+
template_a = self.template_a
|
|
611
|
+
template_b = self.template_b
|
|
612
|
+
template_c = self.template_c
|
|
613
|
+
# set a chain such as template_a -> template_b -> template_c
|
|
614
|
+
# \_> template c
|
|
615
|
+
template_a.set_merge_templates(template_b, 'pod_b')
|
|
616
|
+
template_a.set_merge_templates(template_c, 'pod_c')
|
|
617
|
+
template_b.set_merge_templates(template_c, 'pod_c')
|
|
618
|
+
|
|
619
|
+
msg = 'Cyclic merge detection should not raise anything when import chain is not cyclic.'
|
|
620
|
+
self._test_detect_cycle(template_a, should_raise=False, msg=msg)
|
|
621
|
+
|
|
622
|
+
def test_detect_cycle_on_self_reference(self):
|
|
623
|
+
template = self.template_a
|
|
624
|
+
# import a configurable template on itself
|
|
625
|
+
template.set_merge_templates(template, 'a')
|
|
626
|
+
|
|
627
|
+
msg = 'Cyclic merge detection should raise Exception when a template tries to import itself.'
|
|
628
|
+
self._test_detect_cycle(template, should_raise=True, msg=msg)
|
|
629
|
+
|
|
630
|
+
def test_detect_cycle_on_simple_cycle(self):
|
|
631
|
+
template_a = self.template_a
|
|
632
|
+
template_b = self.template_b
|
|
633
|
+
template_c = self.template_c
|
|
634
|
+
# set a cyclic chain such as (template_a -> template_b -> template_c -> template_a)
|
|
635
|
+
template_a.set_merge_templates(template_b, 'pod_b')
|
|
636
|
+
template_b.set_merge_templates(template_c, 'pod_c')
|
|
637
|
+
template_c.set_merge_templates(template_a, 'pod_a')
|
|
638
|
+
|
|
639
|
+
msg = 'Cyclic merge detection should raise Exception with cycle a -> b -> c -> a .'
|
|
640
|
+
self._test_detect_cycle(template_a, should_raise=True, msg=msg)
|
|
641
|
+
|
|
642
|
+
def test_detect_cycle_on_inner_cycle(self):
|
|
643
|
+
template_a = self.template_a
|
|
644
|
+
template_b = self.template_b
|
|
645
|
+
template_c = self.template_c
|
|
646
|
+
# set a an inner cyclic chain such as template_a -> (template_b -> template_c -> template_b)
|
|
647
|
+
template_a.set_merge_templates(template_b, 'pod_b')
|
|
648
|
+
template_b.set_merge_templates(template_c, 'pod_c')
|
|
649
|
+
template_c.set_merge_templates(template_b, 'pod_b')
|
|
650
|
+
|
|
651
|
+
msg = 'Cyclic merge detection should raise Exception with cycle b -> c -> b .'
|
|
652
|
+
self._test_detect_cycle(template_a, should_raise=True, msg=msg)
|
|
Binary file
|