Changeset 7252 for main/waeup.sirp/trunk


Ignore:
Timestamp:
2 Dec 2011, 21:11:44 (13 years ago)
Author:
Henrik Bettermann
Message:

Add tests for acceptance fee payment.

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

Legend:

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

    r7250 r7252  
    531531        payment.surcharge_3 = academic_session.surcharge_3
    532532        self.context[payment.p_id] = payment
    533         #import pdb; pdb.set_trace()
    534533        self.flash('Payment ticket created.')
    535534        return
     
    929928        return
    930929
     930    # We explicitely want the forms to be validated before payment tickets
     931    # can be created. If no validation is requested, use
     932    # 'validator=NullValidator' in the grok.action directive
    931933    @grok.action('Add online payment ticket')
    932934    def addPaymentTicket(self, **data):
    933935        self.redirect(self.url(self.context, '@@addafp'))
     936        return
    934937
    935938    @grok.action('Remove selected tickets')
     
    983986
    984987    def dataNotComplete(self):
     988        store = getUtility(IExtFileStore)
     989        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
     990            return 'No passport picture uploaded.'
    985991        if not self.request.form.get('confirm_passport', False):
    986             return 'Passport confirmation box not ticked.'
     992            return 'Passport picture confirmation box not ticked.'
    987993        return False
    988994
     995    # We explicitely want the forms to be validated before payment tickets
     996    # can be created. If no validation is requested, use
     997    # 'validator=NullValidator' in the grok.action directive
    989998    @grok.action('Add online payment ticket')
    990999    def addPaymentTicket(self, **data):
    9911000        self.redirect(self.url(self.context, '@@addafp'))
     1001        return
    9921002
    9931003    @grok.action('Remove selected tickets')
     
    9991009    @grok.action('Save')
    10001010    def save(self, **data):
     1011        #import pdb; pdb.set_trace()
    10011012        if self.passport_changed is False:  # False is not None!
    10021013            return # error during image upload. Ignore other values
     
    10091020        if self.passport_changed is False:  # False is not None!
    10101021            return # error during image upload. Ignore other values
    1011         self.applyData(self.context, **data)
    1012         self.context._p_changed = True
    10131022        if self.dataNotComplete():
    10141023            self.flash(self.dataNotComplete())
    10151024            return
     1025        self.applyData(self.context, **data)
    10161026        state = IWorkflowState(self.context).getState()
    10171027        # This shouldn't happen, but the application officer
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py

    r7240 r7252  
    2828from zope.security.interfaces import Unauthorized
    2929from zope.testbrowser.testing import Browser
    30 from hurry.workflow.interfaces import IWorkflowInfo
     30from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    3131from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    3232from waeup.sirp.app import University
     33from waeup.sirp.configuration import SessionConfiguration
    3334from waeup.sirp.applicants.container import ApplicantsContainer
    3435from waeup.sirp.applicants.applicant import Applicant
     
    556557        return
    557558
     559    def test_pay_acceptance_fee(self):
     560        self.login()
     561        self.browser.open(self.edit_path)
     562        # Payment tickets can't be created before the form has been validated
     563        self.browser.getControl("Add online payment ticket").click()
     564        self.assertTrue('Required input is missing' in self.browser.contents)
     565        self.fill_correct_values()
     566        # We have to savethe form otherwise the filled fields will be cleared
     567        # after adding an online payment, because adding an online payment
     568        # requires a filled form but does not save it
     569        self.browser.getControl("Save").click()
     570        self.browser.getControl("Add online payment ticket").click()
     571        # Session object missing
     572        self.assertTrue(
     573            'Session configuration object is not available'
     574            in self.browser.contents)
     575        configuration = SessionConfiguration()
     576        configuration.academic_session = 2009
     577        configuration.acceptance_fee = 200
     578        self.app['configuration'].addSessionConfiguration(configuration)
     579        self.browser.open(self.edit_path)
     580        self.fill_correct_values()
     581        self.browser.getControl("Add online payment ticket").click()
     582        self.assertMatches('...Payment ticket created...', self.browser.contents)
     583        # Payment ticket can be removed if they haven't received a valid callback
     584        ctrl = self.browser.getControl(name='val_id')
     585        value = ctrl.options[0]
     586        ctrl.getControl(value=value).selected = True
     587        self.browser.getControl("Remove selected", index=0).click()
     588        self.assertMatches('...Successfully removed...', self.browser.contents)
     589        # We will try the callback request view
     590        self.browser.getControl("Add online payment ticket").click()
     591        ctrl = self.browser.getControl(name='val_id')
     592        value = ctrl.options[0]
     593        self.browser.getLink(value).click()
     594        self.assertMatches('...Amount Authorized...',
     595                           self.browser.contents)
     596        payment_url = self.browser.url
     597        # The pdf payment receipt can't yet be opened
     598        self.browser.open(payment_url + '/payment_receipt.pdf')
     599        self.assertMatches('...Ticket not yet paid...',
     600                           self.browser.contents)
     601        # Request callback
     602        self.browser.open(payment_url)
     603        self.browser.getLink("Request callback").click()
     604        self.assertMatches('...Valid callback received...',
     605                          self.browser.contents)
     606        # Callback can't be applied twice
     607        self.browser.open(payment_url + '/callback')
     608        self.assertMatches('...This ticket has already been paid...',
     609                          self.browser.contents)
     610        # The payment receipt can be downloaded now
     611        self.browser.open(payment_url)
     612        self.browser.getLink("Download payment receipt").click()
     613        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     614        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     615        # Applicant is is in state 'paid'
     616        self.browser.open(self.view_path)
     617        self.assertMatches('...paid...',
     618                           self.browser.contents)
     619        state = IWorkflowState(self.applicant).getState()
     620        self.assertTrue(state == 'paid')
     621
    558622    def test_final_submit(self):
    559623        # Make sure that a correctly filled form with passport picture
    560         # can be submitted
     624        # can be submitted (only) after payment
    561625        self.login()
    562626        self.browser.getLink("Edit application record").click()
     627        self.assertFalse('Final Submit' in self.browser.contents)
     628        IWorkflowInfo(self.applicant).fireTransition('pay')
     629        self.browser.open(self.edit_path)
     630        self.assertTrue('Final Submit' in self.browser.contents)
    563631        self.fill_correct_values() # fill other fields with correct values
     632        self.browser.getControl("Final Submit").click()
     633        # We forgot to upload a passport picture
     634        self.assertTrue(
     635            'No passport picture uploaded' in self.browser.contents)
    564636        # Create a pseudo image file and select it to be uploaded in form
    565637        pseudo_image = StringIO('I pretend to be a graphics file')
     
    568640        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
    569641        self.browser.getControl("Final Submit").click() # (finally) submit form
    570         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    571         self.assertTrue(
    572             'Passport confirmation box not ticked' in self.browser.contents)
    573         self.browser.getControl(name="confirm_passport").value = True
    574         IWorkflowInfo(self.applicant).fireTransition('submit')
    575         self.browser.getControl("Final Submit").click() # submit form again
    576         self.assertTrue(
    577             'Wrong state' in self.browser.contents)
    578         IWorkflowInfo(self.applicant).fireTransition('reset1')
    579         # Now do the whole thing again but with correct state
    580         self.login()
    581         self.browser.open(self.edit_path)
    582         self.fill_correct_values()
    583         pseudo_image = StringIO('I pretend to be a graphics file')
    584         ctrl = self.browser.getControl(name='form.passport')
    585         file_ctrl = ctrl.mech_control
    586         file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
     642        # The picture has been uploaded but the form cannot be submitted
     643        # since the passport confirmation box was not ticked
     644        self.assertTrue(
     645            'Passport picture confirmation box not ticked' in self.browser.contents)
    587646        self.browser.getControl(name="confirm_passport").value = True
    588647        self.browser.getControl("Final Submit").click()
Note: See TracChangeset for help on using the changeset viewer.