Ignore:
Timestamp:
19 Sep 2012, 10:17:44 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement HostelProcessor?.

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  
    2222from zope.event import notify
    2323from zope.component import getUtility
     24from zope.component.interfaces import IFactory
    2425from datetime import datetime
    2526from waeup.kofa.utils.helpers import attrs_to_fields
     
    271272Bed = attrs_to_fields(Bed)
    272273
     274class 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
    273291@grok.subscribe(IBedTicket, grok.IObjectRemovedEvent)
    274292def handle_bedticket_removed(bedticket, event):
     
    279297        bedticket.bed.owner = NOT_OCCUPIED
    280298        notify(grok.ObjectModifiedEvent(bedticket.bed))
     299
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r9200 r9202  
    3737from waeup.kofa.hostels.container import HostelsContainer
    3838from waeup.kofa.hostels.hostel import Hostel, Bed
     39from waeup.kofa.hostels.batching import HostelProcessor
    3940from waeup.kofa.hostels.export import BedExporter, HostelExporter
    4041from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase)
     
    4243from waeup.kofa.students.accommodation import BedTicket
    4344from waeup.kofa.university.department import Department
     45
     46HOSTEL_SAMPLE_DATA = open(
     47    os.path.join(os.path.dirname(__file__), 'sample_hostel_data.csv'),
     48    'rb').read()
     49
     50HOSTEL_HEADER_FIELDS = HOSTEL_SAMPLE_DATA.split(
     51    '\n')[0].split(',')
    4452
    4553class HostelsContainerTestCase(FunctionalTestCase):
     
    158166        self.browser = Browser()
    159167        self.browser.handleErrors = False
     168
     169        self.logfile = os.path.join(
     170            self.app['datacenter'].storage, 'logs', 'hostels.log')
    160171
    161172    def tearDown(self):
     
    381392        self.assertEqual(len(results), 0)
    382393        # 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()
    386395        self.assertTrue('INFO - zope.mgr - hostels.browser.HostelManageFormPage'
    387396                        ' - hall-1 - cleared' in logcontent)
     
    424433            )
    425434        return
     435
     436class 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.