source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py @ 9617

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

Insert bank account details for maint fee. pay_item:id is still missing.

  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1## $Id: tests.py 9617 2012-11-11 17:08:27Z 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##
18import grok
19from hurry.workflow.interfaces import IWorkflowState
20from zope.component import createObject
21from zope.event import notify
22from waeup.kofa.university.faculty import Faculty
23from waeup.kofa.university.department import Department
24from waeup.kofa.students.tests.test_browser import StudentsFullSetup
25from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
26from waeup.kofa.configuration import SessionConfiguration
27from waeup.kwarapoly.testing import FunctionalLayer
28
29# Also run tests that send requests to external servers?
30#   If you enable this, please make sure the external services
31#   do exist really and are not bothered by being spammed by a test programme.
32EXTERNAL_TESTS = False
33
34def external_test(func):
35    if not EXTERNAL_TESTS:
36        myself = __file__
37        if myself.endswith('.pyc'):
38            myself = myself[:-2]
39        print "WARNING: external tests are skipped!"
40        print "WARNING: edit %s to enable them." % myself
41        return
42    return func
43
44
45class InterswitchTestsStudents(StudentsFullSetup):
46    """Tests for the Interswitch payment gateway.
47    """
48
49    layer = FunctionalLayer
50
51    def setUp(self):
52        super(InterswitchTestsStudents, self).setUp()
53
54        # Create at least one Kwarapoly faculty
55        self.app['faculties']['CPGS'] = Faculty(code='CPGS')
56        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
57        self.certificate2 = createObject('waeup.Certificate')
58        self.certificate2.code = u'CERT2'
59        self.certificate2.application_category = 'basic'
60        self.certificate2.study_mode = 'nd_ft'
61        self.certificate2.start_level = 100
62        self.certificate2.end_level = 300
63        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
64            self.certificate2)
65        # Set study course attributes of test student
66        self.student['studycourse'].certificate = self.certificate2
67        self.student['studycourse'].current_session = 2004
68        self.student['studycourse'].entry_session = 2004
69        self.student['studycourse'].current_verdict = 'A'
70        self.student['studycourse'].current_level = 100
71        # Set local lga
72        self.student.lga = u'kwara_asa'
73        # Update the catalog
74        notify(grok.ObjectModifiedEvent(self.student))
75
76        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
77        self.browser.open(self.payments_path)
78        IWorkflowState(self.student).setState('cleared')
79        self.browser.open(self.payments_path + '/addop')
80        self.browser.getControl("Create ticket").click()
81        self.assertMatches('...ticket created...',
82                           self.browser.contents)
83        ctrl = self.browser.getControl(name='val_id')
84        value = ctrl.options[0]
85        self.browser.getLink(value).click()
86        self.assertMatches('...Amount Authorized...',
87                           self.browser.contents)
88        self.assertMatches(
89            '...<span>36600.0</span>...',
90            self.browser.contents)
91        self.payment_url = self.browser.url
92
93
94#    def callback_url(self, payment_url, resp, apprAmt):
95#        return payment_url + (
96#            '/isw_callback?echo=' +
97#            '&resp=%s' +
98#            '&desc=Something went wrong' +
99#            '&txnRef=p1331792385335' +
100#            '&payRef=' + '&retRef=' +
101#            '&cardNum=0' +
102#            '&apprAmt=%s' +
103#            '&url=http://xyz') % (resp, apprAmt)
104
105    def test_interswitch_form(self):
106        # Manager can access InterswitchForm
107        self.browser.getLink("CollegePAY", index=0).click()
108        self.assertMatches('...Total Amount Authorized:...',
109                           self.browser.contents)
110        self.assertMatches(
111            '...<input type="hidden" name="amount" value="3710000.0" />...',
112            self.browser.contents)
113        self.assertMatches(
114            '...item_name="School Fee" item_amt="3380000" bank_id="120" acct_num="1771180233"...',
115            self.browser.contents)
116        self.assertMatches(
117            '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...',
118            self.browser.contents)
119        self.assertMatches(
120            '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...',
121            self.browser.contents)
122
123        # Let's do the same for maintenance fee payment
124
125        self.browser.open(self.payments_path)
126        self.browser.open(self.payments_path + '/addop')
127        self.browser.getControl(
128            name="form.p_category").value = ['hostel_maintenance']
129        self.browser.getControl("Create ticket").click()
130        self.assertMatches('...You have not yet booked accommodation...',
131                           self.browser.contents)
132        # Students have to book bed first
133        self.browser.open(self.acco_path)
134        IWorkflowState(self.student).setState('admitted')
135        self.browser.getLink("Book accommodation").click()
136        self.assertFalse('Activation Code:' in self.browser.contents)
137        self.browser.getControl("Create bed ticket").click()
138        # Bed is randomly selected but, since there is only
139        # one bed for this student, we know that ...
140        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
141                           self.browser.contents)
142        self.assertMatches('...ticket created...',
143                           self.browser.contents)
144        self.browser.open(self.payments_path + '/addop')
145        self.browser.getControl(
146            name="form.p_category").value = ['hostel_maintenance']
147        self.browser.getControl("Create ticket").click()
148        self.assertMatches('...ticket created...',
149                           self.browser.contents)
150        ctrl = self.browser.getControl(name='val_id')
151        value = ctrl.options[1]
152        self.browser.getLink(value).click()
153        self.assertMatches('...Amount Authorized...',
154                           self.browser.contents)
155
156        # So far maintenance fee is not yet properly configured!!!
157
158        # Maint fee is taken from the session configuration object
159        self.assertMatches(
160            '...<span>987.0</span>...',
161            self.browser.contents)
162        self.payment_url = self.browser.url
163        # Manager can access InterswitchForm
164        self.browser.getLink("CollegePAY", index=0).click()
165        # The total amount to be processed by Interswitch
166        # has been reduced by the Interswitch fee of 150 Nairas
167        self.assertMatches('...Total Amount Authorized:...',
168                           self.browser.contents)
169        self.assertMatches(
170            '...<input type="hidden" name="amount" value="98700.0" />...',
171            self.browser.contents)
172        self.assertMatches(
173            '...item_name="Hostel Maintenance Fee" item_amt="68700" bank_id="31" acct_num="0039050937"...',
174            self.browser.contents)
175        # BT does nor charge a fee for maintenance fee
176        #self.assertFalse("BT Education" in self.browser.contents)
177
178#    @external_test
179#    def test_callback(self):
180
181        # Manager can call callback manually
182#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
183#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
184#                          self.browser.contents)
185#        self.assertMatches('...Failed...',
186#                           self.browser.contents)
187#        self.browser.open(self.payment_url + '/isw_callback')
188#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
189#                          self.browser.contents)
190#        self.assertMatches('...Failed...',
191#                           self.browser.contents)
192#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
193#        self.assertMatches('...Wrong amount...',
194#                          self.browser.contents)
195#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
196#        self.assertMatches('...Valid callback received...',
197#                          self.browser.contents)
198
199    @external_test
200    def test_webservice(self):
201
202        self.browser.open(self.payment_url + '/request_webservice')
203        self.assertMatches('...Unsuccessful callback...',
204                          self.browser.contents)
205        # The payment is now in state failed
206        self.assertMatches('...<span>Failed</span>...',
207                          self.browser.contents)
208
209class InterswitchTestsApplicants(ApplicantsFullSetup):
210    """Tests for the Interswitch payment gateway.
211    """
212
213    layer = FunctionalLayer
214
215    def setUp(self):
216        super(InterswitchTestsApplicants, self).setUp()
217        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
218        self.browser.open(self.manage_path)
219        #IWorkflowState(self.student).setState('started')
220        super(InterswitchTestsApplicants, self).fill_correct_values()
221        self.applicantscontainer.application_fee = 1000.0
222        self.browser.getControl(name="form.nationality").value = ['NG']
223        self.browser.getControl(name="transition").value = ['start']
224        self.browser.getControl("Save").click()
225        self.browser.getControl("Add online").click()
226        self.assertMatches('...ticket created...',
227                           self.browser.contents)
228        #ctrl = self.browser.getControl(name='val_id')
229        #value = ctrl.options[0]
230        #self.browser.getLink(value).click()
231        self.assertMatches('...Amount Authorized...',
232                           self.browser.contents)
233        self.assertMatches(
234            '...<span>1000.0</span>...',
235            self.browser.contents)
236        self.payment_url = self.browser.url
237
238
239    def test_interswitch_form(self):
240
241        # Manager can access InterswitchForm
242        self.browser.getLink("CollegePAY", index=0).click()
243        self.assertMatches('...Total Amount Authorized:...',
244                           self.browser.contents)
245        self.assertMatches(
246            '...<input type="hidden" name="amount" value="100000.0" />...',
247            self.browser.contents)
248
249    @external_test
250    def test_webservice(self):
251
252        self.browser.open(self.payment_url + '/request_webservice')
253        self.assertMatches('...Unsuccessful callback...',
254                          self.browser.contents)
255        # The payment is now in state failed
256        self.assertMatches('...<span>Failed</span>...',
257                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.