Ignore:
Timestamp:
28 Oct 2012, 20:12:11 (12 years ago)
Author:
Henrik Bettermann
Message:

Add missing catalog modifier and add some kind of regression test that this never happens again.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/hostels
Files:
2 edited

Legend:

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

    r9414 r9448  
    127127                                bed.bed_type = bt
    128128                                modified_counter += 1
    129                                 modified_beds += '%s ' % uid
     129                                modified_beds += '%s, ' % uid
     130                                notify(grok.ObjectModifiedEvent(bed))
    130131                        else:
    131132                            bed = Bed()
     
    243244            message = _(u'reserved')
    244245        self.bed_type = bt
     246        notify(grok.ObjectModifiedEvent(self))
    245247        return message
    246248
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r9423 r9448  
    253253        results = cat.searchResults(
    254254            bed_type=('regular_female_all', 'regular_female_all'))
    255         results = [x for x in results]
    256         assert len(results) == 4
     255        results = [(x.bed_id, x.bed_type) for x in results]
     256        self.assertEqual(results,
     257            [(u'hall-1_A_101_D', u'regular_female_all'),
     258             (u'hall-1_A_101_E', u'regular_female_all'),
     259             (u'hall-1_B_101_D', u'regular_female_all'),
     260             (u'hall-1_B_101_E', u'regular_female_all')])
     261
    257262        # Reserve bed
    258263        self.browser.getControl("Switch reservation", index=0).click()
     
    266271        self.assertTrue('Successfully switched beds: hall-1_A_101_A (reserved)'
    267272            in self.browser.contents)
    268         assert self.app['hostels']['hall-1'][
    269             'hall-1_A_101_D'].bed_type == 'regular_female_reserved'
     273        self.assertEqual(self.app['hostels']['hall-1'][
     274            'hall-1_A_101_D'].bed_type, 'regular_female_reserved')
    270275        self.assertTrue('<div>A_101_A</div>' in self.browser.contents)
    271 
    272         # Change hostel configuration
     276        # The catalog has been updated
     277        results = cat.searchResults(
     278            bed_type=('regular_female_all', 'regular_female_all'))
     279        results = [(x.bed_id, x.bed_type) for x in results]
     280        self.assertEqual(results,
     281            [(u'hall-1_A_101_E', u'regular_female_all'),
     282             (u'hall-1_B_101_D', u'regular_female_all'),
     283             (u'hall-1_B_101_E', u'regular_female_all')])
     284        results = cat.searchResults(
     285            bed_type=('regular_female_reserved', 'regular_female_reserved'))
     286        results = [(x.bed_id, x.bed_type) for x in results]
     287        self.assertEqual(results,
     288            [(u'hall-1_A_101_A', u'regular_female_reserved'),
     289             (u'hall-1_A_101_B', u'regular_female_reserved'),
     290             (u'hall-1_A_101_C', u'regular_female_reserved'),
     291             (u'hall-1_A_101_D', u'regular_female_reserved')])
     292
     293        # Change hostel configuration with one bed booked
     294        hall['hall-1_A_101_E'].owner = u'anyid'
     295        notify(grok.ObjectModifiedEvent(hall['hall-1_A_101_E']))
     296        hall.beds_for_fresh = ['A', 'E']
    273297        hall.beds_for_all = ['D']
    274298        self.browser.getControl("Update all beds").click()
    275         expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...'
     299        expected = '...9 empty beds removed, 9 beds added, 1 occupied beds modified...'
    276300        self.assertMatches(expected,self.browser.contents)
     301        # Updating beds (including booked beds!) does update catalog
    277302        results = cat.searchResults(
    278303            bed_type=('regular_female_all', 'regular_female_all'))
    279         results = [x for x in results]
    280         assert len(results) == 1
     304        results = [(x.bed_id, x.bed_type) for x in results]
     305        self.assertEqual(results,
     306            [(u'hall-1_B_101_D', u'regular_female_all'),])
    281307        # Unreserve bed
    282308        ctrl = self.browser.getControl(name='val_id')
     
    348374        old_owner = self.app['hostels']['hall-1']['hall-1_A_101_A'].owner
    349375        self.browser.getControl("Update all beds").click()
    350         # 7 beds have been removed and re-added, 1 bed remains untouched
    351         expected = '...7 empty beds removed, 7 beds added, 0 occupied beds modified...'
     376        # 8 beds have been removed and re-added, 2 beds remains untouched
     377        # because they are occupied
     378        expected = '...8 empty beds removed, 8 beds added, 0 occupied beds modified...'
    352379        self.assertMatches(expected,self.browser.contents)
    353380        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
     
    360387        hall.blocks_for_male = ['A']
    361388        self.browser.getControl("Update all beds").click()
    362         expected = '...7 empty beds removed, 7 beds added, ' + \
    363             '1 occupied beds modified (hall-1_A_101_A )...'
     389        expected = '...8 empty beds removed, 8 beds added, ' + \
     390            '2 occupied beds modified (hall-1_A_101_A, hall-1_A_101_E, )...'
    364391        self.assertMatches(expected,self.browser.contents)
    365392        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
     
    368395        # The number of occupied beds are displayed on container page.
    369396        self.browser.open(self.container_path)
    370         self.assertTrue('1 of 8' in self.browser.contents)
     397        self.assertTrue('2 of 10' in self.browser.contents)
    371398        # Remove entire hostel
    372399        self.browser.open(self.manage_container_path)
Note: See TracChangeset for help on using the changeset viewer.