Changeset 5742 for main/waeup.sirp


Ignore:
Timestamp:
13 Feb 2011, 01:25:37 (14 years ago)
Author:
uli
Message:

Add test for real import of JAMB data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_batching.py

    r5730 r5742  
    2020## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    2121##
    22 """Unit tests for the applicant importer.
     22"""Unit tests for the JAMB data importer.
    2323"""
     24
    2425import grok
     26import os
     27import shutil
     28import tempfile
    2529import unittest
     30from zope.component.hooks import setSite, clearSite
    2631from zope.interface import verify
    2732from waeup.sirp.interfaces import IBatchProcessor
    2833from waeup.sirp.applicants.jambtables import JAMBDataImporter
     34
     35# Sample data we can use in tests...
     36JAMB_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
     3791100546DD,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
     3891111834CC,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
     3991109351AC,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
     40'''
     41
     42# The header fields of the above CSV snippet
     43HEADER_FIELDS = JAMB_SAMPLE_DATA.split('\n')[0].split(',')
     44
     45class FakeSite(dict):
     46    def getSiteManager(self):
     47        return object()
    2948
    3049class JAMBDataImporterTest(unittest.TestCase):
     
    3756                }
    3857            )
     58        self.workdir = tempfile.mkdtemp()
     59        self.csv_file = os.path.join(self.workdir, 'sampledata.csv')
     60        open(self.csv_file, 'wb').write(JAMB_SAMPLE_DATA)
    3961        return
    4062
    4163    def tearDown(self):
    42         pass
     64        shutil.rmtree(self.workdir)
     65        clearSite()
     66        return
    4367
    4468    def test_interface(self):
     
    7599        self.importer.delEntry(dict(reg_no='REG_NO_1'), self.site1)
    76100        assert 'REG_NO_1' not in self.site1['jambdata'].keys()
    77        
     101
     102    def test_import(self):
     103        # Do a real import
     104        # The following modules register important components for import
     105        # Registers converters...
     106        grok.testing.grok('waeup.sirp.utils.converters')
     107        # Registers the Applicant factory...
     108        grok.testing.grok('waeup.sirp.applicants.jambtables.applicants')
     109
     110        # Create a fake site to store datasets in...
     111        site = FakeSite()
     112        # The site must have a 'jambdata' entry...
     113        site['jambdata'] = dict()
     114        # Set the fake site as 'current' site object...
     115        setSite(site)
     116        self.importer.doImport(self.csv_file, HEADER_FIELDS)
     117        self.assertTrue(u'91100546DD' in site['jambdata'].keys())
     118
    78119def test_suite():
    79120    suite = unittest.TestSuite()
Note: See TracChangeset for help on using the changeset viewer.