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

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

Configure hostel maintenance fee payment (2012/2013 only).

  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1## $Id: tests.py 9727 2012-11-27 10:05:02Z 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##
18from zope.component import createObject, getUtility
19from zope.catalog.interfaces import ICatalog
20from hurry.workflow.interfaces import IWorkflowState
21from waeup.kofa.students.tests.test_browser import StudentsFullSetup
22from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
23from waeup.kofa.configuration import SessionConfiguration
24from waeup.uniben.testing import FunctionalLayer
25
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.
29EXTERNAL_TESTS = False
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
42class InterswitchTestsStudents(StudentsFullSetup):
43    """Tests for the Interswitch payment gateway.
44    """
45
46    layer = FunctionalLayer
47
48    def setUp(self):
49        super(InterswitchTestsStudents, self).setUp()
50        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
51        self.browser.open(self.payments_path)
52        IWorkflowState(self.student).setState('cleared')
53        self.student.nationality = u'NG'
54        self.browser.open(self.payments_path + '/addop')
55        self.browser.getControl(name="form.p_category").value = ['schoolfee']
56        self.browser.getControl("Create ticket").click()
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
68
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)
79
80    def test_interswitch_form(self):
81        # Manager can access InterswitchForm
82        self.browser.getLink("CollegePAY", index=0).click()
83        # The total amount to be processed by Interswitch
84        # has been reduced by the Interswitch fee of 150 Nairas
85        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5700" />...',
86                           self.browser.contents)
87        self.assertMatches('...Total Amount Authorized:...',
88                           self.browser.contents)
89        self.assertEqual(self.student.current_mode, 'ug_ft')
90        self.assertMatches(
91            '...<input type="hidden" name="amount" value="4000000.0" />...',
92            self.browser.contents)
93        self.assertMatches(
94            '...item_name="School Fee" item_amt="3835000" bank_id="8" acct_num="2017506430"...',
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)
99
100        # Create school fee ticket for returning students. Payment is made
101        # for next session.
102        current_payment_key = self.student['payments'].keys()[0]
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)
108        self.browser.open(self.payments_path + '/addop')
109        self.browser.getControl(name="form.p_category").value = ['schoolfee']
110        self.browser.getControl("Create ticket").click()
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
122        ctrl = self.browser.getControl(name='val_id')
123        value = ctrl.options[1]
124        self.browser.getLink(value).click()
125        self.browser.getLink("CollegePAY", index=0).click()
126        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
127                           self.browser.contents)
128        self.assertMatches(
129            '...<input type="hidden" name="amount" value="2000000.0" />...',
130            self.browser.contents)
131        self.assertMatches(
132            '...item_name="School Fee" item_amt="1835000" bank_id="16" acct_num="0122009929"...',
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(
146            '...<span>45000.0</span>...',
147            self.browser.contents)
148        # Manager can access InterswitchForm
149        self.browser.getLink("CollegePAY", index=0).click()
150        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
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
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)
190
191        # Create temp maint fee ticket
192        self.browser.open(self.payments_path + '/addop')
193        self.browser.getControl(name="form.p_category").value = ['tempmaint_1']
194        self.browser.getControl("Create ticket").click()
195        ctrl = self.browser.getControl(name='val_id')
196        value = ctrl.options[4]
197        self.browser.getLink(value).click()
198        self.assertMatches(
199            '...<span>8550.0</span>...',
200            self.browser.contents)
201        # Manager can access InterswitchForm
202        self.browser.getLink("CollegePAY", index=0).click()
203        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5705" />...',
204                           self.browser.contents)
205        self.assertMatches('...Total Amount Authorized:...',
206                           self.browser.contents)
207        self.assertMatches(
208            '...<input type="hidden" name="amount" value="855000.0" />...',
209            self.browser.contents)
210        self.assertMatches(
211            '...<item_detail item_id="1" item_name="Hostel Maint. Fee" item_amt="800000" bank_id="129" acct_num="0014414547" />...',
212            self.browser.contents)
213        self.assertMatches(
214            '...item_name="BT Education" item_amt="40000" bank_id="117" acct_num="1010764827"...',
215            self.browser.contents)
216
217
218#    @external_test
219#    def test_callback(self):
220
221        # Manager can call callback manually
222#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
223#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
224#                          self.browser.contents)
225#        self.assertMatches('...Failed...',
226#                           self.browser.contents)
227#        self.browser.open(self.payment_url + '/isw_callback')
228#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
229#                          self.browser.contents)
230#        self.assertMatches('...Failed...',
231#                           self.browser.contents)
232#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
233#        self.assertMatches('...Wrong amount...',
234#                          self.browser.contents)
235#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
236#        self.assertMatches('...Valid callback received...',
237#                          self.browser.contents)
238
239    @external_test
240    def test_webservice(self):
241
242        self.browser.open(self.payment_url + '/request_webservice')
243        self.assertMatches('...Unsuccessful callback...',
244                          self.browser.contents)
245        # The payment is now in state failed ...
246        self.assertMatches('...<span>Failed</span>...',
247                          self.browser.contents)
248        # ... and the catalog has been updated
249        cat = getUtility(ICatalog, name='payments_catalog')
250        results = list(
251            cat.searchResults(p_state=('failed', 'failed')))
252        self.assertEqual(len(results), 1)
253        self.assertEqual(results[0].p_state, 'failed')
254
255class InterswitchTestsApplicants(ApplicantsFullSetup):
256    """Tests for the Interswitch payment gateway.
257    """
258
259    layer = FunctionalLayer
260
261    def setUp(self):
262        super(InterswitchTestsApplicants, self).setUp()
263        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
264        self.browser.open(self.manage_path)
265        #IWorkflowState(self.student).setState('started')
266        super(InterswitchTestsApplicants, self).fill_correct_values()
267        self.applicantscontainer.application_fee = 1000.0
268        self.browser.getControl(name="form.nationality").value = ['NG']
269        self.browser.getControl(name="transition").value = ['start']
270        self.browser.getControl("Save").click()
271        self.browser.getControl("Add online").click()
272        self.assertMatches('...ticket created...',
273                           self.browser.contents)
274        #ctrl = self.browser.getControl(name='val_id')
275        #value = ctrl.options[0]
276        #self.browser.getLink(value).click()
277        self.assertMatches('...Amount Authorized...',
278                           self.browser.contents)
279        self.assertMatches(
280            '...<span>1000.0</span>...',
281            self.browser.contents)
282        self.payment_url = self.browser.url
283
284
285    def test_interswitch_form(self):
286
287        # Manager can access InterswitchForm
288        self.browser.getLink("CollegePAY", index=0).click()
289        self.assertMatches('...Total Amount Authorized:...',
290                           self.browser.contents)
291        self.assertMatches(
292            '...<input type="hidden" name="amount" value="100000.0" />...',
293            self.browser.contents)
294
295    @external_test
296    def test_webservice(self):
297
298        self.browser.open(self.payment_url + '/request_webservice')
299        self.assertMatches('...Unsuccessful callback...',
300                          self.browser.contents)
301        # The payment is now in state failed
302        self.assertMatches('...<span>Failed</span>...',
303                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.