Changeset 7070


Ignore:
Timestamp:
11 Nov 2011, 07:44:46 (13 years ago)
Author:
Henrik Bettermann
Message:

Add more tests and increase test coverage.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/hostels
Files:
5 edited

Legend:

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

    r7068 r7070  
    289289        for bed_id in child_id:
    290290            message = self.context[bed_id].releaseBed()
    291             released.append('%s (%s)' % (bed_id,message))
     291            if message:
     292                released.append('%s (%s)' % (bed_id,message))
    292293        if len(released):
    293294            message = ', '.join(released)
    294295            self.flash('Successfully released beds: %s' % message)
    295296            write_log_message(self, 'released: %s' % message)
     297            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     298        else:
     299            self.flash('No allocated bed selected.')
    296300            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    297301        return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/container.py

    r6959 r7070  
    5555        """
    5656        user = get_current_principal()
    57         if user is None:
    58             user = 'system'
    59         else:
    60             user = user.id
     57        user = user.id
    6158        self.logger.info('%s - %s - %s - %s' % (
    6259                user, ob_class, target, comment))
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r7068 r7070  
    178178    def releaseBed(self):
    179179        if self.owner == NOT_OCCUPIED:
    180             return u'not occupied'
     180            return
    181181        else:
    182182            old_owner = self.owner
     
    186186                'configuration'].accommodation_session
    187187            try:
    188             #import pdb; pdb.set_trace()
    189188                bedticket = grok.getSite()['students'][old_owner][
    190189                              'accommodation'][str(accommodation_session)]
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r7068 r7070  
    283283        self.assertMatches(bedticket.bed_coordinates,
    284284          u' -- booking cancelled on <YYYY-MM-DD hh:mm:ss> --')
     285        # If we release a free be, nothing will happen
     286        ctrl = self.browser.getControl(name='val_id')
     287        ctrl.getControl(value='hall-1_A_101_D').selected = True
     288        self.browser.getControl("Release selected beds", index=0).click()
     289        self.assertMatches(
     290          '...No allocated bed selected...', self.browser.contents)
    285291        # Managers can manually allocate studenst after cancellation
    286292        self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A')
     
    288294        self.browser.getControl("Save").click()
    289295        self.assertMatches("...Form has been saved...", self.browser.contents)
     296        # If we open the same form again, we will be redirected to hostel
     297        # manage page. Beds must be released first before they can be
     298        # allocated to other students.
     299        self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A')
     300        self.assertEqual(self.browser.url,
     301            self.container_path + '/hall-1/@@manage#tab-2')
     302        # Updating the beds again will not affect the allocation and also
     303        # the bed numbering remains the same
     304        old_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
     305        old_owner = self.app['hostels']['hall-1']['hall-1_A_101_A'].owner
     306        self.browser.getControl("Update all beds").click()
     307        # 7 beds have been removed and re-added, 1 bed remains untouched
     308        expected = '...7 empty beds removed, 7 beds added, 0 occupied beds modified...'
     309        self.assertMatches(expected,self.browser.contents)
     310        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
     311        new_owner = self.app['hostels']['hall-1']['hall-1_A_101_A'].owner
     312        self.assertEqual(new_number, old_number)
     313        self.assertEqual(new_owner, old_owner)
     314        # If we change the bed type of an allocated bed, the modification will
     315        # be indicated
     316        hall.blocks_for_female = ['B']
     317        hall.blocks_for_male = ['A']
     318        self.browser.getControl("Update all beds").click()
     319        expected = '...7 empty beds removed, 7 beds added, ' + \
     320            '1 occupied beds modified (hall-1_A_101_A )...'
     321        self.assertMatches(expected,self.browser.contents)
     322        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
     323        # Also the number of the bed has changed.
     324        self.assertFalse(new_number == old_number)
    290325        # Remove entire hostel
    291326        self.browser.open(self.manage_container_path)
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py

    r7068 r7070  
    1919        students = catalog.searchResults(current_session=(
    2020            accommodation_session,accommodation_session))
    21         try:
    22             existing_students = [
    23                 context.__parent__[key].owner
    24                 for key in context.__parent__.keys()]
    25         except AttributeError:
    26             return {NOT_OCCUPIED:NOT_OCCUPIED}
     21        existing_students = [
     22            context.__parent__[key].owner
     23            for key in context.__parent__.keys()]
    2724        students = [student for student in students
    2825                      if not student.student_id in existing_students]
Note: See TracChangeset for help on using the changeset viewer.