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

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

Disable condition: "Students are only allowed to pay for the next session if current session payment"

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