• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Products.CMFCore / 6246931310

20 Sep 2023 09:54AM UTC coverage: 86.008% (-0.3%) from 86.266%
6246931310

Pull #131

github

mauritsvanrees
gha: don't need setup-python on 27 as we use the 27 container.
Pull Request #131: Make decodeFolderFilter and encodeFolderFilter non-public.

2466 of 3689 branches covered (0.0%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

17297 of 19289 relevant lines covered (89.67%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.87
/src/Products/CMFCore/exportimport/tests/test_content.py
1
##############################################################################
2
#
3
# Copyright (c) 2005 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE.
11
#
12
##############################################################################
13
"""Filesystem exporter / importer adapter unit tests.
1✔
14
"""
15

16
import unittest
1✔
17
from csv import reader
1✔
18

19
from six import StringIO
1✔
20
from six import binary_type
1✔
21
from six.moves.configparser import ConfigParser
1✔
22

23
from zope.component import getSiteManager
1✔
24
from zope.testing.cleanup import cleanUp
1✔
25

26
from Products.GenericSetup.tests.common import DummyExportContext
1✔
27
from Products.GenericSetup.tests.common import DummyImportContext
1✔
28

29
from ...interfaces import ITypesTool
1✔
30
from ...testing import DummyWorkflow
1✔
31
from .test_workflow import DummyWorkflowTool
1✔
32

33

34
def safe_bytes(value, encoding='utf8'):
1✔
35
    if isinstance(value, binary_type):
1!
36
        return value
×
37
    return value.encode(encoding)
1✔
38

39

40
class SiteStructureExporterTests(unittest.TestCase):
1✔
41

42
    def _getExporter(self):
1✔
43
        from ..content import exportSiteStructure
1✔
44
        return exportSiteStructure
1✔
45

46
    def _getImporter(self):
1✔
47
        from ..content import importSiteStructure
1✔
48
        return importSiteStructure
1✔
49

50
    def _makeSetupTool(self):
1✔
51
        from Products.GenericSetup.tool import SetupTool
1✔
52
        return SetupTool('portal_setup')
1✔
53

54
    def _makeWorkflowTool(self):
1✔
55
        obj = DummyWorkflowTool()
1✔
56
        return obj
1✔
57

58
    def _setUpAdapters(self):
1✔
59
        from zope.component import provideAdapter
1✔
60

61
        from Products.GenericSetup.content import CSVAwareFileAdapter
1✔
62
        from Products.GenericSetup.content import INIAwareFileAdapter
1✔
63
        from Products.GenericSetup.interfaces import ICSVAware
1✔
64
        from Products.GenericSetup.interfaces import IFilesystemExporter
1✔
65
        from Products.GenericSetup.interfaces import IFilesystemImporter
1✔
66
        from Products.GenericSetup.interfaces import IINIAware
1✔
67

68
        from ...interfaces import IFolderish
1✔
69
        from ..content import StructureFolderWalkingAdapter
1✔
70

71
        provideAdapter(StructureFolderWalkingAdapter,
1✔
72
                       (IFolderish,),
73
                       IFilesystemExporter)
74

75
        provideAdapter(StructureFolderWalkingAdapter,
1✔
76
                       (IFolderish,),
77
                       IFilesystemImporter)
78

79
        provideAdapter(CSVAwareFileAdapter,
1✔
80
                       (ICSVAware,),
81
                       IFilesystemExporter)
82

83
        provideAdapter(CSVAwareFileAdapter,
1✔
84
                       (ICSVAware,),
85
                       IFilesystemImporter)
86

87
        provideAdapter(INIAwareFileAdapter,
1✔
88
                       (IINIAware,),
89
                       IFilesystemExporter)
90

91
        provideAdapter(INIAwareFileAdapter,
1✔
92
                       (IINIAware,),
93
                       IFilesystemImporter)
94

95
    def _get_config_parser(self, text):
1✔
96
        parser = ConfigParser()
1✔
97
        try:
1✔
98
            parser.read_file(StringIO(text))
1✔
99
        except AttributeError:  # Python 2
×
100
            parser.readfp(StringIO(text))
×
101
        return parser
1✔
102

103
    def tearDown(self):
1✔
104
        cleanUp()
1✔
105

106
    def test_export_empty_site(self):
1✔
107
        self._setUpAdapters()
1✔
108
        site = _makeFolder('site', site_folder=True)
1✔
109
        site.title = 'test_export_empty_site'
1✔
110
        site.description = 'Testing export of an empty site.'
1✔
111
        context = DummyExportContext(site)
1✔
112
        exporter = self._getExporter()
1✔
113
        exporter(context)
1✔
114

115
        self.assertEqual(len(context._wrote), 2)
1✔
116
        filename, text, content_type = context._wrote[0]
1✔
117
        self.assertEqual(filename, 'structure/.objects')
1✔
118
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
119

120
        objects = [x for x in reader(StringIO(text))]
1✔
121
        self.assertEqual(len(objects), 0)
1✔
122

123
        filename, text, content_type = context._wrote[1]
1✔
124
        self.assertEqual(filename, 'structure/.properties')
1✔
125
        self.assertEqual(content_type, 'text/plain')
1✔
126

127
        parser = self._get_config_parser(text)
1✔
128

129
        self.assertEqual(parser.get('DEFAULT', 'Title'),
1✔
130
                         site.title)
131
        self.assertEqual(parser.get('DEFAULT', 'Description'),
1✔
132
                         site.description)
133

134
    def test_export_empty_site_with_setup_tool(self):
1✔
135
        self._setUpAdapters()
1✔
136
        site = _makeFolder('site', site_folder=True)
1✔
137
        site._setObject('setup_tool', self._makeSetupTool())
1✔
138
        site.title = 'test_export_empty_site_with_setup_tool'
1✔
139
        site.description = 'Testing export of an empty site with setup tool.'
1✔
140
        context = DummyExportContext(site)
1✔
141
        exporter = self._getExporter()
1✔
142
        exporter(context)
1✔
143

144
        self.assertEqual(len(context._wrote), 2)
1✔
145
        filename, text, content_type = context._wrote[0]
1✔
146
        self.assertEqual(filename, 'structure/.objects')
1✔
147
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
148

149
        objects = [x for x in reader(StringIO(text))]
1✔
150
        self.assertEqual(len(objects), 0)
1✔
151

152
        filename, text, content_type = context._wrote[1]
1✔
153
        self.assertEqual(filename, 'structure/.properties')
1✔
154
        self.assertEqual(content_type, 'text/plain')
1✔
155

156
        parser = self._get_config_parser(text)
1✔
157

158
        self.assertEqual(parser.get('DEFAULT', 'Title'),
1✔
159
                         site.title)
160
        self.assertEqual(parser.get('DEFAULT', 'Description'),
1✔
161
                         site.description)
162

163
    def test_export_site_with_non_exportable_simple_items(self):
1✔
164
        self._setUpAdapters()
1✔
165
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
166

167
        site = _makeFolder('site', site_folder=True)
1✔
168
        site.title = 'AAA'
1✔
169
        site.description = 'DESCRIPTION'
1✔
170
        for id in ITEM_IDS:
1✔
171
            site._setObject(id, _makeItem(id))
1✔
172

173
        context = DummyExportContext(site)
1✔
174
        exporter = self._getExporter()
1✔
175
        exporter(context)
1✔
176

177
        self.assertEqual(len(context._wrote), 2)
1✔
178
        filename, text, content_type = context._wrote[0]
1✔
179
        self.assertEqual(filename, 'structure/.objects')
1✔
180
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
181

182
        objects = [x for x in reader(StringIO(text))]
1✔
183
        self.assertEqual(len(objects), 3)
1✔
184
        for index in range(len(ITEM_IDS)):
1✔
185
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
186
            self.assertEqual(objects[index][1], TEST_CONTENT)
1✔
187

188
        filename, text, content_type = context._wrote[1]
1✔
189
        self.assertEqual(filename, 'structure/.properties')
1✔
190
        self.assertEqual(content_type, 'text/plain')
1✔
191
        parser = self._get_config_parser(text)
1✔
192

193
        self.assertEqual(parser.get('DEFAULT', 'title'), 'AAA')
1✔
194
        self.assertEqual(parser.get('DEFAULT', 'description'), 'DESCRIPTION')
1✔
195

196
    def test_export_site_with_exportable_simple_items_encoded_string(self):
1✔
197
        self._setUpAdapters()
1✔
198
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
199

200
        site = _makeFolder('site', site_folder=True)
1✔
201
        site.title = 'AAA'
1✔
202
        site.description = 'DESCRIPTION'
1✔
203
        ITEMS_TITLE = u'Actualit\xe9'
1✔
204
        ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes'
1✔
205
        for id in ITEM_IDS:
1✔
206
            site._setObject(id, _makeINIAware(id))
1✔
207
            item = getattr(site, id)
1✔
208
            item.setTitle(ITEMS_TITLE.encode('utf8'))
1✔
209
            item.setDescription(ITEMS_DESCRIPTION.encode('utf8'))
1✔
210

211
        context = DummyExportContext(site)
1✔
212
        exporter = self._getExporter()
1✔
213
        exporter(context)
1✔
214

215
        self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
1✔
216
        filename, text, content_type = context._wrote[0]
1✔
217
        self.assertEqual(filename, 'structure/.objects')
1✔
218
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
219

220
        objects = [x for x in reader(StringIO(text))]
1✔
221
        self.assertEqual(len(objects), 3)
1✔
222
        for index in range(len(ITEM_IDS)):
1✔
223
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
224
            self.assertEqual(objects[index][1], TEST_INI_AWARE)
1✔
225

226
            filename, text, content_type = context._wrote[index + 2]
1✔
227
            self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
1✔
228
            object = site._getOb(ITEM_IDS[index])
1✔
229
            self.assertEqual(text.strip(),
1✔
230
                             object.as_ini().strip())
231
            self.assertEqual(content_type, 'text/plain')
1✔
232

233
        filename, text, content_type = context._wrote[1]
1✔
234
        self.assertEqual(filename, 'structure/.properties')
1✔
235
        self.assertEqual(content_type, 'text/plain')
1✔
236
        parser = self._get_config_parser(text)
1✔
237

238
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'title')),
1✔
239
                         ITEMS_TITLE.encode('utf8'))
240
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'description')),
1✔
241
                         ITEMS_DESCRIPTION.encode('utf8'))
242

243
    def test_export_site_with_exportable_simple_items(self):
1✔
244
        self._setUpAdapters()
1✔
245
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
246

247
        site = _makeFolder('site', site_folder=True)
1✔
248
        site.title = 'AAA'
1✔
249
        site.description = 'DESCRIPTION'
1✔
250
        for id in ITEM_IDS:
1✔
251
            site._setObject(id, _makeINIAware(id))
1✔
252

253
        context = DummyExportContext(site)
1✔
254
        exporter = self._getExporter()
1✔
255
        exporter(context)
1✔
256

257
        self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
1✔
258
        filename, text, content_type = context._wrote[0]
1✔
259
        self.assertEqual(filename, 'structure/.objects')
1✔
260
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
261

262
        objects = [x for x in reader(StringIO(text))]
1✔
263
        self.assertEqual(len(objects), 3)
1✔
264
        for index in range(len(ITEM_IDS)):
1✔
265
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
266
            self.assertEqual(objects[index][1], TEST_INI_AWARE)
1✔
267

268
            filename, text, content_type = context._wrote[index + 2]
1✔
269
            self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
1✔
270
            object = site._getOb(ITEM_IDS[index])
1✔
271
            self.assertEqual(text.strip(),
1✔
272
                             object.as_ini().strip())
273
            self.assertEqual(content_type, 'text/plain')
1✔
274

275
        filename, text, content_type = context._wrote[1]
1✔
276
        self.assertEqual(filename, 'structure/.properties')
1✔
277
        self.assertEqual(content_type, 'text/plain')
1✔
278
        parser = self._get_config_parser(text)
1✔
279

280
        self.assertEqual(parser.get('DEFAULT', 'title'), 'AAA')
1✔
281
        self.assertEqual(parser.get('DEFAULT', 'description'), 'DESCRIPTION')
1✔
282

283
    def test_export_site_includes_workflow(self):
1✔
284
        self._setUpAdapters()
1✔
285
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
286

287
        site = _makeFolder('site', site_folder=True)
1✔
288

289
        site._setObject('portal_workflow', self._makeWorkflowTool())
1✔
290
        wftool = site.portal_workflow
1✔
291
        wftool._setObject('foo_workflow', DummyWorkflow('foo_workflow'))
1✔
292
        wftool.foo_workflow.state_var = 'state'
1✔
293
        wftool.setDefaultChain('foo_workflow')
1✔
294
        wftool.setChainForPortalTypes((TEST_INI_AWARE,),
1✔
295
                                      'foo_workflow', verify=False)
296

297
        site.title = 'AAA'
1✔
298
        site.description = 'DESCRIPTION'
1✔
299
        for id in ITEM_IDS:
1✔
300
            site._setObject(id, _makeINIAware(id))
1✔
301
            wftool.setStatusOf('foo_workflow', site[id],
1✔
302
                               {'state': 'published'})
303

304
        context = DummyExportContext(site)
1✔
305
        exporter = self._getExporter()
1✔
306
        exporter(context)
1✔
307

308
        self.assertEqual(len(context._wrote), 3 + len(ITEM_IDS))
1✔
309
        filename, text, content_type = context._wrote[0]
1✔
310
        self.assertEqual(filename, 'structure/.workflow_states')
1✔
311
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
312

313
        objects = [x for x in reader(StringIO(text))]
1✔
314
        self.assertEqual(len(objects), 3)
1✔
315
        for index in range(len(ITEM_IDS)):
1✔
316
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
317
            self.assertEqual(objects[index][1], 'foo_workflow')
1✔
318
            self.assertEqual(objects[index][2], 'published')
1✔
319

320
    def test_export_site_exportable_simple_items_unicode_default_charset(self):
1✔
321
        self._setUpAdapters()
1✔
322
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
323

324
        site = _makeFolder('site', site_folder=True)
1✔
325
        site.title = 'AAA'
1✔
326
        site.description = 'DESCRIPTION'
1✔
327
        ITEMS_TITLE = u'Actualit\xe9'
1✔
328
        ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes'
1✔
329
        for id in ITEM_IDS:
1✔
330
            site._setObject(id, _makeINIAware(id))
1✔
331
            item = getattr(site, id)
1✔
332
            item.setTitle(ITEMS_TITLE)
1✔
333
            item.setDescription(ITEMS_DESCRIPTION)
1✔
334

335
        context = DummyExportContext(site)
1✔
336
        exporter = self._getExporter()
1✔
337
        exporter(context)
1✔
338

339
        self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
1✔
340
        filename, text, content_type = context._wrote[0]
1✔
341
        self.assertEqual(filename, 'structure/.objects')
1✔
342
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
343

344
        objects = [x for x in reader(StringIO(text))]
1✔
345
        self.assertEqual(len(objects), 3)
1✔
346
        for index in range(len(ITEM_IDS)):
1✔
347
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
348
            self.assertEqual(objects[index][1], TEST_INI_AWARE)
1✔
349

350
            filename, text, content_type = context._wrote[index + 2]
1✔
351
            self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
1✔
352
            object = site._getOb(ITEM_IDS[index])
1✔
353
            self.assertEqual(text.strip(),
1✔
354
                             object.as_ini().strip())
355
            self.assertEqual(content_type, 'text/plain')
1✔
356

357
        filename, text, content_type = context._wrote[1]
1✔
358
        self.assertEqual(filename, 'structure/.properties')
1✔
359
        self.assertEqual(content_type, 'text/plain')
1✔
360
        parser = self._get_config_parser(text)
1✔
361

362
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'title')),
1✔
363
                         ITEMS_TITLE.encode('utf8'))
364
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'description')),
1✔
365
                         ITEMS_DESCRIPTION.encode('utf8'))
366

367
    def test_export_site_with_exportable_simple_items_unicode_latin1(self):
1✔
368
        self._setUpAdapters()
1✔
369
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
370

371
        site = _makeFolder('site', site_folder=True)
1✔
372
        site._setProperty('default_charset', 'iso-8859-1', 'string')
1✔
373
        site.title = 'AAA'
1✔
374
        site.description = 'DESCRIPTION'
1✔
375
        ITEMS_TITLE = u'Actualit\xe9'
1✔
376
        ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes'
1✔
377
        for id in ITEM_IDS:
1✔
378
            site._setObject(id, _makeINIAware(id))
1✔
379
            item = getattr(site, id)
1✔
380
            item.setTitle(ITEMS_TITLE)
1✔
381
            item.setDescription(ITEMS_DESCRIPTION)
1✔
382

383
        context = DummyExportContext(site)
1✔
384
        exporter = self._getExporter()
1✔
385
        exporter(context)
1✔
386

387
        self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
1✔
388
        filename, text, content_type = context._wrote[0]
1✔
389
        self.assertEqual(filename, 'structure/.objects')
1✔
390
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
391

392
        objects = [x for x in reader(StringIO(text))]
1✔
393
        self.assertEqual(len(objects), 3)
1✔
394
        for index in range(len(ITEM_IDS)):
1✔
395
            self.assertEqual(objects[index][0], ITEM_IDS[index])
1✔
396
            self.assertEqual(objects[index][1], TEST_INI_AWARE)
1✔
397

398
            filename, text, content_type = context._wrote[index + 2]
1✔
399
            self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
1✔
400
            object = site._getOb(ITEM_IDS[index])
1✔
401
            self.assertEqual(text.strip(),
1✔
402
                             object.as_ini().strip())
403
            self.assertEqual(content_type, 'text/plain')
1✔
404

405
        filename, text, content_type = context._wrote[1]
1✔
406
        self.assertEqual(filename, 'structure/.properties')
1✔
407
        self.assertEqual(content_type, 'text/plain')
1✔
408
        parser = self._get_config_parser(text)
1✔
409

410
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'title'), 'latin1'),
1✔
411
                         ITEMS_TITLE.encode('latin1'))
412
        self.assertEqual(safe_bytes(parser.get('DEFAULT', 'description'),
1✔
413
                                    'latin1'),
414
                         ITEMS_DESCRIPTION.encode('latin1'))
415

416
    def test_export_site_with_subfolders(self):
1✔
417
        self._setUpAdapters()
1✔
418
        FOLDER_IDS = ('foo', 'bar', 'baz')
1✔
419

420
        site = _makeFolder('site', site_folder=True)
1✔
421
        site.title = 'AAA'
1✔
422
        site.description = 'DESCRIPTION'
1✔
423
        for id in FOLDER_IDS:
1✔
424
            folder = _makeFolder(id)
1✔
425
            folder.title = 'Title: %s' % id
1✔
426
            folder.description = 'xyzzy'
1✔
427
            site._setObject(id, folder)
1✔
428

429
        context = DummyExportContext(site)
1✔
430
        exporter = self._getExporter()
1✔
431
        exporter(context)
1✔
432

433
        self.assertEqual(len(context._wrote), 2 + (2 * len(FOLDER_IDS)))
1✔
434
        filename, text, content_type = context._wrote[0]
1✔
435
        self.assertEqual(filename, 'structure/.objects')
1✔
436
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
437

438
        objects = [x for x in reader(StringIO(text))]
1✔
439
        self.assertEqual(len(objects), 3)
1✔
440

441
        for index in range(len(FOLDER_IDS)):
1✔
442
            id = FOLDER_IDS[index]
1✔
443
            self.assertEqual(objects[index][0], id)
1✔
444
            self.assertEqual(objects[index][1], TEST_FOLDER)
1✔
445

446
            filename, text, content_type = context._wrote[2 + (2 * index)]
1✔
447
            self.assertEqual(filename, '/'.join(('structure', id, '.objects')))
1✔
448
            self.assertEqual(content_type, 'text/comma-separated-values')
1✔
449
            subobjects = [x for x in reader(StringIO(text))]
1✔
450
            self.assertEqual(len(subobjects), 0)
1✔
451

452
            filename, text, content_type = context._wrote[2 + (2 * index) + 1]
1✔
453
            self.assertEqual(filename,
1✔
454
                             '/'.join(('structure', id, '.properties')))
455
            self.assertEqual(content_type, 'text/plain')
1✔
456
            parser = self._get_config_parser(text)
1✔
457

458
            self.assertEqual(parser.get('DEFAULT', 'Title'), 'Title: %s' % id)
1✔
459

460
        filename, text, content_type = context._wrote[1]
1✔
461
        self.assertEqual(filename, 'structure/.properties')
1✔
462
        self.assertEqual(content_type, 'text/plain')
1✔
463

464
        parser = self._get_config_parser(text)
1✔
465

466
        self.assertEqual(parser.get('DEFAULT', 'title'), 'AAA')
1✔
467
        self.assertEqual(parser.get('DEFAULT', 'description'), 'DESCRIPTION')
1✔
468

469
    def test_export_site_with_dav_aware_folder(self):
1✔
470
        self._setUpAdapters()
1✔
471

472
        site = _makeFolder('site', site_folder=True)
1✔
473
        site.title = 'AAA'
1✔
474
        site.description = 'DESCRIPTION'
1✔
475

476
        folder = _makeDAVAwareFolder('foo')
1✔
477
        folder.title = 'foo'
1✔
478
        folder.description = 'xyzzy'
1✔
479
        folder.body = 'A content item'
1✔
480
        site._setObject('foo', folder)
1✔
481

482
        context = DummyExportContext(site)
1✔
483
        exporter = self._getExporter()
1✔
484
        exporter(context)
1✔
485

486
        filename, text, content_type = context._wrote[-1]
1✔
487
        self.assertEqual(filename, 'structure/foo/.properties')
1✔
488
        self.assertEqual(content_type, 'text/plain')
1✔
489
        self.assertEqual(text,
1✔
490
                         KNOWN_DAV % (folder.title, folder.description,
491
                                      folder.body))
492

493
    def test_export_site_with_csvaware(self):
1✔
494
        self._setUpAdapters()
1✔
495

496
        site = _makeFolder('site', site_folder=True)
1✔
497
        site.title = 'test_export_site_with_csvaware'
1✔
498
        site.description = 'Testing export of an site with CSV-aware content.'
1✔
499

500
        site._setObject('aware', _makeCSVAware('aware'))
1✔
501

502
        context = DummyExportContext(site)
1✔
503
        exporter = self._getExporter()
1✔
504
        exporter(context)
1✔
505

506
        self.assertEqual(len(context._wrote), 3)
1✔
507
        filename, text, content_type = context._wrote[0]
1✔
508
        self.assertEqual(filename, 'structure/.objects')
1✔
509
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
510

511
        objects = [x for x in reader(StringIO(text))]
1✔
512
        self.assertEqual(len(objects), 1)
1✔
513
        self.assertEqual(objects[0][0], 'aware')
1✔
514
        self.assertEqual(objects[0][1], TEST_CSV_AWARE)
1✔
515

516
        filename, text, content_type = context._wrote[1]
1✔
517
        self.assertEqual(filename, 'structure/.properties')
1✔
518
        self.assertEqual(content_type, 'text/plain')
1✔
519

520
        parser = self._get_config_parser(text)
1✔
521

522
        self.assertEqual(parser.get('DEFAULT', 'Title'), site.title)
1✔
523
        self.assertEqual(parser.get('DEFAULT', 'Description'),
1✔
524
                         site.description)
525

526
        filename, text, content_type = context._wrote[2]
1✔
527
        self.assertEqual(filename, 'structure/aware.csv')
1✔
528
        self.assertEqual(content_type, 'text/comma-separated-values')
1✔
529
        rows = [x for x in reader(StringIO(text))]
1✔
530
        self.assertEqual(len(rows), 2)
1✔
531
        self.assertEqual(rows[0][0], 'one')
1✔
532
        self.assertEqual(rows[0][1], 'two')
1✔
533
        self.assertEqual(rows[0][2], 'three')
1✔
534
        self.assertEqual(rows[1][0], 'four')
1✔
535
        self.assertEqual(rows[1][1], 'five')
1✔
536
        self.assertEqual(rows[1][2], 'six')
1✔
537

538
    def test_import_empty_site(self):
1✔
539
        self._setUpAdapters()
1✔
540
        site = _makeFolder('site', site_folder=True)
1✔
541
        context = DummyImportContext(site)
1✔
542
        context._files['structure/.objects'] = ''
1✔
543
        importer = self._getImporter()
1✔
544
        self.assertEqual(len(site.objectIds()), 0)
1✔
545
        importer(context)
1✔
546
        self.assertEqual(len(site.objectIds()), 0)
1✔
547

548
    def test_import_empty_site_with_setup_tool(self):
1✔
549
        self._setUpAdapters()
1✔
550
        site = _makeFolder('site', site_folder=True)
1✔
551
        site._setObject('setup_tool', self._makeSetupTool())
1✔
552
        context = DummyImportContext(site)
1✔
553
        importer = self._getImporter()
1✔
554

555
        self.assertEqual(len(site.objectIds()), 1)
1✔
556
        self.assertEqual(site.objectIds()[0], 'setup_tool')
1✔
557
        importer(context)
1✔
558
        self.assertEqual(len(site.objectIds()), 1)
1✔
559
        self.assertEqual(site.objectIds()[0], 'setup_tool')
1✔
560

561
    def test_import_site_with_subfolders(self):
1✔
562
        from Products.GenericSetup.tests.test_content import \
1✔
563
            _PROPERTIES_TEMPLATE
564
        self._setUpAdapters()
1✔
565
        FOLDER_IDS = ('foo', 'bar', 'baz')
1✔
566

567
        site = _makeFolder('site', site_folder=True)
1✔
568

569
        context = DummyImportContext(site)
1✔
570

571
        for id in FOLDER_IDS:
1✔
572
            context._files['structure/%s/.objects' % id] = ''
1✔
573
            context._files['structure/%s/.properties' % id] = (
1✔
574
                _PROPERTIES_TEMPLATE % id)
575

576
        _ROOT_OBJECTS = '\n'.join(['%s,%s' % (id, TEST_FOLDER)
1✔
577
                                   for id in FOLDER_IDS])
578

579
        context._files['structure/.objects'] = _ROOT_OBJECTS
1✔
580
        context._files['structure/.properties'] = (
1✔
581
                _PROPERTIES_TEMPLATE % 'Test Site')
582

583
        importer = self._getImporter()
1✔
584
        importer(context)
1✔
585

586
        content = site.contentValues()
1✔
587
        self.assertEqual(len(content), len(FOLDER_IDS))
1✔
588

589
    def test_import_site_with_dav_aware_folder(self):
1✔
590
        from Products.GenericSetup.tests.test_content import \
1✔
591
            _PROPERTIES_TEMPLATE
592
        self._setUpAdapters()
1✔
593
        FOLDER_IDS = ('foo', 'bar', 'baz')
1✔
594

595
        site = _makeFolder('site', site_folder=True)
1✔
596

597
        context = DummyImportContext(site)
1✔
598

599
        for id in FOLDER_IDS:
1✔
600
            context._files['structure/%s/.objects' % id] = ''
1✔
601
            context._files['structure/%s/.properties' % id] = (
1✔
602
                KNOWN_DAV % ('Title', 'Description', 'Body'))
603

604
        _ROOT_OBJECTS = '\n'.join(['%s,%s' % (id, TEST_DAV_FOLDER)
1✔
605
                                  for id in FOLDER_IDS])
606

607
        context._files['structure/.objects'] = _ROOT_OBJECTS
1✔
608
        context._files['structure/.properties'] = (
1✔
609
                _PROPERTIES_TEMPLATE % 'Test Site')
610

611
        importer = self._getImporter()
1✔
612
        importer(context)
1✔
613
        content = site.contentValues()
1✔
614
        self.assertEqual(len(content), len(FOLDER_IDS))
1✔
615
        self.assertEqual(
1✔
616
            content[0]._was_put_as_read,
617
            (KNOWN_DAV % ('Title', 'Description', 'Body')).encode('UTF-8'))
618

619
    def test_import_site_with_dav_aware_folder_with_generic_file_data(self):
1✔
620
        from Products.GenericSetup.tests.test_content import \
1✔
621
            _PROPERTIES_TEMPLATE
622
        self._setUpAdapters()
1✔
623
        FOLDER_IDS = ('foo', 'bar', 'baz')
1✔
624

625
        site = _makeFolder('site', site_folder=True)
1✔
626

627
        context = DummyImportContext(site)
1✔
628

629
        for id in FOLDER_IDS:
1✔
630
            context._files['structure/%s/.objects' % id] = ''
1✔
631
            context._files['structure/%s/.properties' % id] = (
1✔
632
                _PROPERTIES_TEMPLATE % ('Sub Folder Title',))
633

634
        _ROOT_OBJECTS = '\n'.join(['%s,%s' % (id, TEST_DAV_FOLDER)
1✔
635
                                   for id in FOLDER_IDS])
636

637
        context._files['structure/.objects'] = _ROOT_OBJECTS
1✔
638
        context._files['structure/.properties'] = (
1✔
639
                _PROPERTIES_TEMPLATE % 'Test Site')
640

641
        importer = self._getImporter()
1✔
642
        importer(context)
1✔
643
        content = site.contentValues()
1✔
644
        self.assertEqual(len(content), len(FOLDER_IDS))
1✔
645
        self.assertEqual(content[0].title, 'Sub Folder Title')
1✔
646

647
    def test_import_site_with_subitems(self):
1✔
648
        self._setUpAdapters()
1✔
649
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
650

651
        site = _makeFolder('site', site_folder=True)
1✔
652

653
        context = DummyImportContext(site)
1✔
654
        # We want to add 'baz' to 'foo', without losing 'bar'
655
        context._files['structure/.objects'] = '\n'.join(
1✔
656
                            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
657
        for index in range(len(ITEM_IDS)):
1✔
658
            id = ITEM_IDS[index]
1✔
659
            context._files[
1✔
660
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
661
                                                            'xyzzy')
662
        importer = self._getImporter()
1✔
663
        importer(context)
1✔
664

665
        after = site.objectIds()
1✔
666
        self.assertEqual(len(after), len(ITEM_IDS))
1✔
667
        for found_id, expected_id in zip(after, ITEM_IDS):
1✔
668
            self.assertEqual(found_id, expected_id)
1✔
669

670
    def test_import_site_includes_workflow(self):
1✔
671
        self._setUpAdapters()
1✔
672
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
673

674
        site = _makeFolder('site', site_folder=True)
1✔
675

676
        site._setObject('portal_workflow', self._makeWorkflowTool())
1✔
677
        wftool = site.portal_workflow
1✔
678
        wftool._setObject('foo_workflow', DummyWorkflow('foo_workflow'))
1✔
679
        wftool.foo_workflow.state_var = 'state'
1✔
680
        wftool.setDefaultChain('foo_workflow')
1✔
681
        wftool.setChainForPortalTypes((TEST_INI_AWARE,),
1✔
682
                                      'foo_workflow', verify=False)
683

684
        context = DummyImportContext(site)
1✔
685
        context._files['structure/.objects'] = '\n'.join(
1✔
686
                            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
687
        context._files['structure/.workflow_states'] = '\n'.join(
1✔
688
                            ['%s,foo_workflow,draft' % (x) for x in ITEM_IDS])
689
        for index in range(len(ITEM_IDS)):
1✔
690
            id = ITEM_IDS[index]
1✔
691
            context._files[
1✔
692
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
693
                                                            'xyzzy')
694
        importer = self._getImporter()
1✔
695
        importer(context)
1✔
696

697
        for item_id in ITEM_IDS:
1✔
698
            wf = wftool.getStatusOf('foo_workflow', site[item_id])
1✔
699
            self.assertEqual(wf['state'], 'draft')
1✔
700

701
    def test_import_site_with_subitems_and_blanklines_dotobjects(self):
1✔
702
        self._setUpAdapters()
1✔
703
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
704

705
        site = _makeFolder('site', site_folder=True)
1✔
706

707
        context = DummyImportContext(site)
1✔
708
        # We want to add 'baz' to 'foo', without losing 'bar'
709
        correct = '\n'.join(['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
1✔
710
        broken = correct + '\n\n'
1✔
711
        context._files['structure/.objects'] = broken
1✔
712
        for index in range(len(ITEM_IDS)):
1✔
713
            id = ITEM_IDS[index]
1✔
714
            context._files[
1✔
715
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
716
                                                            'xyzzy')
717
        importer = self._getImporter()
1✔
718
        importer(context)
1✔
719

720
        after = site.objectIds()
1✔
721
        self.assertEqual(len(after), len(ITEM_IDS))
1✔
722
        for found_id, expected_id in zip(after, ITEM_IDS):
1✔
723
            self.assertEqual(found_id, expected_id)
1✔
724

725
    def test_import_site_with_subitem_unknown_portal_type(self):
1✔
726
        self._setUpAdapters()
1✔
727
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
728

729
        site = _makeFolder('site', site_folder=True)
1✔
730

731
        context = DummyImportContext(site)
1✔
732
        # We want to add 'baz' to 'foo', without losing 'bar'
733
        context._files['structure/.objects'] = '\n'.join(
1✔
734
                                ['%s,Unknown Type' % x for x in ITEM_IDS])
735
        for index in range(len(ITEM_IDS)):
1✔
736
            id = ITEM_IDS[index]
1✔
737
            context._files[
1✔
738
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
739
                                                            'xyzzy')
740

741
        importer = self._getImporter()
1✔
742
        importer(context)
1✔
743

744
        after = site.objectIds()
1✔
745
        self.assertEqual(len(after), 0)
1✔
746
        self.assertEqual(len(context._notes), len(ITEM_IDS))
1✔
747
        for _level, component, message in context._notes:
1✔
748
            self.assertEqual(component, 'SFWA')
1✔
749
            self.assertTrue(message.startswith("Couldn't make"))
1✔
750

751
    def test_reimport_no_structure_no_delete(self):
1✔
752
        self._setUpAdapters()
1✔
753
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
754

755
        site = _makeFolder('site', site_folder=True)
1✔
756
        for id in ITEM_IDS:
1✔
757
            site._setObject(id, _makeItem(id))
1✔
758

759
        context = DummyImportContext(site)
1✔
760
        # no defined structure => no deletion
761
        context._files['structure/.objects'] = ''
1✔
762

763
        importer = self._getImporter()
1✔
764
        importer(context)
1✔
765

766
        self.assertEqual(len(site.objectIds()), len(ITEM_IDS))
1✔
767

768
    def test_reimport_with_structure_does_delete(self):
1✔
769
        self._setUpAdapters()
1✔
770
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
771

772
        site = _makeFolder('site', site_folder=True)
1✔
773
        for id in ITEM_IDS:
1✔
774
            site._setObject(id, _makeItem(id))
1✔
775
            site._getOb(id).before = True
1✔
776

777
        context = DummyImportContext(site)
1✔
778
        # defined structure => object deleted and recreated
779
        context._files['structure/.objects'] = '\n'.join(
1✔
780
            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
781
        for index in range(len(ITEM_IDS)):
1✔
782
            id = ITEM_IDS[index]
1✔
783
            context._files[
1✔
784
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
785
                                                            'xyzzy')
786

787
        importer = self._getImporter()
1✔
788
        importer(context)
1✔
789

790
        self.assertEqual(len(site.objectIds()), len(ITEM_IDS))
1✔
791
        for obj in site.objectValues():
1✔
792
            self.assertFalse(hasattr(obj, 'before'))
1✔
793

794
    def test_reimport_with_structure_and_preserve(self):
1✔
795
        self._setUpAdapters()
1✔
796
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
797

798
        site = _makeFolder('site', site_folder=True)
1✔
799
        for id in ITEM_IDS:
1✔
800
            site._setObject(id, _makeINIAware(id))
1✔
801
            site._getOb(id).before = True
1✔
802

803
        context = DummyImportContext(site)
1✔
804
        context._files['structure/.objects'] = '\n'.join(
1✔
805
            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
806
        for index in range(len(ITEM_IDS)):
1✔
807
            id = ITEM_IDS[index]
1✔
808
            context._files[
1✔
809
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
810
                                                            'xyzzy')
811
        context._files['structure/.preserve'] = '*'
1✔
812

813
        importer = self._getImporter()
1✔
814
        importer(context)
1✔
815

816
        after = site.objectIds()
1✔
817
        self.assertEqual(len(after), len(ITEM_IDS))
1✔
818
        for i in range(len(ITEM_IDS)):
1✔
819
            self.assertEqual(after[i], ITEM_IDS[i])
1✔
820
            self.assertEqual(getattr(site._getOb(after[i]), 'before', None),
1✔
821
                             True)
822

823
    def test_reimport_with_structure_and_preserve_partial(self):
1✔
824
        self._setUpAdapters()
1✔
825
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
826

827
        site = _makeFolder('site', site_folder=True)
1✔
828
        for id in ITEM_IDS:
1✔
829
            site._setObject(id, _makeINIAware(id))
1✔
830
            site._getOb(id).before = True
1✔
831

832
        context = DummyImportContext(site)
1✔
833
        context._files['structure/.objects'] = '\n'.join(
1✔
834
            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS])
835
        for index in range(len(ITEM_IDS)):
1✔
836
            id = ITEM_IDS[index]
1✔
837
            context._files[
1✔
838
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
839
                                                            'xyzzy')
840
        context._files['structure/.preserve'] = 'b*'
1✔
841

842
        importer = self._getImporter()
1✔
843
        importer(context)
1✔
844

845
        after = site.objectValues()
1✔
846
        self.assertEqual(len(after), len(ITEM_IDS))
1✔
847
        for obj in after:
1✔
848
            if obj.getId().startswith('b'):
1✔
849
                self.assertEqual(getattr(obj, 'before', None), True)
1✔
850
            else:
851
                self.assertEqual(getattr(obj, 'before', None), None)
1✔
852

853
    def test_reimport_with_structure_partial_preserve_and_delete(self):
1✔
854
        self._setUpAdapters()
1✔
855
        ITEM_IDS = ('foo', 'bar', 'baz')
1✔
856

857
        site = _makeFolder('site', site_folder=True)
1✔
858
        for id in ITEM_IDS:
1✔
859
            site._setObject(id, _makeINIAware(id))
1✔
860
            site._getOb(id).before = True
1✔
861

862
        context = DummyImportContext(site)
1✔
863
        context._files['structure/.objects'] = '\n'.join(
1✔
864
            ['%s,%s' % (x, TEST_INI_AWARE) for x in ITEM_IDS[:-1]])
865
        for index in range(len(ITEM_IDS)):
1✔
866
            id = ITEM_IDS[index]
1✔
867
            context._files[
1✔
868
                    'structure/%s.ini' % id] = KNOWN_INI % ('Title: %s' % id,
869
                                                            'xyzzy')
870
        context._files['structure/.preserve'] = 'foo'
1✔
871
        context._files['structure/.delete'] = 'baz'
1✔
872

873
        importer = self._getImporter()
1✔
874
        importer(context)
1✔
875

876
        after = site.objectIds()
1✔
877
        self.assertEqual(len(after), len(ITEM_IDS) - 1)
1✔
878
        self.assertFalse('baz' in after)
1✔
879
        self.assertEqual(getattr(site.foo, 'before', None), True)
1✔
880
        self.assertFalse(hasattr(site.bar, 'before'))
1✔
881

882
    def test_import_site_with_subfolders_and_preserve(self):
1✔
883
        self._setUpAdapters()
1✔
884

885
        site = _makeFolder('site', site_folder=True)
1✔
886
        site._setObject('foo', _makeFolder('foo'))
1✔
887
        site.foo._setObject('bar', _makeFolder('bar'))
1✔
888

889
        context = DummyImportContext(site)
1✔
890
        # We want to add 'baz' to 'foo', without losing 'bar'
891
        context._files['structure/.objects'] = 'foo,%s' % TEST_FOLDER
1✔
892
        context._files['structure/.preserve'] = '*'
1✔
893
        context._files['structure/foo/.objects'] = 'baz,%s' % TEST_FOLDER
1✔
894
        context._files['structure/foo/.preserve'] = '*'
1✔
895
        context._files['structure/foo/baz/.objects'] = ''
1✔
896

897
        importer = self._getImporter()
1✔
898
        importer(context)
1✔
899

900
        self.assertEqual(len(site.objectIds()), 1)
1✔
901
        self.assertEqual(site.objectIds()[0], 'foo')
1✔
902

903
        self.assertEqual(len(site.foo.objectIds()), 2, site.foo.objectIds())
1✔
904
        self.assertEqual(site.foo.objectIds()[0], 'bar')
1✔
905
        self.assertEqual(site.foo.objectIds()[1], 'baz')
1✔
906

907

908
TEST_CSV_AWARE = 'Test CSV Aware'
1✔
909
KNOWN_CSV = """\
1✔
910
one,two,three
911
four,five,six
912
"""
913

914

915
def _makeCSVAware(id):
1✔
916
    from OFS.SimpleItem import SimpleItem
1✔
917
    from zope.interface import implementer
1✔
918

919
    from Products.GenericSetup.interfaces import ICSVAware
1✔
920

921
    from ...interfaces import IDynamicType
1✔
922

923
    @implementer(IDynamicType, ICSVAware)
1✔
924
    class _TestCSVAware(SimpleItem):
1✔
925
        _was_put = None
1✔
926
        portal_type = TEST_CSV_AWARE
1✔
927

928
        def getPortalTypeName(self):
1✔
929
            return self.portal_type
1✔
930

931
        def as_csv(self):
1✔
932
            return KNOWN_CSV
1✔
933

934
        def put_csv(self, text):
1✔
935
            self._was_put = text
×
936

937
    aware = _TestCSVAware()
1✔
938
    aware._setId(id)
1✔
939

940
    return aware
1✔
941

942

943
TEST_INI_AWARE = 'Test INI Aware'
1✔
944
KNOWN_INI = """\
1✔
945
[DEFAULT]
946
title = %s
947
description = %s
948
"""
949

950

951
def _makeINIAware(id):
1✔
952
    from OFS.SimpleItem import SimpleItem
1✔
953
    from zope.interface import implementer
1✔
954

955
    from Products.GenericSetup.interfaces import IINIAware
1✔
956

957
    from ...interfaces import IDynamicType
1✔
958

959
    @implementer(IDynamicType, IINIAware)
1✔
960
    class _TestINIAware(SimpleItem):
1✔
961
        _was_put = None
1✔
962
        title = 'INI title'
1✔
963
        description = 'INI description'
1✔
964
        portal_type = TEST_INI_AWARE
1✔
965

966
        def getPortalTypeName(self):
1✔
967
            return self.portal_type
1✔
968

969
        def as_ini(self):
1✔
970
            return KNOWN_INI % (self.title, self.description)
1✔
971

972
        def put_ini(self, text):
1✔
973
            self._was_put = text
1✔
974

975
        def reindexObject(self):
1✔
976
            return NotImplemented
1✔
977

978
    aware = _TestINIAware()
1✔
979
    aware._setId(id)
1✔
980

981
    return aware
1✔
982

983

984
TEST_DAV_AWARE = 'Test DAV Aware'
1✔
985
KNOWN_DAV = """\
1✔
986
Title: %s
987
Description: %s
988

989
%s
990
"""
991

992

993
def _makeDAVAware(id):
1✔
994
    from OFS.SimpleItem import SimpleItem
×
995
    from zope.interface import implementer
×
996

997
    from Products.GenericSetup.interfaces import IDAVAware
×
998

999
    from ...interfaces import IDynamicType
×
1000

1001
    @implementer(IDynamicType, IDAVAware)
×
1002
    class _TestDAVAware(SimpleItem):
×
1003
        _was_put = None
×
1004
        title = 'DAV title'
×
1005
        description = 'DAV description'
×
1006
        body = 'DAV body'
×
1007
        portal_type = TEST_DAV_AWARE
×
1008

1009
        def getPortalTypeName(self):
×
1010
            return self.portal_type
×
1011

1012
        def manage_FTPget(self):
×
1013
            return KNOWN_DAV % (self.title, self.description, self.body)
×
1014

1015
        def PUT(self, REQUEST, RESPONSE):
×
1016
            self._was_put = REQUEST.get('BODY', '')
×
1017
            stream = REQUEST.get('BODYFILE', None)
×
1018
            self._was_put_as_read = stream.read()
×
1019

1020
    aware = _TestDAVAware()
×
1021
    aware._setId(id)
×
1022

1023
    return aware
×
1024

1025

1026
TEST_DAV_FOLDER = 'Test DAV Folder'
1✔
1027

1028

1029
def _makeDAVAwareFolder(id):
1✔
1030
    from zope.interface import implementer
1✔
1031

1032
    from Products.GenericSetup.interfaces import IDAVAware
1✔
1033

1034
    from ...interfaces import IDynamicType
1✔
1035
    from ...PortalFolder import PortalFolder
1✔
1036

1037
    @implementer(IDynamicType, IDAVAware)
1✔
1038
    class _TestDAVAwareFolder(PortalFolder):
1✔
1039
        _was_put = None
1✔
1040
        body = 'DAV body'
1✔
1041
        portal_type = TEST_DAV_FOLDER
1✔
1042

1043
        def getPortalTypeName(self):
1✔
1044
            return self.portal_type
1✔
1045

1046
        def manage_FTPget(self):
1✔
1047
            return KNOWN_DAV % (self.title, self.description, self.body)
1✔
1048

1049
        def PUT(self, REQUEST, RESPONSE):
1✔
1050
            self._was_put = REQUEST.get('BODY', '')
1✔
1051
            stream = REQUEST.get('BODYFILE', None)
1✔
1052
            self._was_put_as_read = stream.read()
1✔
1053

1054
    folder = _TestDAVAwareFolder(id)
1✔
1055
    folder.portal_type = TEST_DAV_FOLDER
1✔
1056
    return folder
1✔
1057

1058

1059
TEST_CONTENT = 'Test Content'
1✔
1060

1061

1062
def _makeItem(self):
1✔
1063
    from OFS.SimpleItem import SimpleItem
1✔
1064
    from zope.interface import implementer
1✔
1065

1066
    from ...interfaces import IDynamicType
1✔
1067

1068
    @implementer(IDynamicType)
1✔
1069
    class _TestContent(SimpleItem):
1✔
1070
        portal_type = TEST_CONTENT
1✔
1071

1072
        def getPortalTypeName(self):
1✔
1073
            return self.portal_type
1✔
1074

1075
    aware = _TestContent()
1✔
1076
    aware._setId(id)
1✔
1077

1078
    return aware
1✔
1079

1080

1081
TEST_FOLDER = 'Test Folder'
1✔
1082

1083

1084
def _makeFolder(id, site_folder=False):
1✔
1085
    from ...PortalFolder import PortalFolder
1✔
1086
    from ...tests.base.dummy import DummyType
1✔
1087
    from ...TypesTool import TypesTool
1✔
1088

1089
    class _TypeInfo(DummyType):
1✔
1090
        def _getId(self):
1✔
1091
            return self._id
1✔
1092

1093
        def constructInstance(self, container, id, *args, **kw):
1✔
1094
            portal_type = self._getId()
1✔
1095
            if portal_type == TEST_FOLDER:
1✔
1096
                content = PortalFolder(id)
1✔
1097
            elif portal_type == TEST_DAV_FOLDER:
1✔
1098
                content = _makeDAVAwareFolder(id)
1✔
1099
            elif portal_type == TEST_CONTENT:
1!
1100
                content = _makeItem()
×
1101
                content._setId(id)
×
1102
            elif portal_type == TEST_INI_AWARE:
1!
1103
                content = _makeINIAware(id)
1✔
1104
            elif portal_type == TEST_CSV_AWARE:
×
1105
                content = _makeCSVAware(id)
×
1106
            else:
1107
                raise ValueError('Ugh')
×
1108
            content.portal_type = portal_type
1✔
1109
            container._setObject(id, content)
1✔
1110
            return container._getOb(id)
1✔
1111

1112
    folder = PortalFolder(id)
1✔
1113
    folder.portal_type = TEST_FOLDER
1✔
1114
    if site_folder:
1✔
1115
        ttool = TypesTool()
1✔
1116
        ttool._setObject(TEST_CSV_AWARE, _TypeInfo(TEST_CSV_AWARE))
1✔
1117
        ttool._setObject(TEST_INI_AWARE, _TypeInfo(TEST_INI_AWARE))
1✔
1118
        ttool._setObject(TEST_CONTENT, _TypeInfo(TEST_CONTENT))
1✔
1119
        ttool._setObject(TEST_FOLDER, _TypeInfo(TEST_FOLDER))
1✔
1120
        ttool._setObject(TEST_DAV_FOLDER, _TypeInfo(TEST_DAV_FOLDER))
1✔
1121
        getSiteManager().registerUtility(ttool, ITypesTool)
1✔
1122

1123
    return folder
1✔
1124

1125

1126
def test_suite():
1✔
1127
    suite = unittest.TestSuite()
1✔
1128
    suite.addTest(unittest.makeSuite(SiteStructureExporterTests))
1✔
1129
    return suite
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc