source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py @ 11576

Last change on this file since 11576 was 11574, checked in by Henrik Bettermann, 11 years ago

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

  • Property svn:keywords set to Id
File size: 31.7 KB
Line 
1## $Id: tests.py 11574 2014-04-03 16:44:28Z 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##
18import os
19import grok
20import pytz
21from datetime import datetime, date, timedelta
22from hurry.workflow.interfaces import IWorkflowState
23from zope.component import createObject, getUtility
24from zope.catalog.interfaces import ICatalog
25from zope.event import notify
26from waeup.kofa.applicants.container import ApplicantsContainer
27from waeup.kofa.university.faculty import Faculty
28from waeup.kofa.university.department import Department
29from waeup.kofa.students.tests.test_browser import StudentsFullSetup
30from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
31from waeup.kofa.configuration import SessionConfiguration
32from waeup.kwarapoly.testing import FunctionalLayer
33from waeup.kwarapoly.students.payments import CustomStudentOnlinePayment
34
35# Also run tests that send requests to external servers?
36#   If you enable this, please make sure the external services
37#   do exist really and are not bothered by being spammed by a test programme.
38EXTERNAL_TESTS = True
39
40def external_test(func):
41    if not EXTERNAL_TESTS:
42        myself = __file__
43        if myself.endswith('.pyc'):
44            myself = myself[:-2]
45        print "WARNING: external tests are skipped!"
46        print "WARNING: edit %s to enable them." % myself
47        return
48    return func
49
50
51class InterswitchTestsStudents(StudentsFullSetup):
52    """Tests for the Interswitch payment gateway.
53    """
54
55    layer = FunctionalLayer
56
57    def setUp(self):
58        super(InterswitchTestsStudents, self).setUp()
59
60        # Create at least one Kwarapoly faculty
61        self.app['faculties']['CPGS'] = Faculty(code='CPGS')
62        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
63        self.certificate2 = createObject('waeup.Certificate')
64        self.certificate2.code = u'CERT2'
65        self.certificate2.application_category = 'basic'
66        self.certificate2.study_mode = 'nd_ft'
67        self.certificate2.start_level = 100
68        self.certificate2.end_level = 300
69        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
70            self.certificate2)
71        # Set study course attributes of test student
72        self.student['studycourse'].certificate = self.certificate2
73        self.student['studycourse'].current_session = 2004
74        self.student['studycourse'].entry_session = 2004
75        self.student['studycourse'].current_verdict = 'A'
76        self.student['studycourse'].current_level = 100
77        # Set local lga
78        self.student.lga = u'kwara_asa'
79        # Update the catalog
80        notify(grok.ObjectModifiedEvent(self.student))
81
82
83    def test_schoolfee_ticket_creation(self):
84        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
85        self.browser.open(self.payments_path)
86        IWorkflowState(self.student).setState('cleared')
87        self.browser.open(self.payments_path + '/addop')
88        self.browser.getControl(name="form.p_category").value = ['schoolfee']
89        self.browser.getControl("Create ticket").click()
90        self.assertMatches('...Book and pay for accommodation first...',
91                           self.browser.contents)
92        # We add a fake maint. payment ticket to meet the condition
93        maint_payment = CustomStudentOnlinePayment()
94        self.student['payments']['any_key'] = maint_payment
95        maint_payment.p_category = 'hostel_maintenance'
96        maint_payment.p_state = 'unpaid'
97        maint_payment.p_session = 2004
98        self.browser.getControl(name="form.p_category").value = ['schoolfee']
99        self.browser.getControl("Create ticket").click()
100        self.assertMatches('...Book and pay for accommodation first...',
101                           self.browser.contents)
102        # Ticket must be paid
103        maint_payment.p_state = 'paid'
104        self.browser.getControl(name="form.p_category").value = ['schoolfee']
105        self.browser.getControl("Create ticket").click()
106        self.assertMatches('...ticket created...',
107                           self.browser.contents)
108        ctrl = self.browser.getControl(name='val_id')
109        self.value = ctrl.options[1]
110        self.browser.getLink(self.value).click()
111        self.assertMatches('...Amount Authorized...',
112                           self.browser.contents)
113        self.assertMatches(
114            '...<span>39400.0</span>...',
115            self.browser.contents)
116        self.payment_url = self.browser.url
117
118
119#    def callback_url(self, payment_url, resp, apprAmt):
120#        return payment_url + (
121#            '/isw_callback?echo=' +
122#            '&resp=%s' +
123#            '&desc=Something went wrong' +
124#            '&txnRef=p1331792385335' +
125#            '&payRef=' + '&retRef=' +
126#            '&cardNum=0' +
127#            '&apprAmt=%s' +
128#            '&url=http://xyz') % (resp, apprAmt)
129
130    def test_interswitch_form(self):
131
132        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
133        self.browser.open(self.payments_path)
134        # In KwaraPoly only returning students can create school fee payment
135        # without haveing paid accommodation fee
136        IWorkflowState(self.student).setState('returning')
137        configuration = createObject('waeup.SessionConfiguration')
138        configuration.academic_session = 2005
139        self.app['configuration'].addSessionConfiguration(configuration)
140        self.browser.open(self.payments_path + '/addop')
141        self.browser.getControl(name="form.p_category").value = ['schoolfee']
142        self.browser.getControl("Create ticket").click()
143        self.assertMatches('...ticket created...', self.browser.contents)
144        ctrl = self.browser.getControl(name='val_id')
145        self.value = ctrl.options[0]
146        self.browser.getLink(self.value).click()
147        self.assertMatches('...Amount Authorized...', self.browser.contents)
148        self.assertMatches(
149            '...<span>29500.0</span>...',
150            self.browser.contents)
151        self.payment_url = self.browser.url
152
153        # Manager can access InterswitchForm
154        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
155        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
156        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0)
157        self.browser.getLink("CollegePAY", index=0).click()
158        # Split amounts have been set.
159        self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0)
160        self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0)
161        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0)
162        self.assertMatches('...Total Amount Authorized:...',
163                           self.browser.contents)
164        self.assertTrue(
165            '<input type="hidden" name="amount" value="2950000.0" />' in
166            self.browser.contents)
167        self.assertTrue(
168            'item_name="School Fee" item_amt="2620000" bank_id="120" acct_num="1771180233"' in
169            self.browser.contents)
170        self.assertTrue(
171            'item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"' in
172            self.browser.contents)
173        self.assertTrue(
174            'item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"' in
175            self.browser.contents)
176
177        # Let's do the same for maintenance fee payment
178
179        self.browser.open(self.payments_path)
180        self.browser.open(self.payments_path + '/addop')
181        self.browser.getControl(
182            name="form.p_category").value = ['hostel_maintenance']
183        self.browser.getControl("Create ticket").click()
184        self.assertMatches('...You have not yet booked accommodation...',
185                           self.browser.contents)
186        # Students have to book bed first
187        self.browser.open(self.acco_path)
188        IWorkflowState(self.student).setState('admitted')
189        self.browser.getLink("Book accommodation").click()
190        self.assertFalse('Activation Code:' in self.browser.contents)
191        self.browser.getControl("Create bed ticket").click()
192        # Bed is randomly selected but, since there is only
193        # one bed for this student, we know that ...
194        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
195                           self.browser.contents)
196        self.assertMatches('...ticket created...',
197                           self.browser.contents)
198        self.browser.open(self.payments_path + '/addop')
199        self.browser.getControl(
200            name="form.p_category").value = ['hostel_maintenance']
201        self.browser.getControl("Create ticket").click()
202        self.assertMatches('...ticket created...',
203                           self.browser.contents)
204        ctrl = self.browser.getControl(name='val_id')
205        value = ctrl.options[1]
206        self.browser.getLink(value).click()
207        self.assertMatches('...Amount Authorized...',
208                           self.browser.contents)
209        # Maint fee is taken from the hostel object
210        self.assertMatches(
211            '...<span>876.0</span>...',
212            self.browser.contents)
213        self.payment_url = self.browser.url
214        # Manager can access InterswitchForm
215        self.browser.getLink("CollegePAY", index=0).click()
216        # Split amounts have been set.
217        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
218        self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0)
219        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
220        # The total amount to be processed by Interswitch
221        # has been reduced by the Interswitch fee of 150 Nairas
222        self.assertMatches('...Total Amount Authorized:...',
223                           self.browser.contents)
224        self.assertMatches(
225            '...<input type="hidden" name="pay_item_id" value="102" />...',
226            self.browser.contents)
227        self.assertMatches(
228            '...<input type="hidden" name="amount" value="87600.0" />...',
229            self.browser.contents)
230        self.assertMatches(
231            '...item_name="Hostel Maintenance Fee" item_amt="57600" bank_id="31" acct_num="0039050937"...',
232            self.browser.contents)
233
234        # Create carryover ticket
235        self.browser.open(self.payments_path + '/addop')
236        self.browser.getControl(name="form.p_category").value = ['carryover1']
237        self.browser.getControl("Create ticket").click()
238        ctrl = self.browser.getControl(name='val_id')
239        value = ctrl.options[2]
240        self.browser.getLink(value).click()
241        self.assertMatches(
242            '...<span>6000.0</span>...',
243            self.browser.contents)
244        # Manager can access InterswitchForm
245        self.browser.getLink("CollegePAY", index=0).click()
246        # Split amounts have been set.
247        self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0)
248        self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0)
249        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0)
250        self.assertMatches('...<input type="hidden" name="pay_item_id" value="101" />...',
251                           self.browser.contents)
252        self.assertMatches('...Total Amount Authorized:...',
253                           self.browser.contents)
254        self.assertMatches(
255            '...<input type="hidden" name="amount" value="600000.0" />...',
256            self.browser.contents)
257        self.assertMatches(
258            '...item_name="School Fee" item_amt="270000" bank_id="120" acct_num="1771180233"...',
259            self.browser.contents)
260        self.assertMatches(
261            '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...',
262            self.browser.contents)
263        self.assertMatches(
264            '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...',
265            self.browser.contents)
266
267    def test_interswitch_form_new_payment_cats(self):
268        # only a few categories covered
269
270        self.app['configuration']['2004'].certificate_fee = 6800.0
271        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
272        self.browser.open(self.payments_path + '/addop')
273        self.browser.getControl(name="form.p_category").value = ['certificate']
274        self.browser.getControl("Create ticket").click()
275        self.assertMatches('...ticket created...', self.browser.contents)
276        ctrl = self.browser.getControl(name='val_id')
277        value = ctrl.options[0]
278        self.browser.getLink(value).click()
279        self.assertMatches('...Amount Authorized...', self.browser.contents)
280        self.assertMatches(
281            '...<span>6800.0</span>...', self.browser.contents)
282        self.browser.getLink("CollegePAY", index=0).click()
283        self.assertEqual(self.student['payments'][value].amount_auth, 6800.0)
284        self.assertEqual(self.student['payments'][value].provider_amt, 300.0)
285        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
286        self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0)
287
288        self.app['configuration']['2004'].transcript_local_fee = 5000.0
289        self.browser.open(self.payments_path + '/addop')
290        self.browser.getControl(name="form.p_category").value = ['transcript_local']
291        self.browser.getControl("Create ticket").click()
292        ctrl = self.browser.getControl(name='val_id')
293        value = ctrl.options[1]
294        self.browser.getLink(value).click()
295        self.assertMatches('...Amount Authorized...', self.browser.contents)
296        self.assertMatches(
297            '...<span>5000.0</span>...', self.browser.contents)
298        self.payment_url = self.browser.url
299        self.browser.getLink("CollegePAY", index=0).click()
300        self.assertEqual(self.student['payments'][value].amount_auth, 5000.0)
301        self.assertEqual(self.student['payments'][value].provider_amt, 300.0)
302        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
303        self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0)
304
305        self.app['configuration']['2004'].loss_idcard_fee = 1000.0
306        self.browser.open(self.payments_path + '/addop')
307        self.browser.getControl(name="form.p_category").value = ['loss_idcard']
308        self.browser.getControl("Create ticket").click()
309        ctrl = self.browser.getControl(name='val_id')
310        value = ctrl.options[2]
311        self.browser.getLink(value).click()
312        self.assertMatches('...Amount Authorized...', self.browser.contents)
313        self.assertMatches(
314            '...<span>1000.0</span>...', self.browser.contents)
315        self.payment_url = self.browser.url
316        self.browser.getLink("CollegePAY", index=0).click()
317        self.assertEqual(self.student['payments'][value].amount_auth, 1000.0)
318        self.assertEqual(self.student['payments'][value].provider_amt, 9.0)
319        self.assertEqual(self.student['payments'][value].gateway_amt, 15.0)
320        self.assertEqual(self.student['payments'][value].thirdparty_amt, 6.0)
321
322        self.app['configuration']['2004'].loss_examcard_fee = 500.0
323        self.browser.open(self.payments_path + '/addop')
324        self.browser.getControl(name="form.p_category").value = ['loss_examcard']
325        self.browser.getControl("Create ticket").click()
326        ctrl = self.browser.getControl(name='val_id')
327        value = ctrl.options[3]
328        self.browser.getLink(value).click()
329        self.assertMatches('...Amount Authorized...', self.browser.contents)
330        self.assertMatches(
331            '...<span>500.0</span>...', self.browser.contents)
332        self.payment_url = self.browser.url
333        self.browser.getLink("CollegePAY", index=0).click()
334        self.assertEqual(self.student['payments'][value].amount_auth, 500.0)
335        self.assertEqual(self.student['payments'][value].provider_amt, 4.5)
336        self.assertEqual(self.student['payments'][value].gateway_amt, 7.5)
337        self.assertEqual(self.student['payments'][value].thirdparty_amt, 3)
338
339        self.app['configuration']['2004'].change_inst_fee = 6000.0
340        self.browser.open(self.payments_path + '/addop')
341        self.browser.getControl(name="form.p_category").value = ['change_inst']
342        self.browser.getControl("Create ticket").click()
343        ctrl = self.browser.getControl(name='val_id')
344        value = ctrl.options[4]
345        self.browser.getLink(value).click()
346        self.assertMatches('...Amount Authorized...', self.browser.contents)
347        self.assertMatches(
348            '...<span>6000.0</span>...', self.browser.contents)
349        self.payment_url = self.browser.url
350        self.browser.getLink("CollegePAY", index=0).click()
351        self.assertEqual(self.student['payments'][value].amount_auth, 6000.0)
352        self.assertEqual(self.student['payments'][value].provider_amt, 300.0)
353        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
354        self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0)
355
356        self.app['configuration']['2004'].loss_result_fee = 7000.0
357        self.browser.open(self.payments_path + '/addop')
358        self.browser.getControl(name="form.p_category").value = ['loss_result']
359        self.browser.getControl("Create ticket").click()
360        ctrl = self.browser.getControl(name='val_id')
361        value = ctrl.options[5]
362        self.browser.getLink(value).click()
363        self.assertMatches('...Amount Authorized...', self.browser.contents)
364        self.assertMatches(
365            '...<span>7000.0</span>...', self.browser.contents)
366        self.payment_url = self.browser.url
367        self.browser.getLink("CollegePAY", index=0).click()
368        self.assertEqual(self.student['payments'][value].amount_auth, 7000.0)
369        self.assertEqual(self.student['payments'][value].provider_amt, 300.0)
370        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
371        self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0)
372
373    @external_test
374    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
393        # First we have open InterswitchPageStudent to set provider_amt
394        # and gateway_amt
395        self.browser.open(self.payment_url + '/goto_interswitch')
396        # Now we can call the webservice
397        self.browser.open(self.payment_url + '/request_webservice')
398        self.assertMatches('...Unsuccessful callback...',
399                          self.browser.contents)
400        # The payment is now in state failed ...
401        self.assertMatches('...<span>Failed</span>...',
402                          self.browser.contents)
403        # ... and the catalog has been updated
404        cat = getUtility(ICatalog, name='payments_catalog')
405        results = list(
406            cat.searchResults(p_state=('failed', 'failed')))
407        self.assertEqual(len(results), 1)
408        self.assertEqual(results[0].p_state, 'failed')
409
410        # Let's replace the p_id with a valid p_id of the Kwarapoly
411        # live system. This is definitely not an appropriate
412        # solution for testing, but we have no choice since
413        # Interswitch doesn't provide any interface
414        # for testing.
415        payment = self.student['payments'][self.value]
416        payment.p_id = 'p3543612043224'
417        self.browser.open(self.payment_url + '/request_webservice')
418        self.assertMatches('...Callback amount does not match...',
419                          self.browser.contents)
420        # The payment is now in state failed ...
421        self.assertMatches('...<span>Failed</span>...',
422                          self.browser.contents)
423        # Let's replace the amount autorized with the amount of the
424        # live system payment
425        payment.amount_auth = payment.r_amount_approved
426        self.browser.open(self.payment_url + '/request_webservice')
427        self.assertMatches('...Successful payment...',
428                          self.browser.contents)
429        # The payment is now in state paid ...
430        self.assertMatches('...<span>Paid</span>...',
431                          self.browser.contents)
432        # ... and the catalog has been updated
433        cat = getUtility(ICatalog, name='payments_catalog')
434        results = list(
435            cat.searchResults(p_state=('paid', 'paid')))
436        self.assertEqual(len(results), 1)
437        self.assertEqual(results[0].p_state, 'paid')
438        # Approval is logged in students.log ...
439        logfile = os.path.join(
440            self.app['datacenter'].storage, 'logs', 'students.log')
441        logcontent = open(logfile).read()
442        self.assertTrue(
443            'zope.mgr - '
444            'waeup.kwarapoly.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
445            'W1000000 - successful schoolfee payment: p3543612043224\n'
446            in logcontent)
447        # ... and in payments.log
448        logfile = os.path.join(
449            self.app['datacenter'].storage, 'logs', 'payments.log')
450        logcontent = open(logfile).read()
451        self.assertTrue(
452            '"zope.mgr",W1000000,p3543612043224,schoolfee,'
453            '52100.0,00,1200.0,300.0,1800.0,,,\n'
454            in logcontent)
455
456
457class InterswitchTestsApplicants(ApplicantsFullSetup):
458    """Tests for the Interswitch payment gateway.
459    """
460
461    layer = FunctionalLayer
462
463    def setUp(self):
464        super(InterswitchTestsApplicants, self).setUp()
465        configuration = SessionConfiguration()
466        configuration.academic_session = datetime.now().year - 2
467        self.app['configuration'].addSessionConfiguration(configuration)
468        self.configuration = configuration
469        # Create at least one Kwarapoly faculty
470        self.app['faculties']['CPGS'] = Faculty(code='CPGS')
471        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
472        self.certificate2 = createObject('waeup.Certificate')
473        self.certificate2.code = u'CERT2'
474        self.certificate2.application_category = 'ndft'
475        self.certificate2.study_mode = 'nd_ft'
476        self.certificate2.start_level = 100
477        self.certificate2.end_level = 300
478        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
479            self.certificate2)
480        self.applicantscontainer.application_category = 'ndft'
481        self.applicant.applicant_id = u'nd_anything'
482       
483        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
484        self.browser.open(self.manage_path)
485        #IWorkflowState(self.student).setState('started')
486        super(InterswitchTestsApplicants, self).fill_correct_values()
487        self.browser.getControl(name="form.course1").value = ['CERT2']
488        self.applicantscontainer.application_fee = 3333.0
489        self.browser.getControl(name="form.nationality").value = ['NG']
490        self.browser.getControl(name="transition").value = ['start']
491        self.browser.getControl("Save").click()
492        self.browser.getControl("Add online").click()
493        self.assertMatches('...ticket created...',
494                           self.browser.contents)
495        self.assertMatches('...Amount Authorized...',
496                           self.browser.contents)
497        self.assertMatches(
498            '...<span>3333.0</span>...',
499            self.browser.contents)
500        self.payment_url = self.browser.url
501
502
503    def test_interswitch_form(self):
504
505        # Manager can access InterswitchForm
506        self.browser.getLink("CollegePAY", index=0).click()
507        self.assertMatches('...Total Amount Authorized:...',
508                           self.browser.contents)
509        self.assertTrue(
510            '<input type="hidden" name="amount" value="333300.0" />'
511            in self.browser.contents)
512        self.assertTrue(
513            '<item_detail item_id="1" item_name="application" '
514            'item_amt="253300" bank_id="8" acct_num="2014191363" />'
515            in self.browser.contents)
516
517        # hndft fee goes to another account
518        self.applicant.applicant_id = u'hnd_anything'
519        self.browser.open(self.manage_path)
520        ctrl = self.browser.getControl(name='val_id')
521        value = ctrl.options[0]
522        self.browser.getLink(value).click()
523        self.browser.getLink("CollegePAY", index=0).click()
524        self.assertTrue(
525            '<item_detail item_id="1" item_name="application" '
526            'item_amt="253300" bank_id="9" acct_num="7000016724" />'
527            in self.browser.contents)
528        # Commission or bribe?
529        self.assertTrue(
530            '<item_detail item_id="2" item_name="Dalash" item_amt="20000" '
531            'bank_id="117" acct_num="1013196791" />'
532            in self.browser.contents)
533        self.assertTrue(
534            '<item_detail item_id="3" item_name="BT Education" '
535            'item_amt="30000" bank_id="117" acct_num="1010764827" />'
536            in self.browser.contents)
537
538        # prehndft fee goes to another account
539        self.applicant.applicant_id = u'prehnd_anything'
540        self.browser.open(self.manage_path)
541        ctrl = self.browser.getControl(name='val_id')
542        value = ctrl.options[0]
543        self.browser.getLink(value).click()
544        self.browser.getLink("CollegePAY", index=0).click()
545        self.assertTrue(
546            '<item_detail item_id="1" item_name="application" '
547            'item_amt="303300" bank_id="8" acct_num="2013910271" />'
548            in self.browser.contents)
549        # No 'commission', no provider fee
550        self.assertFalse('Dalash' in self.browser.contents)
551        self.assertFalse('BT Education' in self.browser.contents)
552
553        # prejambites fee goes to another account
554        self.applicant.applicant_id = u'prejambites_anything'
555        self.browser.open(self.manage_path)
556        ctrl = self.browser.getControl(name='val_id')
557        value = ctrl.options[0]
558        self.browser.getLink(value).click()
559        self.browser.getLink("CollegePAY", index=0).click()
560        self.assertTrue(
561            '<item_detail item_id="1" item_name="application" '
562            'item_amt="303300" bank_id="10" acct_num="0106259811" />'
563            in self.browser.contents)
564        # No 'commission', no provider fee
565        self.assertFalse('Dalash' in self.browser.contents)
566        self.assertFalse('BT Education' in self.browser.contents)
567
568
569    def prepare_special_container(self):
570        # Add special application container
571        container_name = u'special%s' % (datetime.now().year - 2)
572        applicantscontainer = ApplicantsContainer()
573        applicantscontainer.code = container_name
574        applicantscontainer.prefix = 'special'
575        applicantscontainer.year = datetime.now().year - 2
576        applicantscontainer.title = u'This is a special app container'
577        applicantscontainer.application_category = 'no'
578        applicantscontainer.mode = 'create'
579        delta = timedelta(days=10)
580        applicantscontainer.startdate = datetime.now(pytz.utc) - delta
581        applicantscontainer.enddate = datetime.now(pytz.utc) + delta
582        applicantscontainer.strict_deadline = True
583        self.app['applicants'][container_name] = applicantscontainer
584        # Add an applicant
585        applicant = createObject('waeup.Applicant')
586        # reg_number is the only field which has to be preset here
587        # because managers are allowed to edit this required field
588        applicant.reg_number = u'12345'
589        applicant.firstname = u'Vorname'
590        applicant.lastname = u'Nachname'
591        applicant.email = 'aa@aa.aa'
592        applicant.special_application = u'transcript_local'
593        applicant.applicant_id = u'special_anything'
594        self.app['applicants'][container_name].addApplicant(applicant)
595        self.special_applicant = applicant
596        self.configuration.transcript_local_fee = 5300.0
597        self.special_manage_path = 'http://localhost/app/applicants/%s/%s/%s' % (
598            container_name, applicant.application_number, 'manage')
599
600    def test_interswitch_form_special(self):
601        self.prepare_special_container()
602        self.browser.open(self.special_manage_path)
603        self.browser.getControl("Add online").click()
604        self.assertMatches('...ticket created...',
605                           self.browser.contents)
606        self.browser.getLink("CollegePAY", index=0).click()
607        self.assertTrue(
608            '<item_detail item_id="1" item_name="transcript_local" '
609            'item_amt="450000" bank_id="9" acct_num="7000016724" />'
610            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 TracBrowser for help on using the repository browser.