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

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

Setup xml data for co payments.

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