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

Last change on this file since 9718 was 9713, checked in by Henrik Bettermann, 12 years ago

Update payments catalog after interswitch payment.

  • Property svn:keywords set to Id
File size: 12.3 KB
RevLine 
[7894]1## $Id: tests.py 9713 2012-11-23 07:58:22Z 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##
[9713]18from zope.component import createObject, getUtility
19from zope.catalog.interfaces import ICatalog
[7894]20from hurry.workflow.interfaces import IWorkflowState
21from waeup.kofa.students.tests.test_browser import StudentsFullSetup
[8266]22from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
23from waeup.kofa.configuration import SessionConfiguration
[8020]24from waeup.uniben.testing import FunctionalLayer
[7894]25
[7970]26# Also run tests that send requests to external servers?
27#   If you enable this, please make sure the external services
28#   do exist really and are not bothered by being spammed by a test programme.
[8271]29EXTERNAL_TESTS = False
[7970]30
31def external_test(func):
32    if not EXTERNAL_TESTS:
33        myself = __file__
34        if myself.endswith('.pyc'):
35            myself = myself[:-2]
36        print "WARNING: external tests are skipped!"
37        print "WARNING: edit %s to enable them." % myself
38        return
39    return func
40
41
[8266]42class InterswitchTestsStudents(StudentsFullSetup):
[7929]43    """Tests for the Interswitch payment gateway.
[7894]44    """
45
46    layer = FunctionalLayer
47
[7970]48    def setUp(self):
[8266]49        super(InterswitchTestsStudents, self).setUp()
[7970]50        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[7995]51        self.browser.open(self.payments_path)
[7970]52        IWorkflowState(self.student).setState('cleared')
[9006]53        self.student.nationality = u'NG'
[7995]54        self.browser.open(self.payments_path + '/addop')
[9384]55        self.browser.getControl(name="form.p_category").value = ['schoolfee']
[7970]56        self.browser.getControl("Create ticket").click()
[9435]57        self.assertMatches('...ticket created...',
58                           self.browser.contents)
59        ctrl = self.browser.getControl(name='val_id')
60        value = ctrl.options[0]
61        self.browser.getLink(value).click()
62        self.assertMatches('...Amount Authorized...',
63                           self.browser.contents)
64        self.assertMatches(
65            '...<span>40000.0</span>...',
66            self.browser.contents)
67        self.payment_url = self.browser.url
[7970]68
[8263]69#    def callback_url(self, payment_url, resp, apprAmt):
70#        return payment_url + (
71#            '/isw_callback?echo=' +
72#            '&resp=%s' +
73#            '&desc=Something went wrong' +
74#            '&txnRef=p1331792385335' +
75#            '&payRef=' + '&retRef=' +
76#            '&cardNum=0' +
77#            '&apprAmt=%s' +
78#            '&url=http://xyz') % (resp, apprAmt)
[7894]79
[7970]80    def test_interswitch_form(self):
[7894]81        # Manager can access InterswitchForm
82        self.browser.getLink("CollegePAY", index=0).click()
[8266]83        # The total amount to be processed by Interswitch
84        # has been reduced by the Interswitch fee of 150 Nairas
[9389]85        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5700" />...',
86                           self.browser.contents)
[9384]87        self.assertMatches('...Total Amount Authorized:...',
88                           self.browser.contents)
[9460]89        self.assertEqual(self.student.current_mode, 'ug_ft')
[7894]90        self.assertMatches(
[8276]91            '...<input type="hidden" name="amount" value="4000000.0" />...',
[7894]92            self.browser.contents)
[9384]93        self.assertMatches(
[9460]94            '...item_name="School Fee" item_amt="3835000" bank_id="8" acct_num="2017506430"...',
[9384]95            self.browser.contents)
96        self.assertMatches(
97            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
98            self.browser.contents)
[7894]99
[9520]100        # Create school fee ticket for returning students. Payment is made
101        # for next session.
102        current_payment_key = self.student['payments'].keys()[0]
[9389]103        self.certificate.study_mode = u'ug_pt'
104        IWorkflowState(self.student).setState('returning')
105        configuration = createObject('waeup.SessionConfiguration')
106        configuration.academic_session = 2005
107        self.app['configuration'].addSessionConfiguration(configuration)
[9384]108        self.browser.open(self.payments_path + '/addop')
[9389]109        self.browser.getControl(name="form.p_category").value = ['schoolfee']
[9384]110        self.browser.getControl("Create ticket").click()
[9570]111
112        ## Next session payment can't be made ...
113        #self.assertMatches(
114        #    '...You have not yet paid your current/active session...',
115        #    self.browser.contents)
116        ## current session payment must be approved first.
117        #self.student['payments'][current_payment_key].approve()
118        #self.browser.open(self.payments_path + '/addop')
119        #self.browser.getControl(name="form.p_category").value = ['schoolfee']
120        #self.browser.getControl("Create ticket").click()
121
[9384]122        ctrl = self.browser.getControl(name='val_id')
123        value = ctrl.options[1]
124        self.browser.getLink(value).click()
[9389]125        self.browser.getLink("CollegePAY", index=0).click()
126        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
[9384]127                           self.browser.contents)
128        self.assertMatches(
[9389]129            '...<input type="hidden" name="amount" value="2000000.0" />...',
130            self.browser.contents)
131        self.assertMatches(
[9460]132            '...item_name="School Fee" item_amt="1835000" bank_id="16" acct_num="0122009929"...',
[9389]133            self.browser.contents)
134        self.assertMatches(
135            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
136            self.browser.contents)
137
138        # Create clearance fee ticket
139        self.browser.open(self.payments_path + '/addop')
140        self.browser.getControl(name="form.p_category").value = ['clearance']
141        self.browser.getControl("Create ticket").click()
142        ctrl = self.browser.getControl(name='val_id')
143        value = ctrl.options[2]
144        self.browser.getLink(value).click()
145        self.assertMatches(
[9384]146            '...<span>45000.0</span>...',
147            self.browser.contents)
148        # Manager can access InterswitchForm
149        self.browser.getLink("CollegePAY", index=0).click()
[9389]150        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
[9384]151                           self.browser.contents)
152        self.assertMatches('...Total Amount Authorized:...',
153                           self.browser.contents)
154        self.assertMatches(
155            '...<input type="hidden" name="amount" value="4500000.0" />...',
156            self.browser.contents)
157        self.assertMatches(
158            '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...',
159            self.browser.contents)
160        self.assertMatches(
161            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
162            self.browser.contents)
163
[9515]164        # Create gown fee ticket
165        configuration.maint_fee = 987.0
166        self.app['configuration']['2004'].gown_fee = 234.0
167        self.browser.open(self.payments_path + '/addop')
168        self.browser.getControl(name="form.p_category").value = ['gown']
169        self.browser.getControl("Create ticket").click()
170        ctrl = self.browser.getControl(name='val_id')
171        value = ctrl.options[3]
172        self.browser.getLink(value).click()
173        self.assertMatches(
174            '...<span>234.0</span>...',
175            self.browser.contents)
176        # Manager can access InterswitchForm
177        self.browser.getLink("CollegePAY", index=0).click()
178        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5704" />...',
179                           self.browser.contents)
180        self.assertMatches('...Total Amount Authorized:...',
181                           self.browser.contents)
182        self.assertMatches(
183            '...<input type="hidden" name="amount" value="23400.0" />...',
184            self.browser.contents)
185        self.assertMatches(
186            '...<item_detail item_id="1" item_name="Gown Hire Fee" item_amt="8400" bank_id="7" acct_num="1016232382" />...',
187            self.browser.contents)
188        self.assertFalse(
189            'item_name="BT Education"' in self.browser.contents)
[9384]190
[8263]191#    @external_test
192#    def test_callback(self):
[7970]193
[7894]194        # Manager can call callback manually
[8263]195#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
196#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
197#                          self.browser.contents)
198#        self.assertMatches('...Failed...',
199#                           self.browser.contents)
200#        self.browser.open(self.payment_url + '/isw_callback')
201#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
202#                          self.browser.contents)
203#        self.assertMatches('...Failed...',
204#                           self.browser.contents)
205#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
206#        self.assertMatches('...Wrong amount...',
207#                          self.browser.contents)
208#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
209#        self.assertMatches('...Valid callback received...',
210#                          self.browser.contents)
[7930]211
[7970]212    @external_test
[7930]213    def test_webservice(self):
214
[7970]215        self.browser.open(self.payment_url + '/request_webservice')
[7930]216        self.assertMatches('...Unsuccessful callback...',
217                          self.browser.contents)
[9713]218        # The payment is now in state failed ...
[8266]219        self.assertMatches('...<span>Failed</span>...',
220                          self.browser.contents)
[9713]221        # ... and the catalog has been updated
222        cat = getUtility(ICatalog, name='payments_catalog')
223        results = list(
224            cat.searchResults(p_state=('failed', 'failed')))
225        self.assertEqual(len(results), 1)
226        self.assertEqual(results[0].p_state, 'failed')
[8266]227
228class InterswitchTestsApplicants(ApplicantsFullSetup):
229    """Tests for the Interswitch payment gateway.
230    """
231
232    layer = FunctionalLayer
233
234    def setUp(self):
235        super(InterswitchTestsApplicants, self).setUp()
236        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
237        self.browser.open(self.manage_path)
238        #IWorkflowState(self.student).setState('started')
239        super(InterswitchTestsApplicants, self).fill_correct_values()
[8526]240        self.applicantscontainer.application_fee = 1000.0
[9453]241        self.browser.getControl(name="form.nationality").value = ['NG']
[8266]242        self.browser.getControl(name="transition").value = ['start']
243        self.browser.getControl("Save").click()
244        self.browser.getControl("Add online").click()
245        self.assertMatches('...ticket created...',
246                           self.browser.contents)
[8281]247        #ctrl = self.browser.getControl(name='val_id')
248        #value = ctrl.options[0]
249        #self.browser.getLink(value).click()
[8266]250        self.assertMatches('...Amount Authorized...',
251                           self.browser.contents)
252        self.assertMatches(
253            '...<span>1000.0</span>...',
254            self.browser.contents)
255        self.payment_url = self.browser.url
256
257
258    def test_interswitch_form(self):
259
260        # Manager can access InterswitchForm
261        self.browser.getLink("CollegePAY", index=0).click()
262        self.assertMatches('...Total Amount Authorized:...',
263                           self.browser.contents)
264        self.assertMatches(
[8276]265            '...<input type="hidden" name="amount" value="100000.0" />...',
[8266]266            self.browser.contents)
267
268    @external_test
269    def test_webservice(self):
270
271        self.browser.open(self.payment_url + '/request_webservice')
272        self.assertMatches('...Unsuccessful callback...',
273                          self.browser.contents)
274        # The payment is now in state failed
275        self.assertMatches('...<span>Failed</span>...',
276                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.