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

Implement HostelProcessor?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.