source: main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/documents/tests/test_browser.py @ 12269

Last change on this file since 12269 was 12269, checked in by Henrik Bettermann, 10 years ago

Add product for portal document customizations.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: test_browser.py 12269 2014-12-20 16:12:59Z henrik $
2##
3## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Document browser and functional tests.
20"""
21import os
22import grok
23import datetime
24from cStringIO import StringIO
25from zope.component import queryUtility, getUtility
26from zope.event import notify
27from zope.interface.verify import verifyObject, verifyClass
28from waeup.ikoba.documents.tests.test_batching import DocumentImportExportSetup
29from ikobacustom.skeleton.documents.document import SkeletonDocument
30from ikobacustom.skeleton.documents.export import SkeletonDocumentExporter
31from ikobacustom.skeleton.documents.batching import SkeletonDocumentProcessor
32from ikobacustom.skeleton.testing import FunctionalLayer
33
34
35class DocumentImportExportTest(DocumentImportExportSetup):
36
37    layer = FunctionalLayer
38
39    def setup_for_export(self):
40        document = SkeletonDocument()
41        document.document_id = u'DOC1'
42        document.title = u'My first document'
43        self.app['documents'][document.document_id] = self.document = document
44        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
45        return
46
47    def test_export_reimport_all(self):
48        # we can export all documents in a portal
49        # set values we can expect in export file
50        self.setup_for_export()
51        exporter = SkeletonDocumentExporter()
52        exporter.export_all(self.app, self.outfile)
53        result = open(self.outfile, 'rb').read()
54        self.assertEqual(result,
55            'description,document_id,title,users_with_local_roles\r\n'
56            ',DOC1,My first document,[]\r\n')
57        # We can import the same file.
58        processor = SkeletonDocumentProcessor()
59        result = processor.doImport(
60            self.outfile,
61            ['description','document_id','title','users_with_local_roles'],
62            mode='create')
63        num, num_fail, finished_path, failed_path = result
64        #content = open(failed_path).read()
65        # The object exists.
66        self.assertEqual(num_fail,1)
67        # We remove the original document.
68        del self.app['documents']['DOC1']
69        result = processor.doImport(
70            self.outfile,
71            ['description','document_id','title','users_with_local_roles'],
72            mode='create')
73        num_succ, num_fail, finished_path, failed_path = result
74        self.assertEqual(num_fail,1)
75        # ... only if we add column
76        open(self.outfile, 'wb').write(
77            'description,document_id,title,users_with_local_roles,class_name\r\n'
78            ',DOC1,My first title,[],SkeletonDocument\r\n')
79        result = processor.doImport(
80            self.outfile,
81            ['description','document_id','title','users_with_local_roles','class_name'],
82            mode='create')
83        num_succ, num_fail, finished_path, failed_path = result
84        self.assertEqual(num_fail,0)
85        # We can import the same file in update mode.
86        processor = SkeletonDocumentProcessor()
87        result = processor.doImport(
88            self.outfile,
89            ['description','document_id','title','users_with_local_roles'],
90            mode='update')
91        num_succ, num_fail, finished_path, failed_path = result
92        self.assertEqual(num_succ,1)
93        self.assertEqual(num_fail,0)
94        return
Note: See TracBrowser for help on using the repository browser.