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

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

Setup SELECTABLE_PAYMENT_CATEGORIES dictionary. Uniben students must not see the regular maintenance fee button.

  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1## $Id: tests.py 9731 2012-11-27 15:02:34Z 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>8150.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="815000.0" />...',
209            self.browser.contents)
210        self.assertMatches(
211            '...<item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="800000" bank_id="129" acct_num="0014414547" />...',
212            self.browser.contents)
213        self.assertFalse(
214            'item_name="BT Education"' in self.browser.contents)
215
216#    @external_test
217#    def test_callback(self):
218
219        # Manager can call callback manually
220#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
221#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
222#                          self.browser.contents)
223#        self.assertMatches('...Failed...',
224#                           self.browser.contents)
225#        self.browser.open(self.payment_url + '/isw_callback')
226#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
227#                          self.browser.contents)
228#        self.assertMatches('...Failed...',
229#                           self.browser.contents)
230#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
231#        self.assertMatches('...Wrong amount...',
232#                          self.browser.contents)
233#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
234#        self.assertMatches('...Valid callback received...',
235#                          self.browser.contents)
236
237    @external_test
238    def test_webservice(self):
239
240        self.browser.open(self.payment_url + '/request_webservice')
241        self.assertMatches('...Unsuccessful callback...',
242                          self.browser.contents)
243        # The payment is now in state failed ...
244        self.assertMatches('...<span>Failed</span>...',
245                          self.browser.contents)
246        # ... and the catalog has been updated
247        cat = getUtility(ICatalog, name='payments_catalog')
248        results = list(
249            cat.searchResults(p_state=('failed', 'failed')))
250        self.assertEqual(len(results), 1)
251        self.assertEqual(results[0].p_state, 'failed')
252
253class InterswitchTestsApplicants(ApplicantsFullSetup):
254    """Tests for the Interswitch payment gateway.
255    """
256
257    layer = FunctionalLayer
258
259    def setUp(self):
260        super(InterswitchTestsApplicants, self).setUp()
261        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
262        self.browser.open(self.manage_path)
263        #IWorkflowState(self.student).setState('started')
264        super(InterswitchTestsApplicants, self).fill_correct_values()
265        self.applicantscontainer.application_fee = 1000.0
266        self.browser.getControl(name="form.nationality").value = ['NG']
267        self.browser.getControl(name="transition").value = ['start']
268        self.browser.getControl("Save").click()
269        self.browser.getControl("Add online").click()
270        self.assertMatches('...ticket created...',
271                           self.browser.contents)
272        #ctrl = self.browser.getControl(name='val_id')
273        #value = ctrl.options[0]
274        #self.browser.getLink(value).click()
275        self.assertMatches('...Amount Authorized...',
276                           self.browser.contents)
277        self.assertMatches(
278            '...<span>1000.0</span>...',
279            self.browser.contents)
280        self.payment_url = self.browser.url
281
282
283    def test_interswitch_form(self):
284
285        # Manager can access InterswitchForm
286        self.browser.getLink("CollegePAY", index=0).click()
287        self.assertMatches('...Total Amount Authorized:...',
288                           self.browser.contents)
289        self.assertMatches(
290            '...<input type="hidden" name="amount" value="100000.0" />...',
291            self.browser.contents)
292
293    @external_test
294    def test_webservice(self):
295
296        self.browser.open(self.payment_url + '/request_webservice')
297        self.assertMatches('...Unsuccessful callback...',
298                          self.browser.contents)
299        # The payment is now in state failed
300        self.assertMatches('...<span>Failed</span>...',
301                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.