source: main/waeup.kofa/trunk/src/waeup/kofa/documents/tests/test_export.py @ 12438

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

Propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1## $Id: test_export.py 12438 2015-01-11 08:27:37Z 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"""
19Test the document exporter.
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.kofa.interfaces import (
29    ICSVExporter, IExtFileStore, IFileStoreNameChooser)
30from waeup.kofa.documents.export import (
31    PDFDocumentExporter, HTMLDocumentExporter)
32from waeup.kofa.documents.document import PDFDocument, HTMLDocument
33from waeup.kofa.documents.tests.test_batching import DocumentImportExportSetup
34from waeup.kofa.testing import FunctionalLayer
35
36
37class 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.assertMatches(
65            'class_name,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
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()
78        self.assertMatches(
79            'class_name,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
84            )
85        return
86
87
88class 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()
115        self.assertMatches(
116            'class_name,document_id,history,html_dict,'
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\'],'
120            '{},,created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"',
121            result
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()
130        self.assertMatches(
131            'class_name,document_id,history,html_dict,'
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\'],'
135            '{},,created,,"[{\'user_name\': u\'john\', \'local_role\': u\'johnsrole\'}]"',
136            result
137            )
138        return
Note: See TracBrowser for help on using the repository browser.