1 | ## $Id: test_export.py 12097 2014-11-30 20:49:22Z 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 | Test the document exporter. |
---|
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.interfaces import ( |
---|
29 | ICSVExporter, IExtFileStore, IFileStoreNameChooser) |
---|
30 | from waeup.ikoba.documents.export import ( |
---|
31 | PDFDocumentExporter, HTMLDocumentExporter) |
---|
32 | from waeup.ikoba.documents.document import PDFDocument, HTMLDocument |
---|
33 | from waeup.ikoba.documents.tests.test_batching import DocumentImportExportSetup |
---|
34 | from waeup.ikoba.testing import FunctionalLayer |
---|
35 | |
---|
36 | |
---|
37 | class PDFDocumentExporterTest(DocumentImportExportSetup): |
---|
38 | |
---|
39 | layer = FunctionalLayer |
---|
40 | |
---|
41 | def setUp(self): |
---|
42 | super(PDFDocumentExporterTest, self).setUp() |
---|
43 | self.setup_for_export() |
---|
44 | return |
---|
45 | |
---|
46 | def test_ifaces(self): |
---|
47 | # make sure we fullfill interface contracts |
---|
48 | obj = PDFDocumentExporter() |
---|
49 | verifyObject(ICSVExporter, obj) |
---|
50 | verifyClass(ICSVExporter, PDFDocumentExporter) |
---|
51 | return |
---|
52 | |
---|
53 | def test_get_as_utility(self): |
---|
54 | # we can get an document exporter as utility |
---|
55 | result = queryUtility(ICSVExporter, name="pdfdocuments") |
---|
56 | self.assertTrue(result is not None) |
---|
57 | return |
---|
58 | |
---|
59 | def test_export(self): |
---|
60 | # we can really export a document |
---|
61 | exporter = PDFDocumentExporter() |
---|
62 | exporter.export([self.pdfdocument], self.outfile) |
---|
63 | result = open(self.outfile, 'rb').read() |
---|
64 | self.assertTrue( |
---|
65 | 'description,document_id,title,users_with_local_roles\r\n' |
---|
66 | ',DOC1,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"' |
---|
67 | in result |
---|
68 | ) |
---|
69 | return |
---|
70 | |
---|
71 | def test_export_all(self): |
---|
72 | # we can really export all documents |
---|
73 | exporter = PDFDocumentExporter() |
---|
74 | exporter.export_all(self.app, self.outfile) |
---|
75 | result = open(self.outfile, 'rb').read() |
---|
76 | self.assertTrue( |
---|
77 | 'description,document_id,title,users_with_local_roles\r\n' |
---|
78 | ',DOC1,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"' |
---|
79 | in result |
---|
80 | ) |
---|
81 | return |
---|
82 | |
---|
83 | |
---|
84 | class HTMLDocumentExporterTest(DocumentImportExportSetup): |
---|
85 | |
---|
86 | layer = FunctionalLayer |
---|
87 | |
---|
88 | def setUp(self): |
---|
89 | super(HTMLDocumentExporterTest, self).setUp() |
---|
90 | self.setup_for_export() |
---|
91 | return |
---|
92 | |
---|
93 | def test_ifaces(self): |
---|
94 | # make sure we fullfill interface contracts |
---|
95 | obj = HTMLDocumentExporter() |
---|
96 | verifyObject(ICSVExporter, obj) |
---|
97 | verifyClass(ICSVExporter, HTMLDocumentExporter) |
---|
98 | return |
---|
99 | |
---|
100 | def test_get_as_utility(self): |
---|
101 | # we can get an document exporter as utility |
---|
102 | result = queryUtility(ICSVExporter, name="htmldocuments") |
---|
103 | self.assertTrue(result is not None) |
---|
104 | return |
---|
105 | |
---|
106 | def test_export(self): |
---|
107 | # we can really export a document |
---|
108 | exporter = HTMLDocumentExporter() |
---|
109 | exporter.export([self.htmldocument], self.outfile) |
---|
110 | result = open(self.outfile, 'rb').read() |
---|
111 | self.assertTrue( |
---|
112 | 'description,document_id,html_multilingual,title,' |
---|
113 | 'users_with_local_roles\r\n,DOC2,' |
---|
114 | ',,' |
---|
115 | '"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"\r\n' |
---|
116 | in result |
---|
117 | ) |
---|
118 | return |
---|
119 | |
---|
120 | def test_export_all(self): |
---|
121 | # we can really export all documents |
---|
122 | exporter = HTMLDocumentExporter() |
---|
123 | exporter.export_all(self.app, self.outfile) |
---|
124 | result = open(self.outfile, 'rb').read() |
---|
125 | self.assertTrue( |
---|
126 | 'description,document_id,html_multilingual,title,' |
---|
127 | 'users_with_local_roles\r\n,DOC2,' |
---|
128 | ',,' |
---|
129 | '"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"\r\n' |
---|
130 | in result |
---|
131 | ) |
---|
132 | return |
---|