[12269] | 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 | """ |
---|
| 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 |
---|
[14310] | 29 | from ikobacustom.aaue.documents.document import AAUEDocument |
---|
| 30 | from ikobacustom.aaue.documents.export import AAUEDocumentExporter |
---|
| 31 | from ikobacustom.aaue.documents.batching import AAUEDocumentProcessor |
---|
| 32 | from ikobacustom.aaue.testing import FunctionalLayer |
---|
[12269] | 33 | |
---|
| 34 | |
---|
| 35 | class DocumentImportExportTest(DocumentImportExportSetup): |
---|
| 36 | |
---|
| 37 | layer = FunctionalLayer |
---|
| 38 | |
---|
| 39 | def setup_for_export(self): |
---|
[14310] | 40 | document = AAUEDocument() |
---|
[12269] | 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() |
---|
[14310] | 51 | exporter = AAUEDocumentExporter() |
---|
[12269] | 52 | exporter.export_all(self.app, self.outfile) |
---|
| 53 | result = open(self.outfile, 'rb').read() |
---|
[12290] | 54 | self.assertMatches(result, |
---|
| 55 | 'class_name,description,document_id,history,state,title,' |
---|
| 56 | 'users_with_local_roles\r\n' |
---|
[14310] | 57 | 'AAUEDocument,,DOC1,' |
---|
[12290] | 58 | '[u\'2014-12-21 23:27:15 WAT - Document created by system\'],' |
---|
| 59 | 'created,My first document,[]\r\n') |
---|
[12269] | 60 | # We can import the same file. |
---|
[14310] | 61 | processor = AAUEDocumentProcessor() |
---|
[12269] | 62 | result = processor.doImport( |
---|
| 63 | self.outfile, |
---|
[12290] | 64 | ['class_name','description','document_id','history','state', |
---|
| 65 | 'title','users_with_local_roles'], |
---|
[12269] | 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, |
---|
[12290] | 75 | ['class_name','description','document_id','history','state', |
---|
| 76 | 'title','users_with_local_roles'], |
---|
[12269] | 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. |
---|
[14310] | 81 | processor = AAUEDocumentProcessor() |
---|
[12269] | 82 | result = processor.doImport( |
---|
| 83 | self.outfile, |
---|
[12290] | 84 | ['class_name','description','document_id','history','state', |
---|
| 85 | 'title','users_with_local_roles'], |
---|
[12269] | 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 |
---|