Ignore:
Timestamp:
25 Jan 2023, 08:52:51 (22 months ago)
Author:
Henrik Bettermann
Message:

Allow beds to be blocked so that no student can be allocated to such a bed space (in contrast to reserved beds)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r17176 r17313  
    3131from zope.security.interfaces import Unauthorized
    3232from zope.catalog.interfaces import ICatalog
    33 from zope.component import queryUtility, getUtility
     33from zope.component import queryUtility, getUtility, createObject
    3434from waeup.kofa.app import University
    3535from waeup.kofa.hostels.interfaces import (
     
    5454BED_SAMPLE_DATA = open(
    5555    os.path.join(os.path.dirname(__file__), 'sample_bed_data.csv'),
     56    'rb').read()
     57
     58BED_SAMPLE_DATA_2 = open(
     59    os.path.join(os.path.dirname(__file__), 'sample_bed_data_2.csv'),
    5660    'rb').read()
    5761
     
    396400             (u'hall-1_A_101_C', u'regular_female_reserved'),
    397401             (u'hall-1_A_101_D', u'regular_female_reserved')])
     402        # Block beds.
     403        self.browser.getControl("Switch blockade", index=0).click()
     404        self.assertTrue('No item selected' in self.browser.contents)
     405        ctrl = self.browser.getControl(name='val_id')
     406        ctrl.getControl(value='hall-1_A_101_A').selected = True
     407        ctrl.getControl(value='hall-1_A_101_B').selected = True
     408        ctrl.getControl(value='hall-1_A_101_C').selected = True
     409        ctrl.getControl(value='hall-1_A_101_D').selected = True
     410        self.browser.getControl("Switch blockade", index=0).click()
     411        self.assertTrue('Successfully switched beds: hall-1_A_101_A (blocked)'
     412            in self.browser.contents)
     413        self.assertEqual(self.app['hostels']['hall-1'][
     414            'hall-1_A_101_D'].bed_type, 'regular_female_blocked')
     415        # The catalog has been updated.
     416        results = cat.searchResults(
     417            bed_type=('regular_female_all', 'regular_female_all'))
     418        results = [(x.bed_id, x.bed_type) for x in results]
     419        self.assertEqual(results,
     420            [(u'hall-1_A_101_E', u'regular_female_all'),
     421             (u'hall-1_B_101_D', u'regular_female_all'),
     422             (u'hall-1_B_101_E', u'regular_female_all')])
     423        results = cat.searchResults(
     424            bed_type=('regular_female_blocked', 'regular_female_blocked'))
     425        results = [(x.bed_id, x.bed_type) for x in results]
     426        self.assertEqual(results,
     427            [(u'hall-1_A_101_A', u'regular_female_blocked'),
     428             (u'hall-1_A_101_B', u'regular_female_blocked'),
     429             (u'hall-1_A_101_C', u'regular_female_blocked'),
     430             (u'hall-1_A_101_D', u'regular_female_blocked')])
    398431        # Change hostel configuration with one bed booked.
    399432        hall['hall-1_A_101_E'].owner = u'anyid'
     
    672705        logcontent = open(self.logfile).read()
    673706        self.assertEqual(
    674             'owner,bed_id,hostel_id,reserved,--ERRORS--\r\n'
    675             '<IGNORE>,block-a-upper-hostel_A_101_C,block-a-upper-hostel,2,'
     707            'owner,bed_id,hostel_id,reserved,blocked,--ERRORS--\r\n'
     708            '<IGNORE>,block-a-upper-hostel_A_101_C,block-a-upper-hostel,2,0,'
    676709            'reserved: invalid value\r\n'
    677             'K999,block-a-upper-hostel_A_101_E,block-a-upper-hostel,0,'
     710            'K999,block-a-upper-hostel_A_101_E,block-a-upper-hostel,0,0,'
    678711            'owner: student does not exist\r\n',
    679712            fail_file_content)
    680713        self.assertTrue(
    681714            'system - Bed Processor (update only) - sample_bed_data - '
    682             'block-a-upper-hostel_A_101_A - updated: nothing'
     715            'block-a-upper-hostel_A_101_A - updated: blocked'
    683716            in logcontent)
    684717        self.assertTrue(
     
    697730                    ['block-a-upper-hostel_A_101_B'].bed_type,
    698731                    'regular_female_reserved')
     732        # Add another student K1000001
     733        student = createObject('waeup.Student')
     734        student.firstname = u'Claus'
     735        student.lastname = u'Tester'
     736        self.app['students'].addStudent(student)
     737        # Try to allocate this student to a blocked bed
     738
     739        open(self.csv_file, 'wb').write(BED_SAMPLE_DATA_2)
     740        num, num_warns, fin_file, fail_file = self.processor.doImport(
     741            self.csv_file, BED_HEADER_FIELDS, 'update')
     742        fail_file_content = open(fail_file).read()
     743        self.assertEqual(
     744            'owner,bed_id,hostel_id,reserved,blocked,--ERRORS--\r\n'
     745            'K1000001,block-a-upper-hostel_A_101_A,block-a-upper-hostel,'
     746            '<IGNORE>,<IGNORE>,Bed is blocked.\r\n',
     747            fail_file_content)
    699748        shutil.rmtree(os.path.dirname(fin_file))
    700749        shutil.rmtree(self.workdir)
Note: See TracChangeset for help on using the changeset viewer.