Ignore:
Timestamp:
2 Nov 2011, 11:23:55 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement logging for reservation switch.

Fix switchReservation.

Improve testing.

File:
1 edited

Legend:

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

    r6985 r6988  
    1515##
    1616"""
    17 Tests for hostels. and their UI components
     17Tests for hostels and their UI components.
    1818"""
    1919import shutil
     
    157157        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    158158        self.assertTrue('Hostel created' in self.browser.contents)
     159        self.browser.open(self.container_path + '/addhostel')
     160        self.browser.getControl("Create hostel").click()
     161        self.assertTrue('The hostel already exists' in self.browser.contents)
    159162        hall = self.app['hostels']['hall-1']
    160163        hall.blocks_for_female = ['A','B']
     
    172175        self.assertTrue(len(hall.blocks_for_female) == 0)
    173176        hall.blocks_for_female = ['A','B']
    174         hall.beds_for_fresh = ['A','B']
     177        hall.beds_for_fresh = ['A']
     178        hall.beds_for_returning = ['B']
     179        hall.beds_for_final = ['C']
    175180        hall.beds_for_all = ['D','E']
    176181        self.browser.getControl("Update all beds").click()
    177         expected = '...0 empty beds removed, 8 beds added, 0 occupied beds modified...'
     182        expected = '...0 empty beds removed, 10 beds added, 0 occupied beds modified ()...'
    178183        self.assertMatches(expected,self.browser.contents)
    179184        cat = queryUtility(ICatalog, name='beds_catalog')
    180185        results = cat.searchResults(
    181186            bed_type=('regular_female_all', 'regular_female_all'))
    182         #import pdb; pdb.set_trace()
    183187        results = [x for x in results]
    184188        assert len(results) == 4
    185         # Set bed reserved
    186         ctrl = self.browser.getControl(name='val_id')
     189        # Reserve bed
     190        self.browser.getControl("Switch reservation", index=0).click()
     191        self.assertTrue('No item selected' in self.browser.contents)
     192        ctrl = self.browser.getControl(name='val_id')
     193        ctrl.getControl(value='hall-1_A_101_A').selected = True
     194        ctrl.getControl(value='hall-1_A_101_B').selected = True
     195        ctrl.getControl(value='hall-1_A_101_C').selected = True
    187196        ctrl.getControl(value='hall-1_A_101_D').selected = True
    188197        self.browser.getControl("Switch reservation", index=0).click()
    189         self.assertTrue('Successfully switched beds: hall-1_A_101_D'
     198        self.assertTrue('Successfully switched beds: hall-1_A_101_A (reserved)'
    190199            in self.browser.contents)
    191         assert self.app[
    192             'hostels'][
    193             'hall-1'][
     200        assert self.app['hostels']['hall-1'][
    194201            'hall-1_A_101_D'].bed_type == 'regular_female_reserved'
    195         expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_D"  />'
     202        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_A"  />'
    196203        self.assertTrue(expected in self.browser.contents)
    197         # Release bed
     204        # Provoke exception
     205        self.app['hostels']['hall-1']['hall-1_A_101_D'].bed_type = u'nonsense'
    198206        ctrl = self.browser.getControl(name='val_id')
    199207        ctrl.getControl(value='hall-1_A_101_D').selected = True
    200208        self.browser.getControl("Switch reservation", index=0).click()
    201         assert self.app[
    202             'hostels'][
    203             'hall-1'][
    204             'hall-1_A_101_D'].bed_type == 'regular_female_all'
    205         self.assertFalse(expected in self.browser.contents)
     209        self.assertMatches(
     210            '...need more than 1 value to unpack...', self.browser.contents)
     211        self.app['hostels']['hall-1'][
     212            'hall-1_A_101_D'].bed_type = u'regular_female_reserved'
    206213        # Change hostel configuration
    207214        hall.beds_for_all = ['D']
    208215        self.browser.getControl("Update all beds").click()
    209         expected = '...8 empty beds removed, 6 beds added, 0 occupied beds modified...'
     216        expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...'
    210217        self.assertMatches(expected,self.browser.contents)
    211218        results = cat.searchResults(
    212219            bed_type=('regular_female_all', 'regular_female_all'))
    213220        results = [x for x in results]
    214         assert len(results) == 2
     221        assert len(results) == 1
     222        # Unreserve bed
     223        ctrl = self.browser.getControl(name='val_id')
     224        ctrl.getControl(value='hall-1_A_101_A').selected = True
     225        ctrl.getControl(value='hall-1_A_101_B').selected = True
     226        ctrl.getControl(value='hall-1_A_101_C').selected = True
     227        ctrl.getControl(value='hall-1_A_101_D').selected = True
     228        self.browser.getControl("Switch reservation", index=0).click()
     229        assert self.app['hostels']['hall-1'][
     230            'hall-1_A_101_D'].bed_type == 'regular_female_all'
     231        self.assertFalse(expected in self.browser.contents)
    215232        # Remove entire hostel
    216233        self.browser.open(self.manage_container_path)
Note: See TracChangeset for help on using the changeset viewer.