1 | ## $Id: test_browser.py 14178 2016-09-22 20:11:06Z 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 | """ |
---|
19 | Document browser and functional tests. |
---|
20 | """ |
---|
21 | import os |
---|
22 | import grok |
---|
23 | import datetime |
---|
24 | from cStringIO import StringIO |
---|
25 | from zope.component import queryUtility, getUtility |
---|
26 | from zope.event import notify |
---|
27 | from zope.interface.verify import verifyObject, verifyClass |
---|
28 | from waeup.ikoba.documents.tests.test_batching import DocumentImportExportSetup |
---|
29 | from ikobacustom.uniben.documents.document import SkeletonDocument |
---|
30 | from ikobacustom.uniben.documents.export import SkeletonDocumentExporter |
---|
31 | from ikobacustom.uniben.documents.batching import SkeletonDocumentProcessor |
---|
32 | from ikobacustom.uniben.testing import FunctionalLayer |
---|
33 | |
---|
34 | |
---|
35 | class 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.assertMatches(result, |
---|
55 | 'class_name,description,document_id,history,state,title,' |
---|
56 | 'users_with_local_roles\r\n' |
---|
57 | 'SkeletonDocument,,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 = SkeletonDocumentProcessor() |
---|
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 = SkeletonDocumentProcessor() |
---|
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 |
---|