Changeset 9202 for main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
- Timestamp:
- 19 Sep 2012, 10:17:44 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r9200 r9202 37 37 from waeup.kofa.hostels.container import HostelsContainer 38 38 from waeup.kofa.hostels.hostel import Hostel, Bed 39 from waeup.kofa.hostels.batching import HostelProcessor 39 40 from waeup.kofa.hostels.export import BedExporter, HostelExporter 40 41 from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase) … … 42 43 from waeup.kofa.students.accommodation import BedTicket 43 44 from waeup.kofa.university.department import Department 45 46 HOSTEL_SAMPLE_DATA = open( 47 os.path.join(os.path.dirname(__file__), 'sample_hostel_data.csv'), 48 'rb').read() 49 50 HOSTEL_HEADER_FIELDS = HOSTEL_SAMPLE_DATA.split( 51 '\n')[0].split(',') 44 52 45 53 class HostelsContainerTestCase(FunctionalTestCase): … … 158 166 self.browser = Browser() 159 167 self.browser.handleErrors = False 168 169 self.logfile = os.path.join( 170 self.app['datacenter'].storage, 'logs', 'hostels.log') 160 171 161 172 def tearDown(self): … … 381 392 self.assertEqual(len(results), 0) 382 393 # Both actions have been logged. 383 logfile = os.path.join( 384 self.app['datacenter'].storage, 'logs', 'hostels.log') 385 logcontent = open(logfile).read() 394 logcontent = open(self.logfile).read() 386 395 self.assertTrue('INFO - zope.mgr - hostels.browser.HostelManageFormPage' 387 396 ' - hall-1 - cleared' in logcontent) … … 424 433 ) 425 434 return 435 436 class HostelProcessorTest(HostelsFullSetup): 437 438 layer = FunctionalLayer 439 440 def test_import(self): 441 self.processor = HostelProcessor() 442 self.workdir = tempfile.mkdtemp() 443 self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv') 444 open(self.csv_file, 'wb').write(HOSTEL_SAMPLE_DATA) 445 num, num_warns, fin_file, fail_file = self.processor.doImport( 446 self.csv_file, HOSTEL_HEADER_FIELDS) 447 self.assertEqual(num_warns,0) 448 self.assertEqual(len(self.app['hostels'].keys()), 11) # including hall-x 449 self.assertEqual(self.app['hostels'][ 450 'block-a-upper-hostel'].hostel_id,'block-a-upper-hostel') 451 self.assertEqual(self.app['hostels'][ 452 'block-a-upper-hostel'].beds_for_final, ['A', 'B']) 453 logcontent = open(self.logfile).read() 454 self.assertTrue( 455 "Hostel Processor - block-a-upper-hostel - " 456 "Record updated: beds_for_pre=['G'], floors_per_block=1, " 457 "beds_for_final=['A', 'B'], rooms_per_floor=32, " 458 "blocks_for_male=[], hostel_id=block-a-upper-hostel, " 459 "sort_id=20, beds_for_returning=['C', 'D'], " 460 "hostel_name=Block A Upper Hostel, beds_for_fresh=['E', 'F'], " 461 "blocks_for_female=['A'], beds_for_all=[], beds_reserved=[]" 462 in logcontent) 463 shutil.rmtree(os.path.dirname(fin_file)) 464 return
Note: See TracChangeset for help on using the changeset viewer.