Ignore:
Timestamp:
9 Nov 2011, 13:34:17 (13 years ago)
Author:
Henrik Bettermann
Message:

Add more tests.

browser.py: If student owns a bed, this bed will be taken (to be prepared for the upcoming student allocation feature), otherwise an empty bed is looked up.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
2 edited

Legend:

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

    r7059 r7060  
    12381238        if str(grok.getSite()[
    12391239                'configuration'].accommodation_session) in self.context.keys():
    1240             self.flash('You already booked a bed space for the current accommodation session.')
     1240            self.flash('You already booked a bed space in current accommodation session.')
    12411241            self.redirect(self.url(self.context))
    12421242            return
     
    12501250            self.flash('Activation code is invalid.')
    12511251            return
    1252         # Search a bed and exit if no bed is found or if the student
    1253         # has already booked a bed
     1252        # Search and book bed
    12541253        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
    12551254        entries = cat.searchResults(
    1256             bed_type=(acc_details['bt'],acc_details['bt']))
    1257         available_beds = [
    1258             entry for entry in entries if entry.owner == NOT_OCCUPIED]
    1259         if not available_beds:
    1260             self.flash('There is no free bed in your category %s.'
    1261                         % acc_details['bt'])
    1262             return
    1263         entries = cat.searchResults(
    12641255            owner=(student.student_id,student.student_id))
    1265         # Cannot happen but anyway ...
    12661256        if len(entries):
     1257            # If bed space has bee manually allocated use this bed
    12671258            bed = [entry for entry in entries][0]
    1268             self.flash('You already booked bed %s.'
    1269                         % bed.bed_id)
    1270             return
     1259        else:
     1260            # else search for other available beds
     1261            entries = cat.searchResults(
     1262                bed_type=(acc_details['bt'],acc_details['bt']))
     1263            available_beds = [
     1264                entry for entry in entries if entry.owner == NOT_OCCUPIED]
     1265            if available_beds:
     1266                bed = self.selectBed(available_beds)
     1267                bed.bookBed(student.student_id)
     1268            else:
     1269                self.flash('There is no free bed in your category %s.'
     1270                            % acc_details['bt'])
     1271                return
    12711272        # Mark pin as used (this also fires a pin related transition)
    12721273        if code.state == USED:
     
    12811282                self.flash('You are not the owner of this access code.')
    12821283                return
    1283         # Create bed ticket and book bed
     1284        # Create bed ticket
    12841285        bedticket = createObject(u'waeup.BedTicket')
    12851286        bedticket.booking_code = pin
    12861287        bedticket.booking_session = acc_details['booking_session']
    12871288        bedticket.bed_type = acc_details['bt']
    1288         bed = self.selectBed(available_beds)
    1289         bed.bookBed(student.student_id)
    12901289        bedticket.bed = bed
    12911290        hall_title = bed.__parent__.hostel_name
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7057 r7060  
    10041004        pin = self.app['accesscodes']['HOS-0'].keys()[0]
    10051005        ac = self.app['accesscodes']['HOS-0'][pin]
    1006         ac.owner = self.student_id
     1006        ac.owner = u'Anybody'
    10071007        parts = pin.split('-')[1:]
    10081008        sfeseries, sfenumber = parts
     
    10171017        self.assertMatches('...Activation Code:...',
    10181018                           self.browser.contents)
     1019        self.browser.getControl(name="ac_series").value = u'nonsense'
     1020        self.browser.getControl(name="ac_number").value = sfenumber
     1021        self.browser.getControl("Create bed ticket").click()
     1022        self.assertMatches('...Activation code is invalid...',
     1023                           self.browser.contents)
     1024        self.browser.getControl(name="ac_series").value = sfeseries
     1025        self.browser.getControl(name="ac_number").value = sfenumber
     1026        self.browser.getControl("Create bed ticket").click()
     1027        self.assertMatches('...You are not the owner of this access code...',
     1028                           self.browser.contents)
     1029        ac.owner = self.student_id
    10191030        self.browser.getControl(name="ac_series").value = sfeseries
    10201031        self.browser.getControl(name="ac_number").value = sfenumber
Note: See TracChangeset for help on using the changeset viewer.