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

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

Use dummy account number and bank id instead of empty string.

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1## $Id: tests.py 9385 2012-10-22 12:12:37Z 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 hurry.workflow.interfaces import IWorkflowState
19from waeup.kofa.students.tests.test_browser import StudentsFullSetup
20from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
21from waeup.kofa.configuration import SessionConfiguration
22from waeup.uniben.testing import FunctionalLayer
23
24# Also run tests that send requests to external servers?
25#   If you enable this, please make sure the external services
26#   do exist really and are not bothered by being spammed by a test programme.
27EXTERNAL_TESTS = False
28
29def external_test(func):
30    if not EXTERNAL_TESTS:
31        myself = __file__
32        if myself.endswith('.pyc'):
33            myself = myself[:-2]
34        print "WARNING: external tests are skipped!"
35        print "WARNING: edit %s to enable them." % myself
36        return
37    return func
38
39
40class InterswitchTestsStudents(StudentsFullSetup):
41    """Tests for the Interswitch payment gateway.
42    """
43
44    layer = FunctionalLayer
45
46    def setUp(self):
47        super(InterswitchTestsStudents, self).setUp()
48        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
49        self.browser.open(self.payments_path)
50        IWorkflowState(self.student).setState('cleared')
51        self.student.nationality = u'NG'
52        self.browser.open(self.payments_path + '/addop')
53        self.browser.getControl(name="form.p_category").value = ['schoolfee']
54        self.browser.getControl("Create ticket").click()
55        self.assertMatches('...ticket created...',
56                           self.browser.contents)
57        ctrl = self.browser.getControl(name='val_id')
58        value = ctrl.options[0]
59        self.browser.getLink(value).click()
60
61
62#    def callback_url(self, payment_url, resp, apprAmt):
63#        return payment_url + (
64#            '/isw_callback?echo=' +
65#            '&resp=%s' +
66#            '&desc=Something went wrong' +
67#            '&txnRef=p1331792385335' +
68#            '&payRef=' + '&retRef=' +
69#            '&cardNum=0' +
70#            '&apprAmt=%s' +
71#            '&url=http://xyz') % (resp, apprAmt)
72
73    def test_interswitch_form(self):
74
75        # School fee ticket already created in setUp method
76        self.assertMatches('...Amount Authorized...',
77                           self.browser.contents)
78        self.assertMatches(
79            '...<span>40000.0</span>...',
80            self.browser.contents)
81        self.payment_url = self.browser.url
82        # Manager can access InterswitchForm
83        self.browser.getLink("CollegePAY", index=0).click()
84        self.assertMatches('...Total Amount Authorized:...',
85                           self.browser.contents)
86        # The total amount to be processed by Interswitch
87        # has been reduced by the Interswitch fee of 150 Nairas
88        self.assertMatches('...Total Amount Authorized:...',
89                           self.browser.contents)
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="00" acct_num="000000000000"...',
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 clearance fee ticket
101        self.browser.open(self.payments_path + '/addop')
102        self.browser.getControl(name="form.p_category").value = ['clearance']
103        self.browser.getControl("Create ticket").click()
104        self.assertMatches('...ticket created...',
105                           self.browser.contents)
106        ctrl = self.browser.getControl(name='val_id')
107        value = ctrl.options[1]
108        self.browser.getLink(value).click()
109        self.assertMatches('...Amount Authorized...',
110                           self.browser.contents)
111        self.assertMatches(
112            '...<span>45000.0</span>...',
113            self.browser.contents)
114        # Manager can access InterswitchForm
115        self.browser.getLink("CollegePAY", index=0).click()
116        self.assertMatches('...Total Amount Authorized:...',
117                           self.browser.contents)
118        # The total amount to be processed by Interswitch
119        # has been reduced by the Interswitch fee of 150 Nairas
120        self.assertMatches('...Total Amount Authorized:...',
121                           self.browser.contents)
122        self.assertMatches(
123            '...<input type="hidden" name="amount" value="4500000.0" />...',
124            self.browser.contents)
125        self.assertMatches(
126            '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...',
127            self.browser.contents)
128        self.assertMatches(
129            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
130            self.browser.contents)
131
132
133#    @external_test
134#    def test_callback(self):
135
136        # Manager can call callback manually
137#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
138#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
139#                          self.browser.contents)
140#        self.assertMatches('...Failed...',
141#                           self.browser.contents)
142#        self.browser.open(self.payment_url + '/isw_callback')
143#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
144#                          self.browser.contents)
145#        self.assertMatches('...Failed...',
146#                           self.browser.contents)
147#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
148#        self.assertMatches('...Wrong amount...',
149#                          self.browser.contents)
150#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
151#        self.assertMatches('...Valid callback received...',
152#                          self.browser.contents)
153
154    @external_test
155    def test_webservice(self):
156
157        self.browser.open(self.payment_url + '/request_webservice')
158        self.assertMatches('...Unsuccessful callback...',
159                          self.browser.contents)
160        # The payment is now in state failed
161        self.assertMatches('...<span>Failed</span>...',
162                          self.browser.contents)
163
164class InterswitchTestsApplicants(ApplicantsFullSetup):
165    """Tests for the Interswitch payment gateway.
166    """
167
168    layer = FunctionalLayer
169
170    def setUp(self):
171        super(InterswitchTestsApplicants, self).setUp()
172        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
173        self.browser.open(self.manage_path)
174        #IWorkflowState(self.student).setState('started')
175        super(InterswitchTestsApplicants, self).fill_correct_values()
176        self.applicantscontainer.application_fee = 1000.0
177        self.browser.getControl(name="transition").value = ['start']
178        self.browser.getControl("Save").click()
179        self.browser.getControl("Add online").click()
180        self.assertMatches('...ticket created...',
181                           self.browser.contents)
182        #ctrl = self.browser.getControl(name='val_id')
183        #value = ctrl.options[0]
184        #self.browser.getLink(value).click()
185        self.assertMatches('...Amount Authorized...',
186                           self.browser.contents)
187        self.assertMatches(
188            '...<span>1000.0</span>...',
189            self.browser.contents)
190        self.payment_url = self.browser.url
191
192
193    def test_interswitch_form(self):
194
195        # Manager can access InterswitchForm
196        self.browser.getLink("CollegePAY", index=0).click()
197        self.assertMatches('...Total Amount Authorized:...',
198                           self.browser.contents)
199        self.assertMatches(
200            '...<input type="hidden" name="amount" value="100000.0" />...',
201            self.browser.contents)
202
203    @external_test
204    def test_webservice(self):
205
206        self.browser.open(self.payment_url + '/request_webservice')
207        self.assertMatches('...Unsuccessful callback...',
208                          self.browser.contents)
209        # The payment is now in state failed
210        self.assertMatches('...<span>Failed</span>...',
211                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.