Index: main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_batch_data.csv
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_batch_data.csv	(revision 9263)
+++ main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_batch_data.csv	(revision 9263)
@@ -0,0 +1,5 @@
+batch_id,cost,creation_date,creator,disabled_num,entry_num,num,prefix,used_num
+CLR-1,0.0,2012-04-28 07:28:48.719026,system,0,3,1,CLR,1
+HOS-2,0.0,2012-04-28 07:28:48.719026,system,0,0,2,HOS,0
+HOS-1,0.0,2012-09-19 08:59:27.341100,zope.manager,0,1000,1,HOS,1
+SFE-3,0.0,2012-04-28 07:28:48.719026,system,0,8,3,SFE,0
Index: main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_batching.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_batching.py	(revision 9263)
+++ main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_batching.py	(revision 9263)
@@ -0,0 +1,103 @@
+## $Id$
+##
+## Copyright (C) 2011 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
+##
+"""
+Tests for hostels and their UI components.
+"""
+import os
+import shutil
+import tempfile
+import grok
+import pytz
+from datetime import datetime, timedelta
+from zope.event import notify
+from zope.interface.verify import verifyClass, verifyObject
+from zope.component.hooks import setSite, clearSite
+from zope.testbrowser.testing import Browser
+from zope.security.interfaces import Unauthorized
+from zope.catalog.interfaces import ICatalog
+from zope.component import queryUtility
+from waeup.kofa.app import University
+from waeup.kofa.interfaces import IObjectHistory, IKofaPluggable, IKofaUtils
+from waeup.kofa.testing import (
+    FunctionalLayer, FunctionalTestCase, setUp, tearDown, getRootFolder)
+from waeup.kofa.accesscodes.batching import AccessCodeBatchProcessor
+
+
+BATCH_SAMPLE_DATA = open(
+    os.path.join(os.path.dirname(__file__), 'sample_batch_data.csv'),
+    'rb').read()
+
+BATCH_HEADER_FIELDS = BATCH_SAMPLE_DATA.split(
+    '\n')[0].split(',')
+
+class ACFullSetup(FunctionalTestCase):
+
+    def setUp(self):
+        super(ACFullSetup, self).setUp()
+
+        # Setup a sample site for each test
+        app = University()
+        self.dc_root = tempfile.mkdtemp()
+        app['datacenter'].setStoragePath(self.dc_root)
+
+        # Prepopulate the ZODB...
+        self.getRootFolder()['app'] = app
+        # we add the site immediately after creation to the
+        # ZODB. Catalogs and other local utilities are not setup
+        # before that step.
+        self.app = self.getRootFolder()['app']
+        # Set site here. Some of the following setup code might need
+        # to access grok.getSite() and should get our new app then
+        setSite(app)
+
+        # Put the prepopulated site into test ZODB and prepare test
+        # browser
+        self.browser = Browser()
+        self.browser.handleErrors = False
+
+        self.logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'accesscodes.log')
+
+    def tearDown(self):
+        super(ACFullSetup, self).tearDown()
+        clearSite()
+        shutil.rmtree(self.dc_root)
+
+class ACBatchProcessorTest(ACFullSetup):
+
+    layer = FunctionalLayer
+
+    def test_import(self):
+        self.processor = AccessCodeBatchProcessor()
+        self.workdir = tempfile.mkdtemp()
+        self.csv_file = os.path.join(self.workdir, 'sample_batch_data.csv')
+        open(self.csv_file, 'wb').write(BATCH_SAMPLE_DATA)
+        num, num_warns, fin_file, fail_file = self.processor.doImport(
+            self.csv_file, BATCH_HEADER_FIELDS)
+        self.assertEqual(num_warns,0)
+        self.assertEqual(len(self.app['accesscodes'].keys()), 7)
+        self.assertEqual(self.app['accesscodes']['CLR-1'].num,1)
+        logcontent = open(self.logfile).read()
+        self.assertTrue(
+            'system - AccessCodeBatch Processor - CLR-1 - '
+            'Batch updated: num=1, creator=system, entry_num=3, '
+            'creation_date=2012-04-28 07:28:48.719026+00:00, '
+            'prefix=CLR, cost=0.0, disabled_num=0'
+            in logcontent)
+        shutil.rmtree(os.path.dirname(fin_file))
+        return
