[12288] | 1 | ## $Id: test_export.py 12365 2015-01-02 10:09:50Z henrik $ |
---|
[12266] | 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() |
---|
[12287] | 64 | self.assertMatches( |
---|
| 65 | 'class_name,description,document_id,history,state,title,users_with_local_roles\r\n' |
---|
| 66 | 'PDFDocument,,DOC1,' |
---|
| 67 | '[u\'2014-12-21 16:55:16 UTC - Document created by system\'],' |
---|
| 68 | 'created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"', |
---|
| 69 | result |
---|
[12266] | 70 | ) |
---|
| 71 | return |
---|
| 72 | |
---|
| 73 | def test_export_all(self): |
---|
| 74 | # we can really export all documents |
---|
| 75 | exporter = PDFDocumentExporter() |
---|
| 76 | exporter.export_all(self.app, self.outfile) |
---|
| 77 | result = open(self.outfile, 'rb').read() |
---|
[12287] | 78 | self.assertMatches( |
---|
| 79 | 'class_name,description,document_id,history,state,title,users_with_local_roles\r\n' |
---|
| 80 | 'PDFDocument,,DOC1,' |
---|
| 81 | '[u\'2014-12-21 16:55:16 UTC - Document created by system\'],' |
---|
| 82 | 'created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"', |
---|
| 83 | result |
---|
[12266] | 84 | ) |
---|
| 85 | return |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | class HTMLDocumentExporterTest(DocumentImportExportSetup): |
---|
| 89 | |
---|
| 90 | layer = FunctionalLayer |
---|
| 91 | |
---|
| 92 | def setUp(self): |
---|
| 93 | super(HTMLDocumentExporterTest, self).setUp() |
---|
| 94 | self.setup_for_export() |
---|
| 95 | return |
---|
| 96 | |
---|
| 97 | def test_ifaces(self): |
---|
| 98 | # make sure we fullfill interface contracts |
---|
| 99 | obj = HTMLDocumentExporter() |
---|
| 100 | verifyObject(ICSVExporter, obj) |
---|
| 101 | verifyClass(ICSVExporter, HTMLDocumentExporter) |
---|
| 102 | return |
---|
| 103 | |
---|
| 104 | def test_get_as_utility(self): |
---|
| 105 | # we can get an document exporter as utility |
---|
| 106 | result = queryUtility(ICSVExporter, name="htmldocuments") |
---|
| 107 | self.assertTrue(result is not None) |
---|
| 108 | return |
---|
| 109 | |
---|
| 110 | def test_export(self): |
---|
| 111 | # we can really export a document |
---|
| 112 | exporter = HTMLDocumentExporter() |
---|
| 113 | exporter.export([self.htmldocument], self.outfile) |
---|
| 114 | result = open(self.outfile, 'rb').read() |
---|
[12287] | 115 | self.assertMatches( |
---|
[12365] | 116 | 'class_name,description,document_id,history,html_dict,' |
---|
[12287] | 117 | 'html_multilingual,state,title,users_with_local_roles\r\n' |
---|
| 118 | 'HTMLDocument,,DOC2,' |
---|
| 119 | '[u\'2014-12-21 16:50:28 UTC - Document created by system\'],' |
---|
[12365] | 120 | '{},,created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"', |
---|
[12287] | 121 | result |
---|
[12266] | 122 | ) |
---|
| 123 | return |
---|
| 124 | |
---|
| 125 | def test_export_all(self): |
---|
| 126 | # we can really export all documents |
---|
| 127 | exporter = HTMLDocumentExporter() |
---|
| 128 | exporter.export_all(self.app, self.outfile) |
---|
| 129 | result = open(self.outfile, 'rb').read() |
---|
[12287] | 130 | self.assertMatches( |
---|
[12365] | 131 | 'class_name,description,document_id,history,html_dict,' |
---|
[12287] | 132 | 'html_multilingual,state,title,users_with_local_roles\r\n' |
---|
| 133 | 'HTMLDocument,,DOC2,' |
---|
| 134 | '[u\'2014-12-21 16:50:28 UTC - Document created by system\'],' |
---|
[12365] | 135 | '{},,created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"', |
---|
[12287] | 136 | result |
---|
[12266] | 137 | ) |
---|
| 138 | return |
---|