source: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py @ 16739

Last change on this file since 16739 was 16330, checked in by Henrik Bettermann, 4 years ago

Adjust tests.

  • Property svn:keywords set to Id
File size: 25.5 KB
RevLine 
[7894]1## $Id: tests.py 16330 2020-11-22 15:48:00Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
[9775]18import os
[12980]19from datetime import datetime, date, timedelta
[9713]20from zope.component import createObject, getUtility
21from zope.catalog.interfaces import ICatalog
[7894]22from hurry.workflow.interfaces import IWorkflowState
23from waeup.kofa.students.tests.test_browser import StudentsFullSetup
[8266]24from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
[11787]25from waeup.uniben.configuration import CustomSessionConfiguration
[8020]26from waeup.uniben.testing import FunctionalLayer
[7894]27
[7970]28# Also run tests that send requests to external servers?
29#   If you enable this, please make sure the external services
30#   do exist really and are not bothered by being spammed by a test programme.
[9831]31EXTERNAL_TESTS = False
[7970]32
[11728]33SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
34
[7970]35def external_test(func):
36    if not EXTERNAL_TESTS:
37        myself = __file__
38        if myself.endswith('.pyc'):
39            myself = myself[:-2]
40        print "WARNING: external tests are skipped!"
41        print "WARNING: edit %s to enable them." % myself
42        return
43    return func
44
45
[8266]46class InterswitchTestsStudents(StudentsFullSetup):
[7929]47    """Tests for the Interswitch payment gateway.
[7894]48    """
49
50    layer = FunctionalLayer
51
[7970]52    def setUp(self):
[8266]53        super(InterswitchTestsStudents, self).setUp()
[14758]54        self.app['configuration']['2004'].interswitch_enabled = True
[7970]55        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[7995]56        self.browser.open(self.payments_path)
[7970]57        IWorkflowState(self.student).setState('cleared')
[9006]58        self.student.nationality = u'NG'
[7995]59        self.browser.open(self.payments_path + '/addop')
[9384]60        self.browser.getControl(name="form.p_category").value = ['schoolfee']
[7970]61        self.browser.getControl("Create ticket").click()
[9435]62        self.assertMatches('...ticket created...',
63                           self.browser.contents)
[16330]64        self.browser.open(self.payments_path)
[9435]65        ctrl = self.browser.getControl(name='val_id')
[9775]66        self.value = ctrl.options[0]
67        self.browser.getLink(self.value).click()
[9435]68        self.assertMatches('...Amount Authorized...',
69                           self.browser.contents)
[13111]70        self.assertTrue(
71            '<span>40000.0</span>' in self.browser.contents)
[9435]72        self.payment_url = self.browser.url
[7970]73
[8263]74#    def callback_url(self, payment_url, resp, apprAmt):
75#        return payment_url + (
76#            '/isw_callback?echo=' +
77#            '&resp=%s' +
78#            '&desc=Something went wrong' +
79#            '&txnRef=p1331792385335' +
80#            '&payRef=' + '&retRef=' +
81#            '&cardNum=0' +
82#            '&apprAmt=%s' +
83#            '&url=http://xyz') % (resp, apprAmt)
[7894]84
[7970]85    def test_interswitch_form(self):
[7894]86        # Manager can access InterswitchForm
[15716]87        self.browser.getLink("Pay via Interswitch", index=0).click()
[8266]88        # The total amount to be processed by Interswitch
89        # has been reduced by the Interswitch fee of 150 Nairas
[13111]90        self.assertTrue('<input type="hidden" name="pay_item_id" value="5700" />'
91                           in self.browser.contents)
92        self.assertTrue('Total Amount Authorized:'
93                           in self.browser.contents)
[9460]94        self.assertEqual(self.student.current_mode, 'ug_ft')
[13111]95        self.assertTrue(
96            '<input type="hidden" name="amount" value="4000000" />'
97            in self.browser.contents)
98        self.assertTrue(
[14237]99            'item_name="School Fee" item_amt="3835000" bank_id="8" acct_num="2017506430"'
[13111]100            in self.browser.contents)
101        self.assertTrue(
[14237]102            'item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1014261520"'
[13111]103            in self.browser.contents)
[7894]104
[9520]105        # Create school fee ticket for returning students. Payment is made
106        # for next session.
107        current_payment_key = self.student['payments'].keys()[0]
[9389]108        self.certificate.study_mode = u'ug_pt'
109        IWorkflowState(self.student).setState('returning')
110        configuration = createObject('waeup.SessionConfiguration')
111        configuration.academic_session = 2005
112        self.app['configuration'].addSessionConfiguration(configuration)
[9384]113        self.browser.open(self.payments_path + '/addop')
[9389]114        self.browser.getControl(name="form.p_category").value = ['schoolfee']
[9384]115        self.browser.getControl("Create ticket").click()
[9570]116
117        ## Next session payment can't be made ...
118        #self.assertMatches(
119        #    '...You have not yet paid your current/active session...',
120        #    self.browser.contents)
121        ## current session payment must be approved first.
122        #self.student['payments'][current_payment_key].approve()
123        #self.browser.open(self.payments_path + '/addop')
124        #self.browser.getControl(name="form.p_category").value = ['schoolfee']
125        #self.browser.getControl("Create ticket").click()
126
[16330]127        self.browser.open(self.payments_path)
[9384]128        ctrl = self.browser.getControl(name='val_id')
129        value = ctrl.options[1]
[9775]130        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
131        self.assertEqual(self.student['payments'][value].gateway_amt, 0.0)
[9384]132        self.browser.getLink(value).click()
[15716]133        self.browser.getLink("Pay via Interswitch", index=0).click()
[9775]134        # Split amounts have been set.
[14237]135        self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
[9775]136        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
[13111]137        self.assertTrue('<input type="hidden" name="pay_item_id" value="5701" />'
138                           in self.browser.contents)
139        self.assertTrue(
140            '<input type="hidden" name="amount" value="2000000" />'
141            in self.browser.contents)
142        self.assertTrue(
[14237]143            'item_name="School Fee" item_amt="1835000" bank_id="8" acct_num="2017506430"'
[13111]144            in self.browser.contents)
145        self.assertTrue(
[14237]146            'item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1014261520"'
[13111]147            in self.browser.contents)
[9389]148
149        # Create clearance fee ticket
[10902]150        #self.browser.open(self.payments_path + '/addop')
151        #self.browser.getControl(name="form.p_category").value = ['clearance']
152        #self.browser.getControl("Create ticket").click()
153        #ctrl = self.browser.getControl(name='val_id')
154        #value = ctrl.options[2]
155        #self.browser.getLink(value).click()
156        #self.assertMatches(
157        #    '...<span>45000.0</span>...',
158        #    self.browser.contents)
159        ## Manager can access InterswitchForm
[15716]160        #self.browser.getLink("Pay via Interswitch", index=0).click()
[10902]161        #self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
162        #self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
163        #self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
164        #                   self.browser.contents)
165        #self.assertMatches('...Total Amount Authorized:...',
166        #                   self.browser.contents)
167        #self.assertMatches(
168        #    '...<input type="hidden" name="amount" value="4500000.0" />...',
169        #    self.browser.contents)
170        #self.assertMatches(
171        #    '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...',
172        #    self.browser.contents)
173        #self.assertMatches(
174        #    '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
175        #    self.browser.contents)
[9384]176
[9515]177        # Create gown fee ticket
178        configuration.maint_fee = 987.0
179        self.app['configuration']['2004'].gown_fee = 234.0
180        self.browser.open(self.payments_path + '/addop')
181        self.browser.getControl(name="form.p_category").value = ['gown']
182        self.browser.getControl("Create ticket").click()
[16330]183        self.browser.open(self.payments_path)
[9515]184        ctrl = self.browser.getControl(name='val_id')
[10902]185        value = ctrl.options[2]
[9515]186        self.browser.getLink(value).click()
[13111]187        self.assertTrue(
188            '<span>234.0</span>',
[9515]189            self.browser.contents)
190        # Manager can access InterswitchForm
[15716]191        self.browser.getLink("Pay via Interswitch", index=0).click()
[9775]192        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
193        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
[13111]194        self.assertTrue('<input type="hidden" name="pay_item_id" value="5704" />'
195                           in self.browser.contents)
196        self.assertTrue('Total Amount Authorized:'
197                           in self.browser.contents)
198        self.assertTrue(
199            '<input type="hidden" name="amount" value="23400" />'
200            in self.browser.contents)
201        self.assertTrue(
[13771]202            '<item_detail item_id="1" item_name="Gown Hire Fee" item_amt="8400" bank_id="8" acct_num="2017506430" />'
[13111]203            in self.browser.contents)
[9515]204        self.assertFalse(
205            'item_name="BT Education"' in self.browser.contents)
[9384]206
[12566]207        # Create hostel application ticket
[13251]208        #self.browser.open(self.payments_path + '/addop')
209        #self.browser.getControl(name="form.p_category").value = ['hostel_application']
210        #self.browser.getControl("Create ticket").click()
211        #ctrl = self.browser.getControl(name='val_id')
212        #value = ctrl.options[3]
213        #self.browser.getLink(value).click()
214        #self.assertTrue(
215        #    '<span>1000.0</span>' in self.browser.contents)
216        #self.student['payments'][value].approve()
[12566]217
[9727]218        # Create temp maint fee ticket
[13251]219        #self.browser.open(self.payments_path + '/addop')
220        #self.browser.getControl(name="form.p_category").value = ['tempmaint_1']
221        #self.browser.getControl("Create ticket").click()
222        #ctrl = self.browser.getControl(name='val_id')
223        #value = ctrl.options[4]
224        #self.browser.getLink(value).click()
225        #self.assertTrue(
226        #    '<span>8150.0</span>' in self.browser.contents)
[9727]227        # Manager can access InterswitchForm
[15716]228        #self.browser.getLink("Pay via Interswitch", index=0).click()
[13251]229        #self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
230        #self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
231        #self.assertTrue('<input type="hidden" name="pay_item_id" value="5705" />'
232        #                 in self.browser.contents)
233        #self.assertMatches('...Total Amount Authorized:...',
234        #                   self.browser.contents)
235        #self.assertTrue(
236        #    '<input type="hidden" name="amount" value="815000" />'
237        #    in self.browser.contents)
238        #self.assertTrue(
239        #    '<item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="800000" bank_id="129" acct_num="0014419432" />'
240        #    in self.browser.contents)
241        #self.assertFalse(
242        #    'item_name="BT Education"' in self.browser.contents)
[9727]243
[9863]244        # Create previous session fee ticket
245        configuration = createObject('waeup.SessionConfiguration')
246        configuration.academic_session = 2003
247        configuration.clearance_fee = 3456.0
248        self.app['configuration'].addSessionConfiguration(configuration)
249        self.student['studycourse'].entry_session = 2002
[10902]250        #self.browser.open(self.payments_path + '/addpp')
251        #self.browser.getControl(name="form.p_category").value = ['clearance']
252        #self.browser.getControl(name="form.p_session").value = ['2003']
253        #self.browser.getControl(name="form.p_level").value = ['300']
254        #self.browser.getControl("Create ticket").click()
255        #ctrl = self.browser.getControl(name='val_id')
256        #value = ctrl.options[5]
257        #self.browser.getLink(value).click()
258        #self.assertMatches(
259        #    '...<span>45000.0</span>...',
260        #    self.browser.contents)
261        ## Manager can access InterswitchForm
[15716]262        #self.browser.getLink("Pay via Interswitch", index=0).click()
[10902]263        #self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
264        #self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
265        #self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
266        #                   self.browser.contents)
267        #self.assertMatches('...Total Amount Authorized:...',
268        #                   self.browser.contents)
269        ##self.assertMatches(
270        #    '...<input type="hidden" name="amount" value="4500000.0" />...',
271        #    self.browser.contents)
272        #self.assertMatches(
273        #    '...<item_detail item_id="1" item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516" />...',
274        #    self.browser.contents)
[9863]275
[9869]276        # Create balance payment ticket
277        self.browser.open(self.payments_path + '/addbp')
278        self.browser.getControl(name="form.p_category").value = ['schoolfee']
279        self.browser.getControl(name="form.balance_session").value = ['2003']
280        self.browser.getControl(name="form.balance_level").value = ['300']
281        self.browser.getControl(name="form.balance_amount").value = '200'
282        self.browser.getControl("Create ticket").click()
[16330]283        self.browser.open(self.payments_path)
[9869]284        ctrl = self.browser.getControl(name='val_id')
[13251]285        value = ctrl.options[3]
[9869]286        self.browser.getLink(value).click()
[13111]287        self.assertTrue(
288            '<span>200.0</span>' in self.browser.contents)
[9869]289        # Manager can access InterswitchForm
[15716]290        self.browser.getLink("Pay via Interswitch", index=0).click()
[9869]291        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
292        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
[13111]293        self.assertTrue('<input type="hidden" name="pay_item_id" value="5701" />'
294                           in self.browser.contents)
295        self.assertTrue(
296            '<input type="hidden" name="amount" value="20000" />'
297            in self.browser.contents)
298        self.assertTrue(
[13771]299            'item_name="School Fee" item_amt="5000" bank_id="8" acct_num="2017506430"'
[13111]300            in self.browser.contents)
[9869]301        self.assertFalse(
302            'item_name="BT Education"' in self.browser.contents)
[9863]303
[13785]304        # Create JUPEB fee ticket
305        self.app['configuration']['2004'].jupeb_fee = 345.0
306        self.browser.open(self.payments_path + '/addop')
307        self.browser.getControl(name="form.p_category").value = ['jupeb']
308        self.browser.getControl("Create ticket").click()
[16330]309        self.browser.open(self.payments_path)
[13785]310        ctrl = self.browser.getControl(name='val_id')
311        value = ctrl.options[4]
312        self.browser.getLink(value).click()
313        self.assertTrue(
314            '<span>345.0</span>',
315            self.browser.contents)
316        # Manager can access InterswitchForm
[15716]317        self.browser.getLink("Pay via Interswitch", index=0).click()
[13785]318        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
319        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
320        self.assertTrue('<input type="hidden" name="pay_item_id" value="5717" />'
321                           in self.browser.contents)
322        self.assertTrue('Total Amount Authorized:'
323                           in self.browser.contents)
324        self.assertTrue(
325            '<input type="hidden" name="amount" value="34500" />'
326            in self.browser.contents)
327        self.assertTrue(
328            '<item_detail item_id="1" item_name="JUPEB Examination Fee" item_amt="19500" bank_id="8" acct_num="2017506430" />'
329            in self.browser.contents)
330        self.assertFalse(
331            'item_name="BT Education"' in self.browser.contents)
332
[8263]333#    @external_test
334#    def test_callback(self):
[7970]335
[7894]336        # Manager can call callback manually
[8263]337#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
338#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
339#                          self.browser.contents)
340#        self.assertMatches('...Failed...',
341#                           self.browser.contents)
342#        self.browser.open(self.payment_url + '/isw_callback')
343#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
344#                          self.browser.contents)
345#        self.assertMatches('...Failed...',
346#                           self.browser.contents)
347#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
348#        self.assertMatches('...Wrong amount...',
349#                          self.browser.contents)
350#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
351#        self.assertMatches('...Valid callback received...',
352#                          self.browser.contents)
[7930]353
[12980]354    def test_interswitch_form_ticket_expired(self):
355        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
356        acc_payment = createObject('waeup.StudentOnlinePayment')
357        acc_payment.p_state = 'unpaid'
358        acc_payment.p_category = 'clearance'
359        acc_payment.p_id = 'xyz'
360        acc_payment.pay_item_id = '123'
361        acc_payment.amount_auth = 876.0
362        self.student['payments']['xyz'] = acc_payment
363        self.browser.open(self.payments_path + '/xyz')
[15716]364        self.browser.getLink("Pay via Interswitch", index=0).click()
[13111]365        self.assertTrue('<input type="hidden" name="pay_item_id" value="5702" />'
366                           in self.browser.contents)
367        self.assertTrue('Total Amount Authorized:'
368                           in self.browser.contents)
[12980]369        self.assertEqual(self.student.current_mode, 'ug_ft')
[13111]370        self.assertTrue(
371            '<input type="hidden" name="amount" value="87600" />'
372            in self.browser.contents)
[13016]373        delta = timedelta(days=8)
[12980]374        acc_payment.creation_date -= delta
375        self.browser.open(self.payments_path + '/xyz')
[15716]376        self.browser.getLink("Pay via Interswitch", index=0).click()
[12980]377        self.assertMatches(
378            '...This payment ticket is too old. Please create a new ticket...',
379            self.browser.contents)
[13016]380        delta = timedelta(days=2)
[12980]381        acc_payment.creation_date += delta
382        self.browser.open(self.payments_path + '/xyz')
[15716]383        self.browser.getLink("Pay via Interswitch", index=0).click()
[12980]384        self.assertMatches('...Total Amount Authorized:...',
385                           self.browser.contents)
386
[11645]387    def test_pay_twice(self):
388        # Create second ticket
389        self.browser.open(self.payments_path + '/addop')
390        self.browser.getControl(name="form.p_category").value = ['schoolfee']
391        self.browser.getControl("Create ticket").click()
[16330]392        self.browser.open(self.payments_path)
[11645]393        # Pay first ticket
394        self.student['payments'][self.value].approve()
395        # Try to pay second ticket
396        self.browser.open(self.payments_path)
397        ctrl = self.browser.getControl(name='val_id')
398        value = ctrl.options[1]
399        self.browser.getLink(value).click()
[15716]400        self.browser.getLink("Pay via Interswitch", index=0).click()
[11645]401        self.assertMatches(
402            '...alert alert-danger">This type of payment has already been made...',
403            self.browser.contents)
404
[7970]405    @external_test
[7930]406    def test_webservice(self):
[9775]407        # First we have open InterswitchPageStudent to set provider_amt
408        # and gateway_amt
409        self.browser.open(self.payment_url + '/goto_interswitch')
410        # Now we can call the webservice
[7970]411        self.browser.open(self.payment_url + '/request_webservice')
[7930]412        self.assertMatches('...Unsuccessful callback...',
413                          self.browser.contents)
[9713]414        # The payment is now in state failed ...
[8266]415        self.assertMatches('...<span>Failed</span>...',
416                          self.browser.contents)
[9713]417        # ... and the catalog has been updated
418        cat = getUtility(ICatalog, name='payments_catalog')
419        results = list(
420            cat.searchResults(p_state=('failed', 'failed')))
421        self.assertEqual(len(results), 1)
422        self.assertEqual(results[0].p_state, 'failed')
[8266]423
[9775]424        # Let's replace the p_id with a valid p_id of the Uniben
425        # live system. This is definitely not an appropriate
426        # solution for testing, but we have no choice since
427        # Interswitch doesn't provide any interface
428        # for testing.
429        payment = self.student['payments'][self.value]
430        payment.p_id = 'p3547789850240'
431        self.browser.open(self.payment_url + '/request_webservice')
432        self.assertMatches('...Callback amount does not match...',
433                          self.browser.contents)
434        # The payment is now in state failed ...
435        self.assertMatches('...<span>Failed</span>...',
436                          self.browser.contents)
437        # Let's replace the amount autorized with the amount of the
438        # live system payment
439        payment.amount_auth = payment.r_amount_approved
440        self.browser.open(self.payment_url + '/request_webservice')
441        self.assertMatches('...Successful payment...',
442                          self.browser.contents)
443        # The payment is now in state paid ...
444        self.assertMatches('...<span>Paid</span>...',
445                          self.browser.contents)
446        # ... and the catalog has been updated
447        cat = getUtility(ICatalog, name='payments_catalog')
448        results = list(
449            cat.searchResults(p_state=('paid', 'paid')))
450        self.assertEqual(len(results), 1)
451        self.assertEqual(results[0].p_state, 'paid')
452        # Approval is logged in students.log ...
453        logfile = os.path.join(
454            self.app['datacenter'].storage, 'logs', 'students.log')
455        logcontent = open(logfile).read()
456        self.assertTrue(
457            'zope.mgr - '
[11633]458            'waeup.uniben.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - '
[9775]459            'B1000000 - successful schoolfee payment: p3547789850240\n'
460            in logcontent)
461        # ... and in payments.log
462        logfile = os.path.join(
463            self.app['datacenter'].storage, 'logs', 'payments.log')
464        logcontent = open(logfile).read()
465        self.assertTrue(
466            '"zope.mgr",B1000000,p3547789850240,schoolfee,'
467            '12000.0,00,1500.0,150.0,0.0,,,\n'
468            in logcontent)
469
470
[8266]471class InterswitchTestsApplicants(ApplicantsFullSetup):
472    """Tests for the Interswitch payment gateway.
473    """
474
475    layer = FunctionalLayer
476
477    def setUp(self):
478        super(InterswitchTestsApplicants, self).setUp()
[11787]479        configuration = CustomSessionConfiguration()
[10836]480        configuration.academic_session = datetime.now().year - 2
[14758]481        configuration.interswitch_enabled = True
[13887]482        self.applicantscontainer.application_fee = 1000.0
[10836]483        self.app['configuration'].addSessionConfiguration(configuration)
[8266]484        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
485        self.browser.open(self.manage_path)
486        #IWorkflowState(self.student).setState('started')
487        super(InterswitchTestsApplicants, self).fill_correct_values()
[16330]488        self.browser.getControl("Create and make online").click()
[11752]489        self.assertMatches('...passport photo before making payment...',
[11728]490                           self.browser.contents)
491        self.browser.open(self.manage_path)
492        super(InterswitchTestsApplicants, self).fill_correct_values()
493        #self.browser.getControl(name="form.nationality").value = ['NG']
494        #self.browser.getControl(name="transition").value = ['start']
495        image = open(SAMPLE_IMAGE, 'rb')
496        ctrl = self.browser.getControl(name='form.passport')
497        file_ctrl = ctrl.mech_control
498        file_ctrl.add_file(image, filename='myphoto.jpg')
[8266]499        self.browser.getControl("Save").click()
[16330]500        self.browser.getControl("Create and make online").click()
[8266]501        self.assertMatches('...ticket created...',
502                           self.browser.contents)
[8281]503        #ctrl = self.browser.getControl(name='val_id')
504        #value = ctrl.options[0]
505        #self.browser.getLink(value).click()
[10836]506        self.payment_url = self.browser.url
507
508    def test_interswitch_form(self):
[8266]509        self.assertMatches('...Amount Authorized...',
510                           self.browser.contents)
[13111]511        self.assertTrue(
512            '<span>1000.0</span>' in self.browser.contents)
[8266]513        # Manager can access InterswitchForm
[15716]514        self.browser.getLink("Pay via Interswitch", index=0).click()
[8266]515        self.assertMatches('...Total Amount Authorized:...',
516                           self.browser.contents)
[13111]517        self.assertTrue(
518            '<input type="hidden" name="amount" value="100000" />'
519            in self.browser.contents)
[13016]520        delta = timedelta(days=8)
[12980]521        self.applicant.values()[0].creation_date -= delta
522        self.browser.open(self.payment_url)
[15716]523        self.browser.getLink("Pay via Interswitch", index=0).click()
[12980]524        self.assertMatches(
525            '...This payment ticket is too old. Please create a new ticket...',
526            self.browser.contents)
[8266]527
528    @external_test
529    def test_webservice(self):
530
531        self.browser.open(self.payment_url + '/request_webservice')
532        self.assertMatches('...Unsuccessful callback...',
533                          self.browser.contents)
534        # The payment is now in state failed
535        self.assertMatches('...<span>Failed</span>...',
536                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.