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

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

Log payment category.

Adjust to previous revisions.

  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1## $Id: tests.py 9435 2012-10-26 21:48:51Z 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.assertMatches(
89            '...<input type="hidden" name="amount" value="4000000.0" />...',
90            self.browser.contents)
91        self.assertMatches(
92            '...item_name="School Fee" item_amt="3835000" bank_id="00" acct_num="000000000000"...',
93            self.browser.contents)
94        self.assertMatches(
95            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
96            self.browser.contents)
97
98        # Create school fee ticket for returning students
99        self.certificate.study_mode = u'ug_pt'
100        IWorkflowState(self.student).setState('returning')
101        configuration = createObject('waeup.SessionConfiguration')
102        configuration.academic_session = 2005
103        self.app['configuration'].addSessionConfiguration(configuration)
104        self.browser.open(self.payments_path + '/addop')
105        self.browser.getControl(name="form.p_category").value = ['schoolfee']
106        self.browser.getControl("Create ticket").click()
107        ctrl = self.browser.getControl(name='val_id')
108        value = ctrl.options[1]
109        self.browser.getLink(value).click()
110        self.browser.getLink("CollegePAY", index=0).click()
111        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
112                           self.browser.contents)
113        self.assertMatches(
114            '...<input type="hidden" name="amount" value="2000000.0" />...',
115            self.browser.contents)
116        self.assertMatches(
117            '...item_name="School Fee" item_amt="1835000" bank_id="00" acct_num="000000000000"...',
118            self.browser.contents)
119        self.assertMatches(
120            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
121            self.browser.contents)
122
123        # Create clearance fee ticket
124        self.browser.open(self.payments_path + '/addop')
125        self.browser.getControl(name="form.p_category").value = ['clearance']
126        self.browser.getControl("Create ticket").click()
127        ctrl = self.browser.getControl(name='val_id')
128        value = ctrl.options[2]
129        self.browser.getLink(value).click()
130        self.assertMatches(
131            '...<span>45000.0</span>...',
132            self.browser.contents)
133        # Manager can access InterswitchForm
134        self.browser.getLink("CollegePAY", index=0).click()
135        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
136                           self.browser.contents)
137        self.assertMatches('...Total Amount Authorized:...',
138                           self.browser.contents)
139        self.assertMatches(
140            '...<input type="hidden" name="amount" value="4500000.0" />...',
141            self.browser.contents)
142        self.assertMatches(
143            '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...',
144            self.browser.contents)
145        self.assertMatches(
146            '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...',
147            self.browser.contents)
148
149
150#    @external_test
151#    def test_callback(self):
152
153        # Manager can call callback manually
154#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
155#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
156#                          self.browser.contents)
157#        self.assertMatches('...Failed...',
158#                           self.browser.contents)
159#        self.browser.open(self.payment_url + '/isw_callback')
160#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
161#                          self.browser.contents)
162#        self.assertMatches('...Failed...',
163#                           self.browser.contents)
164#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
165#        self.assertMatches('...Wrong amount...',
166#                          self.browser.contents)
167#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
168#        self.assertMatches('...Valid callback received...',
169#                          self.browser.contents)
170
171    @external_test
172    def test_webservice(self):
173
174        self.browser.open(self.payment_url + '/request_webservice')
175        self.assertMatches('...Unsuccessful callback...',
176                          self.browser.contents)
177        # The payment is now in state failed
178        self.assertMatches('...<span>Failed</span>...',
179                          self.browser.contents)
180
181class InterswitchTestsApplicants(ApplicantsFullSetup):
182    """Tests for the Interswitch payment gateway.
183    """
184
185    layer = FunctionalLayer
186
187    def setUp(self):
188        super(InterswitchTestsApplicants, self).setUp()
189        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
190        self.browser.open(self.manage_path)
191        #IWorkflowState(self.student).setState('started')
192        super(InterswitchTestsApplicants, self).fill_correct_values()
193        self.applicantscontainer.application_fee = 1000.0
194        self.browser.getControl(name="transition").value = ['start']
195        self.browser.getControl("Save").click()
196        self.browser.getControl("Add online").click()
197        self.assertMatches('...ticket created...',
198                           self.browser.contents)
199        #ctrl = self.browser.getControl(name='val_id')
200        #value = ctrl.options[0]
201        #self.browser.getLink(value).click()
202        self.assertMatches('...Amount Authorized...',
203                           self.browser.contents)
204        self.assertMatches(
205            '...<span>1000.0</span>...',
206            self.browser.contents)
207        self.payment_url = self.browser.url
208
209
210    def test_interswitch_form(self):
211
212        # Manager can access InterswitchForm
213        self.browser.getLink("CollegePAY", index=0).click()
214        self.assertMatches('...Total Amount Authorized:...',
215                           self.browser.contents)
216        self.assertMatches(
217            '...<input type="hidden" name="amount" value="100000.0" />...',
218            self.browser.contents)
219
220    @external_test
221    def test_webservice(self):
222
223        self.browser.open(self.payment_url + '/request_webservice')
224        self.assertMatches('...Unsuccessful callback...',
225                          self.browser.contents)
226        # The payment is now in state failed
227        self.assertMatches('...<span>Failed</span>...',
228                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.