Changeset 5742 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 13 Feb 2011, 01:25:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/tests/test_batching.py
r5730 r5742 20 20 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 ## 22 """Unit tests for the applicantimporter.22 """Unit tests for the JAMB data importer. 23 23 """ 24 24 25 import grok 26 import os 27 import shutil 28 import tempfile 25 29 import unittest 30 from zope.component.hooks import setSite, clearSite 26 31 from zope.interface import verify 27 32 from waeup.sirp.interfaces import IBatchProcessor 28 33 from waeup.sirp.applicants.jambtables import JAMBDataImporter 34 35 # Sample data we can use in tests... 36 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 37 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 38 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 39 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 40 ''' 41 42 # The header fields of the above CSV snippet 43 HEADER_FIELDS = JAMB_SAMPLE_DATA.split('\n')[0].split(',') 44 45 class FakeSite(dict): 46 def getSiteManager(self): 47 return object() 29 48 30 49 class JAMBDataImporterTest(unittest.TestCase): … … 37 56 } 38 57 ) 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) 39 61 return 40 62 41 63 def tearDown(self): 42 pass 64 shutil.rmtree(self.workdir) 65 clearSite() 66 return 43 67 44 68 def test_interface(self): … … 75 99 self.importer.delEntry(dict(reg_no='REG_NO_1'), self.site1) 76 100 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 78 119 def test_suite(): 79 120 suite = unittest.TestSuite()
Note: See TracChangeset for help on using the changeset viewer.