Index: main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/tests/test_browser.py
===================================================================
--- main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/tests/test_browser.py	(revision 12285)
+++ main/ikobacustom.skeleton/trunk/src/ikobacustom/skeleton/customers/tests/test_browser.py	(revision 12285)
@@ -0,0 +1,94 @@
+## $Id: test_browser.py 12269 2014-12-20 16:12:59Z henrik $
+##
+## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+"""
+Document browser and functional tests.
+"""
+import os
+import grok
+import datetime
+from cStringIO import StringIO
+from zope.component import queryUtility, getUtility, createObject
+from zope.event import notify
+from zope.interface.verify import verifyObject, verifyClass
+from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup
+from ikobacustom.skeleton.customers.documents import SkeletonCustomerDocument
+from ikobacustom.skeleton.customers.export import SkeletonCustomerDocumentExporter
+from ikobacustom.skeleton.customers.batching import SkeletonCustomerDocumentProcessor
+from ikobacustom.skeleton.testing import FunctionalLayer
+
+
+class CustomerImportExportTest(CustomerImportExportSetup):
+
+    layer = FunctionalLayer
+
+    def setup_for_export(self):
+        customer = createObject(u'waeup.Customer')
+        self.app['customers'].addCustomer(customer)
+        document = createObject(u'waeup.SkeletonCustomerDocument')
+        document.title = u'My first document'
+        customer['documents'].addDocument(document)
+        self.customer = customer
+        self.document = document
+        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
+        return
+
+    def test_export_reimport_all(self):
+        # we can export all documents in a portal
+        # set values we can expect in export file
+        self.setup_for_export()
+        exporter = SkeletonCustomerDocumentExporter()
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertMatches(result,
+            'class_name,document_id,history,state,title,user_id\r\n'
+            'SkeletonCustomerDocument,%s,'
+            '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],'
+            'created,My first document,K1000000\r\n'
+            % self.document.document_id)
+        # We can import the file if we change the header (user_id -> customer_id)
+        processor = SkeletonCustomerDocumentProcessor()
+        open(self.outfile, 'wb').write(
+            'customer_id,class_name,document_id,state,title\r\n'
+            'K1000000,SkeletonCustomerDocument,%s,started,My first title\r\n'
+            % self.document.document_id)
+        result = processor.doImport(
+            self.outfile,
+            ['customer_id','class_name','document_id','state','title'],
+            mode='create')
+        num, num_fail, finished_path, failed_path = result
+        #content = open(failed_path).read()
+        # The object exists.
+        self.assertEqual(num_fail,1)
+        # We remove the original document.
+        del self.customer['documents'][self.document.document_id]
+        result = processor.doImport(
+            self.outfile,
+            ['customer_id','class_name','document_id','state','title'],
+            mode='create')
+        num_succ, num_fail, finished_path, failed_path = result
+        self.assertEqual(num_fail,0)
+        # We can import the same file in update mode.
+        processor = SkeletonCustomerDocumentProcessor()
+        result = processor.doImport(
+            self.outfile,
+            ['customer_id','class_name','document_id','state','title'],
+            mode='update')
+        num_succ, num_fail, finished_path, failed_path = result
+        self.assertEqual(num_succ,1)
+        self.assertEqual(num_fail,0)
+        return
