source: main/ikobacustom.aaue/trunk/src/ikobacustom/aaue/documents/tests/test_browser.py @ 17497

Last change on this file since 17497 was 14310, checked in by Henrik Bettermann, 8 years ago

Renaming and port setting.

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1## $Id: test_browser.py 14310 2016-12-05 09:14:32Z 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.aaue.documents.document import AAUEDocument
30from ikobacustom.aaue.documents.export import AAUEDocumentExporter
31from ikobacustom.aaue.documents.batching import AAUEDocumentProcessor
32from ikobacustom.aaue.testing import FunctionalLayer
33
34
35class DocumentImportExportTest(DocumentImportExportSetup):
36
37    layer = FunctionalLayer
38
39    def setup_for_export(self):
40        document = AAUEDocument()
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 = AAUEDocumentExporter()
52        exporter.export_all(self.app, self.outfile)
53        result = open(self.outfile, 'rb').read()
54        self.assertMatches(result,
55            'class_name,description,document_id,history,state,title,'
56            'users_with_local_roles\r\n'
57            'AAUEDocument,,DOC1,'
58            '[u\'2014-12-21 23:27:15 WAT - Document created by system\'],'
59            'created,My first document,[]\r\n')
60        # We can import the same file.
61        processor = AAUEDocumentProcessor()
62        result = processor.doImport(
63            self.outfile,
64            ['class_name','description','document_id','history','state',
65             'title','users_with_local_roles'],
66            mode='create')
67        num, num_fail, finished_path, failed_path = result
68        #content = open(failed_path).read()
69        # The object exists.
70        self.assertEqual(num_fail,1)
71        # We remove the original document.
72        del self.app['documents']['DOC1']
73        result = processor.doImport(
74            self.outfile,
75            ['class_name','description','document_id','history','state',
76             'title','users_with_local_roles'],
77            mode='create')
78        num_succ, num_fail, finished_path, failed_path = result
79        self.assertEqual(num_fail,0)
80        # We can import the same file in update mode.
81        processor = AAUEDocumentProcessor()
82        result = processor.doImport(
83            self.outfile,
84            ['class_name','description','document_id','history','state',
85             'title','users_with_local_roles'],
86            mode='update')
87        num_succ, num_fail, finished_path, failed_path = result
88        self.assertEqual(num_succ,1)
89        self.assertEqual(num_fail,0)
90        return
Note: See TracBrowser for help on using the repository browser.