Ignore:
Timestamp:
3 Apr 2014, 16:44:28 (11 years ago)
Author:
Henrik Bettermann
Message:

Add webservice test for applicants. Start customization of doAfterApplicantPaymentApproval and doAfterApplicantPayment.

Location:
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/payment.py

    r11573 r11574  
    2222from zope.component.interfaces import IFactory
    2323from zope.interface import implementedBy
     24from hurry.workflow.interfaces import IWorkflowInfo
    2425from waeup.kofa.applicants.payment import ApplicantOnlinePayment
    2526from waeup.kofa.utils.helpers import attrs_to_fields
    2627from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
     28from waeup.kwarapoly.interfaces import MessageFactory as _
    2729
    2830class CustomApplicantOnlinePayment(ApplicantOnlinePayment):
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py

    r11557 r11574  
    3636#   If you enable this, please make sure the external services
    3737#   do exist really and are not bothered by being spammed by a test programme.
    38 EXTERNAL_TESTS = False
     38EXTERNAL_TESTS = True
    3939
    4040def external_test(func):
     
    373373    @external_test
    374374    def test_webservice(self):
     375        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     376        IWorkflowState(self.student).setState('cleared')
     377        # We add a fake maint. payment ticket to meet the condition
     378        maint_payment = CustomStudentOnlinePayment()
     379        self.student['payments']['any_key'] = maint_payment
     380        maint_payment.p_category = 'hostel_maintenance'
     381        maint_payment.p_state = 'paid'
     382        maint_payment.p_session = 2004
     383        # We create the school fee payment ticket
     384        self.browser.open(self.payments_path + '/addop')
     385        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     386        self.browser.getControl("Create ticket").click()
     387        self.assertMatches('...ticket created...',
     388                           self.browser.contents)
     389        ctrl = self.browser.getControl(name='val_id')
     390        self.value = ctrl.options[1]
     391        self.browser.getLink(self.value).click()
     392        self.payment_url = self.browser.url
    375393        # First we have open InterswitchPageStudent to set provider_amt
    376394        # and gateway_amt
     
    475493        self.assertMatches('...ticket created...',
    476494                           self.browser.contents)
    477         #ctrl = self.browser.getControl(name='val_id')
    478         #value = ctrl.options[0]
    479         #self.browser.getLink(value).click()
    480495        self.assertMatches('...Amount Authorized...',
    481496                           self.browser.contents)
     
    594609            'item_amt="450000" bank_id="9" acct_num="7000016724" />'
    595610            in self.browser.contents)
     611
     612    @external_test
     613    def test_webservice(self):
     614
     615        self.browser.open(self.payment_url + '/request_webservice')
     616        self.assertMatches('...Unsuccessful callback...',
     617                          self.browser.contents)
     618        # The payment is now in state failed
     619        self.assertMatches('...<span>Failed</span>...',
     620                          self.browser.contents)
     621        # Let's replace the p_id with a valid p_id of the Kwarapoly
     622        # live system. This is definitely not an appropriate
     623        # solution for testing, but we have no choice since
     624        # Interswitch doesn't provide any interface
     625        # for testing.
     626        p_id = self.applicant.keys()[0]
     627        payment = self.applicant[p_id]
     628        payment.p_id = 'p3543612043224'
     629        self.browser.open(self.payment_url + '/request_webservice')
     630        self.assertMatches('...Callback amount does not match...',
     631                          self.browser.contents)
     632        payment.amount_auth = payment.r_amount_approved
     633
     634        self.browser.open(self.payment_url + '/request_webservice')
     635        self.assertMatches('...Successful payment...',
     636                          self.browser.contents)
     637        # The payment is now in state paid ...
     638        self.assertMatches('...<span>Paid</span>...',
     639                          self.browser.contents)
     640        # ... and the catalog has been updated
     641        cat = getUtility(ICatalog, name='payments_catalog')
     642        results = list(
     643            cat.searchResults(p_state=('paid', 'paid')))
     644        self.assertEqual(len(results), 1)
     645        self.assertEqual(results[0].p_state, 'paid')
     646        # Approval is logged in applicants.log ...
     647        logfile = os.path.join(
     648            self.app['datacenter'].storage, 'logs', 'applicants.log')
     649        logcontent = open(logfile).read()
     650        self.assertTrue(
     651            'zope.mgr - waeup.kwarapoly.interswitch.browser.InterswitchPaymentRequestWebservicePageApplicant'
     652            ' - nd_anything - successful payment: p3543612043224\n'
     653            in logcontent)
     654        # ... and in payments.log
     655        logfile = os.path.join(
     656            self.app['datacenter'].storage, 'logs', 'payments.log')
     657        logcontent = open(logfile).read()
     658        self.assertTrue(
     659            '"zope.mgr",nd_anything,p3543612043224,application,52100.0,'
     660            '00,0.0,0.0,0.0,,,\n'
     661            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.