source: main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py @ 9693

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

BT split amount is 1600 not 500.

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1## $Id: tests.py 9682 2012-11-19 06:20:06Z 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.fceokene.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.browser.open(self.payments_path + '/addop')
52        self.browser.getControl(name="form.p_category").value = ['schoolfee']
53        self.browser.getControl("Create ticket").click()
54        self.assertMatches('...ticket created...',
55                           self.browser.contents)
56        ctrl = self.browser.getControl(name='val_id')
57        value = ctrl.options[0]
58        self.browser.getLink(value).click()
59        self.assertMatches('...Amount Authorized...',
60                           self.browser.contents)
61        self.assertMatches(
62            '...<span>12495.0</span>...',
63            self.browser.contents)
64        self.payment_url = self.browser.url
65
66
67#    def callback_url(self, payment_url, resp, apprAmt):
68#        return payment_url + (
69#            '/isw_callback?echo=' +
70#            '&resp=%s' +
71#            '&desc=Something went wrong' +
72#            '&txnRef=p1331792385335' +
73#            '&payRef=' + '&retRef=' +
74#            '&cardNum=0' +
75#            '&apprAmt=%s' +
76#            '&url=http://xyz') % (resp, apprAmt)
77
78    def test_interswitch_form(self):
79
80        # Manager can access InterswitchForm for the created school fee ticket
81        self.browser.getLink("CollegePAY", index=0).click()
82        self.assertMatches('...Total Amount Authorized:...',
83                           self.browser.contents)
84        self.assertMatches(
85            '...<input type="hidden" name="amount" value="1249500.0" />...',
86            self.browser.contents)
87        self.assertMatches(
88            '...item_name="School Fee" item_amt="934800" bank_id="117" acct_num="6216801033"...',
89            self.browser.contents)
90        self.assertMatches(
91            '...item_name="FCEOkene Split" item_amt="140000" bank_id="117" acct_num="6216801058"...',
92            self.browser.contents)
93        self.assertMatches(
94            '...item_name="BT Education" item_amt="160000" bank_id="31" acct_num="0026781725"...',
95            self.browser.contents)
96
97        # Let's do the same for maintenance fee payment
98
99        self.browser.open(self.payments_path)
100        self.browser.open(self.payments_path + '/addop')
101        self.browser.getControl(
102            name="form.p_category").value = ['hostel_maintenance']
103        self.browser.getControl("Create ticket").click()
104        self.assertMatches('...You have not yet booked accommodation...',
105                           self.browser.contents)
106        # Students have to book bed first
107        self.browser.open(self.acco_path)
108        IWorkflowState(self.student).setState('admitted')
109        self.browser.getLink("Book accommodation").click()
110        self.assertFalse('Activation Code:' in self.browser.contents)
111        self.browser.getControl("Create bed ticket").click()
112        # Bed is randomly selected but, since there is only
113        # one bed for this student, we know that ...
114        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
115                           self.browser.contents)
116        self.assertMatches('...ticket created...',
117                           self.browser.contents)
118        self.browser.open(self.payments_path + '/addop')
119        self.browser.getControl(
120            name="form.p_category").value = ['hostel_maintenance']
121        self.browser.getControl("Create ticket").click()
122        self.assertMatches('...ticket created...',
123                           self.browser.contents)
124        ctrl = self.browser.getControl(name='val_id')
125        value = ctrl.options[1]
126        self.browser.getLink(value).click()
127        self.assertMatches('...Amount Authorized...',
128                           self.browser.contents)
129        self.assertMatches(
130            '...<span>4150.0</span>...',
131            self.browser.contents)
132        self.payment_url = self.browser.url
133        # Manager can access InterswitchForm
134        self.browser.getLink("CollegePAY", index=0).click()
135        # The total amount to be processed by Interswitch
136        # has been reduced by the Interswitch fee of 150 Nairas
137        self.assertMatches('...Total Amount Authorized:...',
138                           self.browser.contents)
139        self.assertMatches(
140            '...<input type="hidden" name="amount" value="400000.0" />...',
141            self.browser.contents)
142        self.assertMatches(
143            '...item_name="Hostel Maintenance Fee" item_amt="385000" bank_id="117" acct_num="1012044132"...',
144            self.browser.contents)
145        # BT does nor charge a fee for maintenance fee
146        self.assertFalse("BT Education" in self.browser.contents)
147
148#    @external_test
149#    def test_callback(self):
150
151        # Manager can call callback manually
152#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
153#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
154#                          self.browser.contents)
155#        self.assertMatches('...Failed...',
156#                           self.browser.contents)
157#        self.browser.open(self.payment_url + '/isw_callback')
158#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
159#                          self.browser.contents)
160#        self.assertMatches('...Failed...',
161#                           self.browser.contents)
162#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
163#        self.assertMatches('...Wrong amount...',
164#                          self.browser.contents)
165#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
166#        self.assertMatches('...Valid callback received...',
167#                          self.browser.contents)
168
169    @external_test
170    def test_webservice(self):
171
172        self.browser.open(self.payment_url + '/request_webservice')
173        self.assertMatches('...Unsuccessful callback...',
174                          self.browser.contents)
175        # The payment is now in state failed
176        self.assertMatches('...<span>Failed</span>...',
177                          self.browser.contents)
178
179class InterswitchTestsApplicants(ApplicantsFullSetup):
180    """Tests for the Interswitch payment gateway.
181    """
182
183    layer = FunctionalLayer
184
185    def setUp(self):
186        super(InterswitchTestsApplicants, self).setUp()
187        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
188        self.browser.open(self.manage_path)
189        #IWorkflowState(self.student).setState('started')
190        super(InterswitchTestsApplicants, self).fill_correct_values()
191        self.applicantscontainer.application_fee = 1000.0
192        self.browser.getControl(name="form.nationality").value = ['NG']
193        self.browser.getControl(name="transition").value = ['start']
194        self.browser.getControl("Save").click()
195        self.browser.getControl("Add online").click()
196        self.assertMatches('...ticket created...',
197                           self.browser.contents)
198        #ctrl = self.browser.getControl(name='val_id')
199        #value = ctrl.options[0]
200        #self.browser.getLink(value).click()
201        self.assertMatches('...Amount Authorized...',
202                           self.browser.contents)
203        self.assertMatches(
204            '...<span>1000.0</span>...',
205            self.browser.contents)
206        self.payment_url = self.browser.url
207
208
209    def test_interswitch_form(self):
210
211        # Manager can access InterswitchForm
212        self.browser.getLink("CollegePAY", index=0).click()
213        self.assertMatches('...Total Amount Authorized:...',
214                           self.browser.contents)
215        self.assertMatches(
216            '...<input type="hidden" name="amount" value="100000.0" />...',
217            self.browser.contents)
218
219    @external_test
220    def test_webservice(self):
221
222        self.browser.open(self.payment_url + '/request_webservice')
223        self.assertMatches('...Unsuccessful callback...',
224                          self.browser.contents)
225        # The payment is now in state failed
226        self.assertMatches('...<span>Failed</span>...',
227                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.