Ignore:
Timestamp:
6 Sep 2015, 07:13:59 (9 years ago)
Author:
Henrik Bettermann
Message:

Remove temporary solution for payment of maintenance fee and revert to original bed allocation.

Copy and adjust test_student_accommodation method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r13110 r13251  
    1919import shutil
    2020import tempfile
     21import pytz
     22from datetime import datetime, timedelta, date
    2123from StringIO import StringIO
    2224from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
    2325from zope.securitypolicy.interfaces import IPrincipalRoleManager
     26from zope.security.interfaces import Unauthorized
    2427from zope.component.hooks import setSite, clearSite
    2528from zope.component import getUtility, createObject
     
    3033from waeup.kofa.students.tests.test_browser import StudentsFullSetup
    3134from waeup.kofa.students.accommodation import BedTicket
     35from waeup.kofa.hostels.hostel import Hostel, Bed, NOT_OCCUPIED
    3236from waeup.kofa.testing import FunctionalTestCase
    3337from waeup.kofa.browser.tests.test_pdf import samples_dir
     
    4751    def setUp(self):
    4852        super(StudentUITests, self).setUp()
    49 
    50         bedticket = BedTicket()
    51         bedticket.booking_session = 2004
    52         bedticket.bed_type = u'any bed type'
    53         bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
    54         bedticket.bed_coordinates = u'My bed coordinates'
    55         self.student['accommodation'].addBedTicket(bedticket)
    5653
    5754    def test_next_session_allowed(self):
     
    253250                           self.browser.contents)
    254251        self.browser.open(self.payments_path + '/addop')
    255         self.browser.getControl(
    256             name="form.p_category").value = ['tempmaint_1']
    257         self.browser.getControl("Create ticket").click()
    258         self.assertMatches('...You have not yet paid the hostel application fee...',
    259                            self.browser.contents)
    260         self.browser.open(self.payments_path + '/addop')
    261         self.browser.getControl(name="form.p_category").value = ['hostel_application']
    262         self.browser.getControl("Create ticket").click()
    263         self.assertMatches('...ticket created...',
    264                            self.browser.contents)
    265         ha_ticket = self.student['payments'].values()[2]
    266         ha_ticket.approve()
    267         self.browser.open(self.payments_path + '/addop')
    268         self.browser.getControl(
    269             name="form.p_category").value = ['tempmaint_1']
    270         self.browser.getControl("Create ticket").click()
    271         self.assertMatches('...ticket created...',
    272                            self.browser.contents)
    273         self.browser.open(self.payments_path + '/addop')
    274         self.browser.getControl(
    275             name="form.p_category").value = ['tempmaint_2']
    276         self.browser.getControl("Create ticket").click()
    277         self.assertMatches('...ticket created...',
    278                            self.browser.contents)
    279         self.browser.open(self.payments_path + '/addop')
    280         self.browser.getControl(
    281             name="form.p_category").value = ['tempmaint_3']
    282         self.browser.getControl("Create ticket").click()
    283         self.assertMatches('...ticket created...',
    284                            self.browser.contents)
    285         self.browser.open(self.payments_path + '/addop')
     252        #self.browser.getControl(
     253        #    name="form.p_category").value = ['tempmaint_1']
     254        #self.browser.getControl("Create ticket").click()
     255        #self.assertMatches('...You have not yet paid the hostel application fee...',
     256        #                   self.browser.contents)
     257        #self.browser.open(self.payments_path + '/addop')
     258        #self.browser.getControl(name="form.p_category").value = ['hostel_application']
     259        #self.browser.getControl("Create ticket").click()
     260        #self.assertMatches('...ticket created...',
     261        #                   self.browser.contents)
     262        #ha_ticket = self.student['payments'].values()[2]
     263        #ha_ticket.approve()
     264        #self.browser.open(self.payments_path + '/addop')
     265        #self.browser.getControl(
     266        #    name="form.p_category").value = ['tempmaint_1']
     267        #self.browser.getControl("Create ticket").click()
     268        #self.assertMatches('...ticket created...',
     269        #                   self.browser.contents)
     270        #self.browser.open(self.payments_path + '/addop')
     271        #self.browser.getControl(
     272        #    name="form.p_category").value = ['tempmaint_2']
     273        #self.browser.getControl("Create ticket").click()
     274        #self.assertMatches('...ticket created...',
     275        #                   self.browser.contents)
     276        #self.browser.open(self.payments_path + '/addop')
     277        #self.browser.getControl(
     278        #    name="form.p_category").value = ['tempmaint_3']
     279        #self.browser.getControl("Create ticket").click()
     280        #self.assertMatches('...ticket created...',
     281        #                   self.browser.contents)
     282        #self.browser.open(self.payments_path + '/addop')
    286283        # We can't test clearance payment ticket creation at the moment,
    287284        # since Uniben decided to deactivate clearance for ug students.
     
    604601        self.assertEqual(error, None)
    605602
    606         #error, payment = utils.setPaymentDetails('hostel_maintenance',
     603        bedticket = BedTicket()
     604        bedticket.booking_session = 2004
     605        bedticket.bed_type = u'any bed type'
     606        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
     607        bedticket.bed_coordinates = u'My bed coordinates'
     608        self.student['accommodation'].addBedTicket(bedticket)
     609
     610        error, payment = utils.setPaymentDetails('hostel_maintenance',
     611            self.student, None, None)
     612        self.assertEqual(payment.p_level, 100)
     613        self.assertEqual(payment.p_session, 2004)
     614        self.assertEqual(payment.amount_auth, 876.0)
     615        self.assertEqual(payment.p_item, u'My bed coordinates')
     616        self.assertEqual(error, None)
     617
     618        error, payment = utils.setPaymentDetails('bed_allocation',
     619            self.student, None, None)
     620        self.assertEqual(payment.p_level, 100)
     621        self.assertEqual(payment.p_session, 2004)
     622        self.assertEqual(payment.amount_auth, 150.0)
     623        self.assertEqual(payment.p_item, u'regular_male_re')
     624        self.assertEqual(error, None)
     625
     626        #error, payment = utils.setPaymentDetails('hostel_application',
    607627        #    self.student, None, None)
    608628        #self.assertEqual(payment.p_level, 100)
    609629        #self.assertEqual(payment.p_session, 2004)
    610         #self.assertEqual(payment.amount_auth, 180.0)
     630        #self.assertEqual(payment.amount_auth, 1000.0)
    611631        #self.assertEqual(payment.p_item, u'')
    612632        #self.assertEqual(error, None)
    613633
    614         #error, payment = utils.setPaymentDetails('bed_allocation',
     634        #payment.approve()
     635        #self.student['payments'][payment.p_id] = payment
     636
     637        #error, payment = utils.setPaymentDetails('tempmaint_1',
    615638        #    self.student, None, None)
    616639        #self.assertEqual(payment.p_level, 100)
    617640        #self.assertEqual(payment.p_session, 2004)
    618         #self.assertEqual(payment.amount_auth, 150.0)
    619         #self.assertEqual(payment.p_item, u'')
     641        #self.assertEqual(payment.amount_auth, 8150.0)
     642        #self.assertEqual(payment.p_item, u'Hall 1-4 M/F Ekehuan')
    620643        #self.assertEqual(error, None)
    621644
    622         error, payment = utils.setPaymentDetails('hostel_application',
    623             self.student, None, None)
    624         self.assertEqual(payment.p_level, 100)
    625         self.assertEqual(payment.p_session, 2004)
    626         self.assertEqual(payment.amount_auth, 1000.0)
    627         self.assertEqual(payment.p_item, u'')
    628         self.assertEqual(error, None)
    629 
    630         payment.approve()
    631         self.student['payments'][payment.p_id] = payment
    632 
    633         error, payment = utils.setPaymentDetails('tempmaint_1',
    634             self.student, None, None)
    635         self.assertEqual(payment.p_level, 100)
    636         self.assertEqual(payment.p_session, 2004)
    637         self.assertEqual(payment.amount_auth, 8150.0)
    638         self.assertEqual(payment.p_item, u'Hall 1-4 M/F Ekehuan')
    639         self.assertEqual(error, None)
    640 
    641         error, payment = utils.setPaymentDetails('tempmaint_2',
    642             self.student, None, None)
    643         self.assertEqual(payment.p_level, 100)
    644         self.assertEqual(payment.p_session, 2004)
    645         self.assertEqual(payment.amount_auth, 12650.0)
    646         self.assertEqual(payment.p_item, u'Hall 5 M/F')
    647         self.assertEqual(error, None)
    648 
    649         error, payment = utils.setPaymentDetails('tempmaint_3',
    650             self.student, None, None)
    651         self.assertEqual(payment.p_level, 100)
    652         self.assertEqual(payment.p_session, 2004)
    653         self.assertEqual(payment.amount_auth, 9650.0)
    654         self.assertEqual(payment.p_item, u'Clinical Hostel')
    655         self.assertEqual(error, None)
     645        #error, payment = utils.setPaymentDetails('tempmaint_2',
     646        #    self.student, None, None)
     647        #self.assertEqual(payment.p_level, 100)
     648        #self.assertEqual(payment.p_session, 2004)
     649        #self.assertEqual(payment.amount_auth, 12650.0)
     650        #self.assertEqual(payment.p_item, u'Hall 5 M/F')
     651        #self.assertEqual(error, None)
     652
     653        #error, payment = utils.setPaymentDetails('tempmaint_3',
     654        #    self.student, None, None)
     655        #self.assertEqual(payment.p_level, 100)
     656        #self.assertEqual(payment.p_session, 2004)
     657        #self.assertEqual(payment.amount_auth, 9650.0)
     658        #self.assertEqual(payment.p_item, u'Clinical Hostel')
     659        #self.assertEqual(error, None)
    656660
    657661        error, payment = utils.setPaymentDetails('transfer',
     
    901905        open(path, 'wb').write(self.browser.contents)
    902906        print "Sample PDF transcript.pdf written to %s" % path
     907
     908    def test_student_accommodation(self):
     909        self.browser.open(self.login_path)
     910        self.browser.getControl(name="form.login").value = self.student_id
     911        self.browser.getControl(name="form.password").value = 'spwd'
     912        self.browser.getControl("Login").click()
     913        # Students can add online booking fee payment tickets and open the
     914        # callback view (see test_manage_payments).
     915        self.browser.getLink("Payments").click()
     916        self.browser.getLink("Add current session payment ticket").click()
     917        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
     918        self.browser.getControl("Create ticket").click()
     919        ctrl = self.browser.getControl(name='val_id')
     920        value = ctrl.options[0]
     921        self.browser.getLink(value).click()
     922        p_ticket = self.student['payments'].values()[0]
     923        p_ticket.approveStudentPayment()
     924        # The new HOS-0 pin has been created.
     925        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
     926        pin = self.app['accesscodes']['HOS-0'].keys()[0]
     927        ac = self.app['accesscodes']['HOS-0'][pin]
     928        parts = pin.split('-')[1:]
     929        sfeseries, sfenumber = parts
     930        # Students can use HOS code and book a bed space with it ...
     931        self.browser.open(self.acco_path)
     932        # ... but not if booking period has expired ...
     933        self.app['hostels'].enddate = datetime.now(pytz.utc)
     934        self.browser.getLink("Book accommodation").click()
     935        self.assertMatches('...Outside booking period: ...',
     936                           self.browser.contents)
     937        self.app['hostels'].enddate = datetime.now(pytz.utc) + timedelta(days=10)
     938        # ... or student data are incomplete ...
     939        self.student['studycourse'].current_level = None
     940        self.browser.getLink("Book accommodation").click()
     941        self.assertMatches('...Your data are incomplete...',
     942            self.browser.contents)
     943        self.student['studycourse'].current_level = 100
     944        # ... or student is not the an allowed state ...
     945        self.browser.getLink("Book accommodation").click()
     946        self.assertMatches('...You are in the wrong...',
     947                           self.browser.contents)
     948        IWorkflowInfo(self.student).fireTransition('admit')
     949        self.browser.getLink("Book accommodation").click()
     950        self.assertMatches('...Activation Code:...',
     951                           self.browser.contents)
     952        # Student can't use faked ACs ...
     953        self.browser.getControl(name="ac_series").value = u'nonsense'
     954        self.browser.getControl(name="ac_number").value = sfenumber
     955        self.browser.getControl("Create bed ticket").click()
     956        self.assertMatches('...Activation code is invalid...',
     957                           self.browser.contents)
     958        # ... or ACs owned by somebody else.
     959        ac.owner = u'Anybody'
     960        self.browser.getControl(name="ac_series").value = sfeseries
     961        self.browser.getControl(name="ac_number").value = sfenumber
     962        self.browser.getControl("Create bed ticket").click()
     963        self.assertMatches('...You are not the owner of this access code...',
     964                           self.browser.contents)
     965        # The bed remains empty.
     966        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
     967        self.assertTrue(bed.owner == NOT_OCCUPIED)
     968        ac.owner = self.student_id
     969        self.browser.getControl(name="ac_series").value = sfeseries
     970        self.browser.getControl(name="ac_number").value = sfenumber
     971        self.browser.getControl("Create bed ticket").click()
     972        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     973                           self.browser.contents)
     974        # Bed has been allocated.
     975        self.assertTrue(bed.owner == self.student_id)
     976        # BedTicketAddPage is now blocked.
     977        self.browser.getLink("Book accommodation").click()
     978        self.assertMatches('...You already booked a bed space...',
     979            self.browser.contents)
     980        # The bed ticket displays the data correctly.
     981        self.browser.open(self.acco_path + '/2004')
     982        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
     983                           self.browser.contents)
     984        self.assertMatches('...2004/2005...', self.browser.contents)
     985        self.assertMatches('...regular_male_fr...', self.browser.contents)
     986        self.assertMatches('...%s...' % pin, self.browser.contents)
     987        # Students can open the pdf slip.
     988        self.browser.open(self.browser.url + '/bed_allocation_slip.pdf')
     989        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     990        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     991        # Students can't relocate themselves.
     992        self.assertFalse('Relocate' in self.browser.contents)
     993        relocate_path = self.acco_path + '/2004/relocate'
     994        self.assertRaises(
     995            Unauthorized, self.browser.open, relocate_path)
     996        # Students can't see the Remove button and check boxes.
     997        self.browser.open(self.acco_path)
     998        self.assertFalse('Remove' in self.browser.contents)
     999        self.assertFalse('val_id' in self.browser.contents)
     1000        # Students can pay maintenance fee now.
     1001        self.browser.open(self.payments_path)
     1002        self.browser.open(self.payments_path + '/addop')
     1003        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
     1004        self.browser.getControl("Create ticket").click()
     1005        self.assertMatches('...Payment ticket created...',
     1006                           self.browser.contents)
     1007        ctrl = self.browser.getControl(name='val_id')
     1008        value = ctrl.options[0]
     1009        # Maintennace fee is taken from the hostel object.
     1010        self.assertEqual(self.student['payments'][value].amount_auth, 876.0)
     1011        # If the hostel's maintenance fee isn't set, the fee is
     1012        # taken from the session configuration object.
     1013        self.app['hostels']['hall-1'].maint_fee = 0.0
     1014        self.browser.open(self.payments_path + '/addop')
     1015        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
     1016        self.browser.getControl("Create ticket").click()
     1017        ctrl = self.browser.getControl(name='val_id')
     1018        value = ctrl.options[1]
     1019        self.assertEqual(self.student['payments'][value].amount_auth, 987.0)
     1020        return
Note: See TracChangeset for help on using the changeset viewer.