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

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

Set pay_item_id according to payment category. Extend test.

  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1## $Id: tests.py 9389 2012-10-22 16:29:57Z 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
57
58#    def callback_url(self, payment_url, resp, apprAmt):
59#        return payment_url + (
60#            '/isw_callback?echo=' +
61#            '&resp=%s' +
62#            '&desc=Something went wrong' +
63#            '&txnRef=p1331792385335' +
64#            '&payRef=' + '&retRef=' +
65#            '&cardNum=0' +
66#            '&apprAmt=%s' +
67#            '&url=http://xyz') % (resp, apprAmt)
68
69    def test_interswitch_form(self):
70
71        # School fee ticket already created in setUp method
72        self.assertMatches('...ticket created...',
73                           self.browser.contents)
74        ctrl = self.browser.getControl(name='val_id')
75        value = ctrl.options[0]
76        self.browser.getLink(value).click()
77        self.assertMatches('...Amount Authorized...',
78                           self.browser.contents)
79        self.assertMatches(
80            '...<span>40000.0</span>...',
81            self.browser.contents)
82        self.payment_url = self.browser.url
83        # Manager can access InterswitchForm
84        self.browser.getLink("CollegePAY", index=0).click()
85        # The total amount to be processed by Interswitch
86        # has been reduced by the Interswitch fee of 150 Nairas
87        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5700" />...',
88                           self.browser.contents)
89        self.assertMatches('...Total Amount Authorized:...',
90                           self.browser.contents)
91        self.assertMatches(
92            '...<input type="hidden" name="amount" value="4000000.0" />...',
93            self.browser.contents)
94        self.assertMatches(
95            '...item_name="School Fee" item_amt="3835000" bank_id="00" acct_num="000000000000"...',
96            self.browser.contents)
97        self.assertMatches(
98            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
99            self.browser.contents)
100
101        # Create school fee ticket for returning students
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        ctrl = self.browser.getControl(name='val_id')
111        value = ctrl.options[1]
112        self.browser.getLink(value).click()
113        self.browser.getLink("CollegePAY", index=0).click()
114        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
115                           self.browser.contents)
116        self.assertMatches(
117            '...<input type="hidden" name="amount" value="2000000.0" />...',
118            self.browser.contents)
119        self.assertMatches(
120            '...item_name="School Fee" item_amt="1835000" bank_id="00" acct_num="000000000000"...',
121            self.browser.contents)
122        self.assertMatches(
123            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
124            self.browser.contents)
125
126        # Create clearance fee ticket
127        self.browser.open(self.payments_path + '/addop')
128        self.browser.getControl(name="form.p_category").value = ['clearance']
129        self.browser.getControl("Create ticket").click()
130        ctrl = self.browser.getControl(name='val_id')
131        value = ctrl.options[2]
132        self.browser.getLink(value).click()
133        self.assertMatches(
134            '...<span>45000.0</span>...',
135            self.browser.contents)
136        # Manager can access InterswitchForm
137        self.browser.getLink("CollegePAY", index=0).click()
138        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
139                           self.browser.contents)
140        self.assertMatches('...Total Amount Authorized:...',
141                           self.browser.contents)
142        self.assertMatches(
143            '...<input type="hidden" name="amount" value="4500000.0" />...',
144            self.browser.contents)
145        self.assertMatches(
146            '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...',
147            self.browser.contents)
148        self.assertMatches(
149            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
150            self.browser.contents)
151
152
153#    @external_test
154#    def test_callback(self):
155
156        # Manager can call callback manually
157#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
158#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
159#                          self.browser.contents)
160#        self.assertMatches('...Failed...',
161#                           self.browser.contents)
162#        self.browser.open(self.payment_url + '/isw_callback')
163#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
164#                          self.browser.contents)
165#        self.assertMatches('...Failed...',
166#                           self.browser.contents)
167#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
168#        self.assertMatches('...Wrong amount...',
169#                          self.browser.contents)
170#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
171#        self.assertMatches('...Valid callback received...',
172#                          self.browser.contents)
173
174    @external_test
175    def test_webservice(self):
176
177        self.browser.open(self.payment_url + '/request_webservice')
178        self.assertMatches('...Unsuccessful callback...',
179                          self.browser.contents)
180        # The payment is now in state failed
181        self.assertMatches('...<span>Failed</span>...',
182                          self.browser.contents)
183
184class InterswitchTestsApplicants(ApplicantsFullSetup):
185    """Tests for the Interswitch payment gateway.
186    """
187
188    layer = FunctionalLayer
189
190    def setUp(self):
191        super(InterswitchTestsApplicants, self).setUp()
192        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
193        self.browser.open(self.manage_path)
194        #IWorkflowState(self.student).setState('started')
195        super(InterswitchTestsApplicants, self).fill_correct_values()
196        self.applicantscontainer.application_fee = 1000.0
197        self.browser.getControl(name="transition").value = ['start']
198        self.browser.getControl("Save").click()
199        self.browser.getControl("Add online").click()
200        self.assertMatches('...ticket created...',
201                           self.browser.contents)
202        #ctrl = self.browser.getControl(name='val_id')
203        #value = ctrl.options[0]
204        #self.browser.getLink(value).click()
205        self.assertMatches('...Amount Authorized...',
206                           self.browser.contents)
207        self.assertMatches(
208            '...<span>1000.0</span>...',
209            self.browser.contents)
210        self.payment_url = self.browser.url
211
212
213    def test_interswitch_form(self):
214
215        # Manager can access InterswitchForm
216        self.browser.getLink("CollegePAY", index=0).click()
217        self.assertMatches('...Total Amount Authorized:...',
218                           self.browser.contents)
219        self.assertMatches(
220            '...<input type="hidden" name="amount" value="100000.0" />...',
221            self.browser.contents)
222
223    @external_test
224    def test_webservice(self):
225
226        self.browser.open(self.payment_url + '/request_webservice')
227        self.assertMatches('...Unsuccessful callback...',
228                          self.browser.contents)
229        # The payment is now in state failed
230        self.assertMatches('...<span>Failed</span>...',
231                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.