Ignore:
Timestamp:
7 Nov 2011, 09:42:01 (13 years ago)
Author:
Henrik Bettermann
Message:

Add tests for student accommodation booking.

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

Legend:

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

    r7015 r7017  
    10321032    title = 'Accommodation'
    10331033    pnav = 4
    1034     officers_only_actions = ['delBedTickets']
     1034    officers_only_actions = ['Remove selected']
    10351035
    10361036    def formatDatetime(self,datetimeobj):
     
    10491049        return
    10501050
     1051    @property
     1052    def is_student(self):
     1053        prm = get_principal_role_manager()
     1054        roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
     1055        return 'waeup.Student' in roles
     1056
    10511057    @grok.action('Remove selected')
    10521058    def delBedTickets(self, **data):
     1059        if self.is_student:
     1060            self.flash('You are not allowed to remove bed tickets.')
     1061            self.redirect(self.url(self.context))
     1062            return
    10531063        form = self.request.form
    10541064        if form.has_key('val_id'):
     
    10741084        return
    10751085
    1076     def isStudent(self):
    1077         prm = get_principal_role_manager()
    1078         roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
    1079         return 'waeup.Student' in roles
    1080 
    10811086    @property
    10821087    def selected_actions(self):
    10831088        sa = self.actions
    1084         if self.isStudent():
     1089        if self.is_student:
    10851090            sa = [action for action in self.actions
    1086                   if not action in officers_only_actions]
     1091                  if not action.label in self.officers_only_actions]
    10871092        return sa
    10881093
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/accommodationmanagepage.pt

    r7009 r7017  
    1818    <thead>
    1919    <tr>
    20       <th>&nbsp;</th>
     20      <th tal:condition="not: view/is_student">&nbsp;</th>
    2121      <th>Session</th>
    2222      <th>Booking Date</th>
     
    2727    <tbody>
    2828      <tr tal:repeat="cl context/values">
    29          <td>
     29         <td tal:condition="not: view/is_student">
    3030          <input type="checkbox"
    3131                 name="val_id"
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7015 r7017  
    751751
    752752    def test_student_payments(self):
    753         # Set up SessionConfiguration object
     753        # Login
    754754        self.browser.open(self.login_path)
    755755        self.browser.getControl(name="form.login").value = self.student_id
     
    915915
    916916    def test_student_accommodation(self):
    917         return
     917        # Login
     918        self.browser.open(self.login_path)
     919        self.browser.getControl(name="form.login").value = self.student_id
     920        self.browser.getControl(name="form.password").value = 'spwd'
     921        self.browser.getControl("Login").click()
     922
     923        # Students can add online booking fee payment tickets and open the
     924        # callback view (see test_manage_payments)
     925        self.browser.getLink("Payments").click()
     926        self.browser.getControl("Add online payment ticket").click()
     927        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
     928        self.browser.getControl("Create ticket").click()
     929        ctrl = self.browser.getControl(name='val_id')
     930        value = ctrl.options[0]
     931        self.browser.getLink(value).click()
     932        self.browser.open(self.browser.url + '/callback')
     933        # The new HOS-0 pin has been created
     934        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
     935        pin = self.app['accesscodes']['HOS-0'].keys()[0]
     936        ac = self.app['accesscodes']['HOS-0'][pin]
     937        ac.owner = self.student_id
     938        parts = pin.split('-')[1:]
     939        sfeseries, sfenumber = parts
     940        # Students can use HOS code and book a bed space with it
     941        self.browser.open(self.acco_student_path)
     942        self.browser.getLink("Book accommodation").click()
     943        self.assertMatches('...You are in the wrong...',
     944                           self.browser.contents)
     945        IWorkflowInfo(self.student).fireTransition('admit')
     946        self.browser.getLink("Book accommodation").click()
     947        self.assertMatches('...Activation Code:...',
     948                           self.browser.contents)
     949        self.browser.getControl(name="ac_series").value = sfeseries
     950        self.browser.getControl(name="ac_number").value = sfenumber
     951        self.browser.getControl("Create bed ticket").click()
     952        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     953                           self.browser.contents)
     954        # Bed has been allocated
     955        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
     956        self.assertTrue(bed.owner == self.student_id)
     957        # BedTicketAddPage is now blocked
     958        self.browser.getLink("Book accommodation").click()
     959        self.assertMatches('...You already booked a bed space...',
     960            self.browser.contents)
     961        # The bed ticket displays the data correctly
     962        self.browser.open(self.acco_student_path + '/2004')
     963        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     964                           self.browser.contents)
     965        self.assertMatches('...2004/2005...', self.browser.contents)
     966        self.assertMatches('...regular_male_fr...', self.browser.contents)
     967        self.assertMatches('...%s...' % pin, self.browser.contents)
     968        # Students can't relocate themselves
     969        self.assertFalse('Relocate' in self.browser.contents)
     970        relocate_path = self.acco_student_path + '/2004/relocate'
     971        self.assertRaises(
     972            Unauthorized, self.browser.open, relocate_path)
     973        # Students can't the Remove button and check boxes
     974        self.browser.open(self.acco_student_path)
     975        self.assertFalse('Remove' in self.browser.contents)
     976        self.assertFalse('val_id' in self.browser.contents)
     977        return
Note: See TracChangeset for help on using the changeset viewer.