Index: main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_batching.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_batching.py	(revision 6250)
+++ main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_batching.py	(revision 6250)
@@ -0,0 +1,128 @@
+##
+## test_batching.py
+## Login : <uli@pu.smp.net>
+## Started on  Tue Aug 24 02:04:44 2010 Uli Fouquet
+## $Id$
+## 
+## Copyright (C) 2010 Uli Fouquet
+## 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
+##
+"""Unit tests for the JAMB data importer.
+"""
+
+import grok
+import os
+import shutil
+import tempfile
+import unittest
+from zope.component.hooks import setSite, clearSite
+from zope.interface import verify
+from waeup.sirp.interfaces import IBatchProcessor
+from waeup.sirp.applicants.jambtables import JAMBDataImporter
+
+# Sample data we can use in tests...
+JAMB_SAMPLE_DATA = '''reg_no,fst_sit_fname,lastname,firstname,middlenames,sex,date_of_birth,jamb_state,jamb_lga,course1,screening_date,screening_venue,entry_session,screening_type,ignore_this_col
+91100546DD,ISUOSUO MOSES ODOMERO,ISUOSUO,MOSES,ODOMERO,M,25/5/1982,DEL,ISO-S,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde,blah
+91111834CC,DURUIHEOMA AUGUSTINA ADANNA,DURUIHEOMA,AUGUSTINA,ADANNA,F,15/4/1986,IMO,MBAIT,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde,blah
+91109351AC,ARISERE EBIKEBUNA COMFORT,ARISERE,EBIKEBUNA,COMFORT,F,6/1/1984,EDO,OV-SW,BSCPOL,2009/09/25 09:00:00 GMT+1,REPRINT SLIP AS FROM WED 23/09/2009,9,pde,blah
+'''
+
+# The header fields of the above CSV snippet
+HEADER_FIELDS = JAMB_SAMPLE_DATA.split('\n')[0].split(',')
+
+class FakeSite(dict):
+    def getSiteManager(self):
+        return object()
+
+class JAMBDataImporterTest(unittest.TestCase):
+
+    def setUp(self):
+        self.importer = JAMBDataImporter()
+        self.site1 = dict(
+            jambdata = {
+                'REG_NO_1': 'Application1',
+                }
+            )
+        self.workdir = tempfile.mkdtemp()
+        self.csv_file = os.path.join(self.workdir, 'sampledata.csv')
+        open(self.csv_file, 'wb').write(JAMB_SAMPLE_DATA)
+        return
+
+    def tearDown(self):
+        shutil.rmtree(self.workdir)
+        clearSite()
+        return
+
+    def test_interface(self):
+        """Make sure we fulfill the interface contracts."""
+        assert verify.verifyObject(IBatchProcessor, self.importer) is True
+        assert verify.verifyClass(IBatchProcessor, JAMBDataImporter) is True
+
+    def test_parentsExist(self):
+        assert self.importer.parentsExist(None, dict()) is False
+        assert self.importer.parentsExist(None, self.site1) is True
+
+    def test_entryExists(self):
+        assert self.importer.entryExists(
+            dict(reg_no='REG_NONE'), self.site1) is False
+        assert self.importer.entryExists(
+            dict(reg_no='REG_NO_1'), self.site1) is True
+
+    def test_getParent(self):
+        parent = self.importer.getParent(None, self.site1)
+        assert parent is self.site1['jambdata']
+
+    def test_getEntry(self):
+        assert self.importer.getEntry(
+            dict(reg_no='REG_NONE'), self.site1) is None
+        assert self.importer.getEntry(
+            dict(reg_no='REG_NO_1'), self.site1) == 'Application1'
+
+    def test_addEntry(self):
+        self.importer.addEntry(
+            'New application', dict(reg_no='REG_NO_99'), self.site1)
+        assert self.site1['jambdata']['REG_NO_99'] == 'New application'
+
+    def test_delEntry(self):
+        self.importer.delEntry(dict(reg_no='REG_NO_1'), self.site1)
+        assert 'REG_NO_1' not in self.site1['jambdata'].keys()
+
+    def test_import(self):
+        # Do a real import
+        # The following modules register important components for import
+        # Registers converters...
+        grok.testing.grok('waeup.sirp.utils.converters')
+        # Registers the Applicant factory...
+        grok.testing.grok('waeup.sirp.applicants.applicants')
+
+        # Create a fake site to store datasets in...
+        site = FakeSite()
+        # The site must have a 'jambdata' entry...
+        site['jambdata'] = dict()
+        # Set the fake site as 'current' site object...
+        setSite(site)
+        self.importer.doImport(self.csv_file, HEADER_FIELDS)
+        self.assertTrue(u'91100546DD' in site['jambdata'].keys())
+
+def test_suite():
+    suite = unittest.TestSuite()
+    for testcase in [
+        JAMBDataImporterTest,
+        ]:
+        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+                testcase
+                )
+        )
+    return suite
