source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py @ 14292

Last change on this file since 14292 was 14122, checked in by Henrik Bettermann, 8 years ago

Split utme application payments.

  • Property svn:keywords set to Id
File size: 22.2 KB
RevLine 
[12730]1## $Id: tests.py 14122 2016-08-24 06:13:46Z henrik $
[11846]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
19from datetime import datetime, date, timedelta
20from zope.component import createObject, getUtility
21from zope.catalog.interfaces import ICatalog
22from hurry.workflow.interfaces import IWorkflowState
23from waeup.kofa.students.tests.test_browser import StudentsFullSetup
24from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
25from waeup.kofa.configuration import SessionConfiguration
26from waeup.aaue.testing import FunctionalLayer
27
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.
[13388]31EXTERNAL_TESTS = False
[11846]32
33def external_test(func):
34    if not EXTERNAL_TESTS:
35        myself = __file__
36        if myself.endswith('.pyc'):
37            myself = myself[:-2]
38        print "WARNING: external tests are skipped!"
39        print "WARNING: edit %s to enable them." % myself
40        return
41    return func
42
43
44class InterswitchTestsApplicants(ApplicantsFullSetup):
45    """Tests for the Interswitch payment gateway.
46    """
47
48    layer = FunctionalLayer
49
50    def setUp(self):
51        super(InterswitchTestsApplicants, self).setUp()
52        configuration = SessionConfiguration()
53        configuration.academic_session = datetime.now().year - 2
54        self.app['configuration'].addSessionConfiguration(configuration)
55        self.configuration = configuration
56        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
57        self.browser.open(self.manage_path)
58        #IWorkflowState(self.student).setState('started')
59        super(InterswitchTestsApplicants, self).fill_correct_values()
[13977]60        #self.browser.getControl(name="form.programme_type").value = ['regular']
[13532]61        self.applicantscontainer.application_fee = 10000.0
[11846]62        self.browser.getControl(name="form.nationality").value = ['NG']
63        self.browser.getControl(name="transition").value = ['start']
64        self.browser.getControl("Save").click()
[13532]65
66    def test_interswitch_form_regular(self):
[11846]67        self.browser.getControl("Add online").click()
[13381]68        self.assertTrue('ticket created' in self.browser.contents)
[11846]69        #self.browser.getLink(value).click()
[13381]70        self.assertTrue('Amount Authorized' in self.browser.contents)
[13532]71        self.assertTrue('<span>10000.0</span>' in self.browser.contents)
[11846]72        self.payment_url = self.browser.url
73        # Manager can access InterswitchForm
74        self.browser.getLink("CollegePAY", index=0).click()
[13381]75        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
76        self.assertTrue(
[13532]77            '<input type="hidden" name="amount" value="1000000" />'
[13381]78            in self.browser.contents)
[13532]79        self.assertTrue(
[14081]80            'item_name="BT Education" item_amt="200000"'
[13532]81            in self.browser.contents)
82        self.assertTrue(
[14081]83            'item_name="Application Fee" item_amt="775000" bank_id="117" acct_num="1010835352"'
[13532]84            in self.browser.contents)
85        self.assertTrue(
86            '<input type="hidden" name="product_id" value="5845" />'
87            in self.browser.contents)
[13017]88        delta = timedelta(days=8)
[12977]89        self.applicant.values()[0].creation_date -= delta
90        self.browser.open(self.payment_url)
91        self.browser.getLink("CollegePAY", index=0).click()
[13381]92        self.assertTrue(
93            'This payment ticket is too old. Please create a new ticket'
94            in self.browser.contents)
[11846]95
[14121]96    def test_interswitch_form_pg(self):
97        self.applicant.applicant_id = u'pg_anything'
98        self.browser.getControl("Add online").click()
99        self.assertTrue('ticket created' in self.browser.contents)
100        #self.browser.getLink(value).click()
101        self.assertTrue('Amount Authorized' in self.browser.contents)
102        self.assertTrue('<span>10000.0</span>' in self.browser.contents)
103        self.payment_url = self.browser.url
104        # Manager can access InterswitchForm
105        self.browser.getLink("CollegePAY", index=0).click()
106        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
107        self.assertTrue(
108            '<input type="hidden" name="amount" value="1000000" />'
109            in self.browser.contents)
110        self.assertTrue(
111            'item_name="BT Education" item_amt="200000"'
112            in self.browser.contents)
113        self.assertTrue(
114            'item_name="Application Fee" item_amt="575000" bank_id="117" acct_num="1010835352"'
115            in self.browser.contents)
116        self.assertTrue(
117            'item_name="PG Handbook" item_amt="200000" bank_id="117" acct_num="1014270207"'
118            in self.browser.contents)
119        self.assertTrue(
120            '<input type="hidden" name="product_id" value="5845" />'
121            in self.browser.contents)
122        delta = timedelta(days=8)
123        self.applicant.values()[0].creation_date -= delta
124        self.browser.open(self.payment_url)
125        self.browser.getLink("CollegePAY", index=0).click()
126        self.assertTrue(
127            'This payment ticket is too old. Please create a new ticket'
128            in self.browser.contents)
129
[14122]130    def test_interswitch_form_utme(self):
131        self.applicant.applicant_id = u'utme_anything'
132        self.browser.getControl("Add online").click()
133        self.assertTrue('ticket created' in self.browser.contents)
134        #self.browser.getLink(value).click()
135        self.assertTrue('Amount Authorized' in self.browser.contents)
136        self.assertTrue('<span>10000.0</span>' in self.browser.contents)
137        self.payment_url = self.browser.url
138        # Manager can access InterswitchForm
139        self.browser.getLink("CollegePAY", index=0).click()
140        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
141        self.assertTrue(
142            '<input type="hidden" name="amount" value="1000000" />'
143            in self.browser.contents)
144        self.assertTrue(
145            'item_name="BT Education" item_amt="100000"'
146            in self.browser.contents)
147        self.assertTrue(
148            'item_name="Application Fee" item_amt="675000" bank_id="117" acct_num="1010835352"'
149            in self.browser.contents)
150        self.assertTrue(
151            'item_name="Screening Guide" item_amt="200000" bank_id="117" acct_num="1013879579"'
152            in self.browser.contents)
153        self.assertTrue(
154            '<input type="hidden" name="product_id" value="5845" />'
155            in self.browser.contents)
156        delta = timedelta(days=8)
157        self.applicant.values()[0].creation_date -= delta
158        self.browser.open(self.payment_url)
159        self.browser.getLink("CollegePAY", index=0).click()
160        self.assertTrue(
161            'This payment ticket is too old. Please create a new ticket'
162            in self.browser.contents)
163
[11846]164    @external_test
165    def test_webservice(self):
166
167        self.browser.open(self.payment_url + '/request_webservice')
[13381]168        self.assertTrue('Unsuccessful callback' in self.browser.contents)
[11846]169        # The payment is now in state failed
[13381]170        self.assertTrue('<span>Failed</span>' in self.browser.contents)
[11868]171
172class InterswitchTestsStudents(StudentsFullSetup):
173    """Tests for the Interswitch payment gateway.
174    """
175
176    layer = FunctionalLayer
177
178    def setUp(self):
179        super(InterswitchTestsStudents, self).setUp()
180
[13378]181    def test_interswitch_form_pt_school_fees(self):
182        self.certificate.study_mode = 'ug_pt'
[12975]183        self.student['studycourse'].entry_session = 2013
[13400]184        self.student['studycourse'].certificate.school_fee_1 = 50250.0
185        self.app['configuration']['2004'].union_fee = 1000.0
186        self.app['configuration']['2004'].welfare_fee = 500.0
[11868]187        # Manager can access InterswitchForm
188        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
189        self.browser.open(self.payments_path)
190        IWorkflowState(self.student).setState('cleared')
191        self.student.nationality = u'NG'
192        self.browser.open(self.payments_path + '/addop')
[13400]193        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
[11868]194        self.browser.getControl("Create ticket").click()
[13381]195        self.assertTrue('ticket created' in self.browser.contents)
196        ctrl = self.browser.getControl(name='val_id')
197        self.value = ctrl.options[0]
198        self.browser.getLink(self.value).click()
199        self.assertTrue('Amount Authorized' in self.browser.contents)
[13438]200        # 50250 + 1000 + 500 -500
201        self.assertTrue('<span>51250.0</span>' in self.browser.contents)
[13381]202        self.payment_url = self.browser.url
203        self.browser.getLink("CollegePAY", index=0).click()
204        self.assertTrue(
205            'Please pay acceptance fee first' in self.browser.contents)
206        acc_payment = createObject('waeup.StudentOnlinePayment')
207        acc_payment.p_state = 'paid'
208        acc_payment.p_category = 'clearance'
209        self.student['payments']['xyz'] = acc_payment
210        self.browser.getLink("CollegePAY", index=0).click()
211        self.assertTrue('<input type="hidden" name="pay_item_id" value="105" />'
212                        in self.browser.contents)
213        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
214        self.assertEqual(self.student.current_mode, 'ug_pt')
215        self.assertTrue(
[13438]216            '<input type="hidden" name="amount" value="5125000" />'
[13381]217            in self.browser.contents)
218        self.assertTrue(
[13410]219            'item_name="School Fee Plus" '
[13400]220            'item_amt="4600000" bank_id="7" '
[13381]221            'acct_num="1014847058"' in self.browser.contents)
222
223    def test_interswitch_form_regular_school_fees(self):
224        self.certificate.study_mode = 'ug_ft'
225        self.student['studycourse'].entry_session = 2013
226        self.student['studycourse'].certificate.school_fee_1 = 51750.0
227        # Manager can access InterswitchForm
228        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
229        self.browser.open(self.payments_path)
230        IWorkflowState(self.student).setState('cleared')
231        self.student.nationality = u'NG'
232        self.browser.open(self.payments_path + '/addop')
[13421]233        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
[13381]234        self.browser.getControl("Create ticket").click()
235        self.assertTrue('ticket created' in
[11868]236                           self.browser.contents)
237        ctrl = self.browser.getControl(name='val_id')
238        self.value = ctrl.options[0]
239        self.browser.getLink(self.value).click()
[13381]240        self.assertTrue('Amount Authorized' in
[11868]241                           self.browser.contents)
[13381]242        self.assertTrue('<span>51750.0</span>' in self.browser.contents)
[11868]243        self.payment_url = self.browser.url
244        self.browser.getLink("CollegePAY", index=0).click()
[12975]245        self.assertTrue(
246            'Please pay acceptance fee first' in self.browser.contents)
247        acc_payment = createObject('waeup.StudentOnlinePayment')
248        acc_payment.p_state = 'paid'
249        acc_payment.p_category = 'clearance'
250        self.student['payments']['xyz'] = acc_payment
251        self.browser.getLink("CollegePAY", index=0).click()
[13652]252        self.assertTrue('<input type="hidden" name="pay_item_id" value="107" />'
[13381]253                        in self.browser.contents)
254        self.assertTrue('Total Amount Authorized:'
255                        in self.browser.contents)
256        self.assertEqual(self.student.current_mode, 'ug_ft')
257        self.assertTrue(
258            '<input type="hidden" name="amount" value="5175000" />'
259            in self.browser.contents)
260        self.assertTrue(
[13421]261            'item_name="School Fee Plus" item_amt="4750000" bank_id="117" '
[13381]262            'acct_num="1010827641"' in self.browser.contents)
[11868]263
[12975]264
[13378]265    def test_interswitch_form_pt_acceptance_fees(self):
266        self.certificate.study_mode = 'ug_pt'
[13678]267        self.app['configuration']['2004'].clearance_fee_ug_pt = 40250.0
[13400]268        self.app['configuration']['2004'].matric_gown_fee = 2000.0
269        self.app['configuration']['2004'].lapel_fee = 800.0
[12729]270        # Manager can access InterswitchForm
271        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
272        self.browser.open(self.payments_path)
273        IWorkflowState(self.student).setState('admitted')
274        self.student.nationality = u'NG'
275        self.browser.open(self.payments_path + '/addop')
[13400]276        self.browser.getControl(name="form.p_category").value = ['clearance_incl']
[12729]277        self.browser.getControl("Create ticket").click()
[13381]278        self.assertTrue('ticket created' in  self.browser.contents)
[12729]279        ctrl = self.browser.getControl(name='val_id')
280        self.value = ctrl.options[0]
281        self.browser.getLink(self.value).click()
[13381]282        self.assertTrue('Amount Authorized' in self.browser.contents)
[13438]283        # 40250 + 2000 + 800 - 500
284        self.assertTrue('<span>42550.0</span>' in self.browser.contents)
[12729]285        self.payment_url = self.browser.url
286        self.browser.getLink("CollegePAY", index=0).click()
[13381]287        self.assertTrue('<input type="hidden" name="pay_item_id" value="104" />' in
[12729]288                           self.browser.contents)
[13381]289        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
290        self.assertTrue(
[13438]291            '<input type="hidden" name="amount" value="4255000" />'
[13381]292            in self.browser.contents)
293        self.assertTrue(
[13410]294            'item_name="Acceptance Fee Plus" '
[13400]295            'item_amt="4000000" bank_id="117" '
[13381]296            'acct_num="1014066976"' in self.browser.contents)
[12729]297
[13381]298    def test_interswitch_form_regular_acceptance_fees(self):
299        self.certificate.study_mode = 'ug_ft'
300        self.app['configuration']['2004'].clearance_fee = 43050.0
301        # Manager can access InterswitchForm
302        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
303        self.browser.open(self.payments_path)
304        IWorkflowState(self.student).setState('admitted')
305        self.student.nationality = u'NG'
306        self.browser.open(self.payments_path + '/addop')
[13421]307        self.browser.getControl(name="form.p_category").value = ['clearance_incl']
[13381]308        self.browser.getControl("Create ticket").click()
309        self.assertTrue('ticket created' in self.browser.contents)
310        ctrl = self.browser.getControl(name='val_id')
311        self.value = ctrl.options[0]
312        self.browser.getLink(self.value).click()
313        self.assertTrue('Amount Authorized' in self.browser.contents)
314        self.assertTrue('<span>43050.0</span>' in self.browser.contents)
315        self.payment_url = self.browser.url
316        self.browser.getLink("CollegePAY", index=0).click()
317        self.assertTrue('<input type="hidden" name="pay_item_id" value="102" />'
318                        in self.browser.contents)
319        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
320        self.assertTrue(
321            '<input type="hidden" name="amount" value="4305000" />'
322            in self.browser.contents)
323        self.assertTrue(
[13421]324            'item_name="Acceptance Fee Plus" item_amt="4280000" bank_id="117" '
[13381]325            'acct_num="1010827641"' in self.browser.contents)
326
[13464]327    def test_interswitch_form_concessional_fees(self):
[13381]328        self.certificate.study_mode = 'ug_pt'
[13464]329        self.app['configuration']['2004'].concessional_fee = 1567.0
[13381]330        # Manager can access InterswitchForm
331        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
332        self.browser.open(self.payments_path)
333        IWorkflowState(self.student).setState('admitted')
334        self.student.nationality = u'NG'
335        self.browser.open(self.payments_path + '/addop')
[13421]336        self.browser.getControl(name="form.p_category").value = ['concessional']
[13381]337        self.browser.getControl("Create ticket").click()
338        self.assertTrue('ticket created' in  self.browser.contents)
339        ctrl = self.browser.getControl(name='val_id')
340        self.value = ctrl.options[0]
341        self.browser.getLink(self.value).click()
342        self.assertTrue('Amount Authorized' in self.browser.contents)
343        self.assertTrue(
344            '<span>1567.0</span>' in self.browser.contents)
345        self.payment_url = self.browser.url
346        self.certificate.study_mode = 'ug_ft'
347        self.browser.getLink("CollegePAY", index=0).click()
[13421]348        self.assertTrue('<input type="hidden" name="pay_item_id" value="107" />'
[13381]349                           in self.browser.contents)
350        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
351        self.assertTrue(
352            '<input type="hidden" name="amount" value="156700" />'
353            in self.browser.contents)
354        self.assertTrue(
[13438]355            'item_name="Concessional Fee" item_amt="131700" '
[13421]356            'bank_id="117" acct_num="1010835352"'
[13381]357            in self.browser.contents)
358
[12977]359    def test_interswitch_form_ticket_expired(self):
[13379]360        self.certificate.study_mode = 'ug_pt'
[12977]361        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
362        acc_payment = createObject('waeup.StudentOnlinePayment')
363        acc_payment.p_state = 'unpaid'
[13408]364        acc_payment.p_session = 2004
[12977]365        acc_payment.p_category = 'clearance'
366        acc_payment.p_id = 'xyz'
367        acc_payment.pay_item_id = '123'
368        acc_payment.amount_auth = 876.0
369        self.student['payments']['xyz'] = acc_payment
370        self.browser.open(self.payments_path + '/xyz')
371        self.browser.getLink("CollegePAY", index=0).click()
[13381]372        self.assertTrue('<input type="hidden" name="pay_item_id" value="104" />'
373                        in self.browser.contents)
374        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
[13379]375        self.assertEqual(self.student.current_mode, 'ug_pt')
[13381]376        self.assertTrue(
377            '<input type="hidden" name="amount" value="87600" />'
378            in self.browser.contents)
[13017]379        delta = timedelta(days=8)
[12977]380        acc_payment.creation_date -= delta
381        self.browser.open(self.payments_path + '/xyz')
382        self.browser.getLink("CollegePAY", index=0).click()
[13381]383        self.assertTrue(
384            'This payment ticket is too old. Please create a new ticket'
385            in self.browser.contents)
[13017]386        delta = timedelta(days=2)
[12977]387        acc_payment.creation_date += delta
388        self.browser.open(self.payments_path + '/xyz')
389        self.browser.getLink("CollegePAY", index=0).click()
[13381]390        self.assertTrue('Total Amount Authorized:' in self.browser.contents)
[12977]391
[11868]392    @external_test
393    def test_webservice(self):
394        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
395        self.browser.open(self.payments_path)
396        IWorkflowState(self.student).setState('cleared')
397        self.student.nationality = u'NG'
398        self.browser.open(self.payments_path + '/addop')
[13421]399        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
[11868]400        self.browser.getControl("Create ticket").click()
[13381]401        self.assertTrue('ticket created' in self.browser.contents)
[11868]402        ctrl = self.browser.getControl(name='val_id')
403        self.value = ctrl.options[0]
404        self.browser.getLink(self.value).click()
405        self.payment_url = self.browser.url
[13388]406        # First we have to open InterswitchPageStudent to set provider_amt
[11868]407        # and gateway_amt
408        self.browser.open(self.payment_url + '/goto_interswitch')
409        # Now we can call the webservice
410        self.browser.open(self.payment_url + '/request_webservice')
[13381]411        self.assertTrue('Unsuccessful callback' in self.browser.contents)
[11868]412        # The payment is now in state failed ...
[13381]413        self.assertTrue('<span>Failed</span>' in self.browser.contents)
[11868]414        # ... and the catalog has been updated
415        cat = getUtility(ICatalog, name='payments_catalog')
416        results = list(
417            cat.searchResults(p_state=('failed', 'failed')))
418        self.assertEqual(len(results), 1)
419        self.assertEqual(results[0].p_state, 'failed')
420
[13385]421        # Let's replace the p_id with a valid p_id of the AAUE
[11868]422        # live system. This is definitely not an appropriate
423        # solution for testing, but we have no choice since
424        # Interswitch doesn't provide any interface
425        # for testing.
426        payment = self.student['payments'][self.value]
[13385]427        payment.p_id = 'p4465649308559'
[11868]428        self.browser.open(self.payment_url + '/request_webservice')
[13388]429        self.assertTrue('Unsuccessful callback: Amount Inconsistency' in
[11868]430                          self.browser.contents)
431        # The payment is now in state failed ...
[13381]432        self.assertTrue('<span>Failed</span>' in self.browser.contents)
[11868]433        # Let's replace the amount autorized with the amount of the
434        # live system payment
[13388]435        payment.amount_auth = 60250.0
[11868]436        self.browser.open(self.payment_url + '/request_webservice')
[13381]437        self.assertTrue('Successful payment' in
[11868]438                          self.browser.contents)
439        # The payment is now in state paid ...
[13381]440        self.assertTrue('<span>Paid</span>' in self.browser.contents)
[11868]441        # ... and the catalog has been updated
442        cat = getUtility(ICatalog, name='payments_catalog')
443        results = list(
444            cat.searchResults(p_state=('paid', 'paid')))
445        self.assertEqual(len(results), 1)
446        self.assertEqual(results[0].p_state, 'paid')
447        # Approval is logged in students.log ...
448        logfile = os.path.join(
449            self.app['datacenter'].storage, 'logs', 'students.log')
450        logcontent = open(logfile).read()
451        self.assertTrue(
452            'zope.mgr - '
453            'waeup.aaue.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - '
[13530]454            'E1000000 - successful schoolfee_incl payment: p4465649308559\n'
[11868]455            in logcontent)
456        # ... and in payments.log
457        logfile = os.path.join(
458            self.app['datacenter'].storage, 'logs', 'payments.log')
459        logcontent = open(logfile).read()
460        self.assertTrue(
[13530]461            '"zope.mgr",E1000000,p4465649308559,schoolfee_incl,'
[13385]462            '60250.0,00,1500.0,250.0,0.0,,,\n'
[11868]463            in logcontent)
Note: See TracBrowser for help on using the repository browser.