- Timestamp:
- 19 Sep 2012, 10:17:44 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r9199 r9202 22 22 from zope.event import notify 23 23 from zope.component import getUtility 24 from zope.component.interfaces import IFactory 24 25 from datetime import datetime 25 26 from waeup.kofa.utils.helpers import attrs_to_fields … … 271 272 Bed = attrs_to_fields(Bed) 272 273 274 class HostelFactory(grok.GlobalUtility): 275 """A factory for hostels. 276 277 We need this factory for the hostel processor. 278 """ 279 grok.implements(IFactory) 280 grok.name(u'waeup.Hostel') 281 title = u"Create a new hostel.", 282 description = u"This factory instantiates new hostel instances." 283 284 def __call__(self, *args, **kw): 285 return Hostel() 286 287 def getInterfaces(self): 288 return implementedBy(Hostel) 289 290 273 291 @grok.subscribe(IBedTicket, grok.IObjectRemovedEvent) 274 292 def handle_bedticket_removed(bedticket, event): … … 279 297 bedticket.bed.owner = NOT_OCCUPIED 280 298 notify(grok.ObjectModifiedEvent(bedticket.bed)) 299 -
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.