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

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

Configure Interswitch module with hash value in form.

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1## $Id: tests.py 9392 2012-10-23 08:24:31Z 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
82
83#    def callback_url(self, payment_url, resp, apprAmt):
84#        return payment_url + (
85#            '/isw_callback?echo=' +
86#            '&resp=%s' +
87#            '&desc=Something went wrong' +
88#            '&txnRef=p1331792385335' +
89#            '&payRef=' + '&retRef=' +
90#            '&cardNum=0' +
91#            '&apprAmt=%s' +
92#            '&url=http://xyz') % (resp, apprAmt)
93
94    def test_interswitch_form(self):
95
96        # In the setup method we created the ticket
97        self.assertMatches('...ticket created...',
98                           self.browser.contents)
99        ctrl = self.browser.getControl(name='val_id')
100        value = ctrl.options[0]
101        self.browser.getLink(value).click()
102        self.assertMatches('...Amount Authorized...',
103                           self.browser.contents)
104        self.assertMatches(
105            '...<span>37100.0</span>...',
106            self.browser.contents)
107        self.payment_url = self.browser.url
108
109        # Manager can access InterswitchForm
110        self.browser.getLink("CollegePAY", index=0).click()
111        self.assertMatches('...Total Amount Authorized:...',
112                           self.browser.contents)
113        self.assertMatches(
114            '...<input type="hidden" name="amount" value="3710000.0" />...',
115            self.browser.contents)
116        self.assertMatches(
117            '...item_name="schoolfee" item_amt="3380000" bank_id="120" acct_num="1771180233"...',
118            self.browser.contents)
119        self.assertMatches(
120            '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...',
121            self.browser.contents)
122        self.assertMatches(
123            '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...',
124            self.browser.contents)
125
126#    @external_test
127#    def test_callback(self):
128
129        # Manager can call callback manually
130#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
131#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
132#                          self.browser.contents)
133#        self.assertMatches('...Failed...',
134#                           self.browser.contents)
135#        self.browser.open(self.payment_url + '/isw_callback')
136#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
137#                          self.browser.contents)
138#        self.assertMatches('...Failed...',
139#                           self.browser.contents)
140#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
141#        self.assertMatches('...Wrong amount...',
142#                          self.browser.contents)
143#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
144#        self.assertMatches('...Valid callback received...',
145#                          self.browser.contents)
146
147    @external_test
148    def test_webservice(self):
149
150        self.browser.open(self.payment_url + '/request_webservice')
151        self.assertMatches('...Unsuccessful callback...',
152                          self.browser.contents)
153        # The payment is now in state failed
154        self.assertMatches('...<span>Failed</span>...',
155                          self.browser.contents)
156
157class InterswitchTestsApplicants(ApplicantsFullSetup):
158    """Tests for the Interswitch payment gateway.
159    """
160
161    layer = FunctionalLayer
162
163    def setUp(self):
164        super(InterswitchTestsApplicants, self).setUp()
165        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
166        self.browser.open(self.manage_path)
167        #IWorkflowState(self.student).setState('started')
168        super(InterswitchTestsApplicants, self).fill_correct_values()
169        self.applicantscontainer.application_fee = 1000.0
170        self.browser.getControl(name="transition").value = ['start']
171        self.browser.getControl("Save").click()
172        self.browser.getControl("Add online").click()
173        self.assertMatches('...ticket created...',
174                           self.browser.contents)
175        #ctrl = self.browser.getControl(name='val_id')
176        #value = ctrl.options[0]
177        #self.browser.getLink(value).click()
178        self.assertMatches('...Amount Authorized...',
179                           self.browser.contents)
180        self.assertMatches(
181            '...<span>1000.0</span>...',
182            self.browser.contents)
183        self.payment_url = self.browser.url
184
185
186    def test_interswitch_form(self):
187
188        # Manager can access InterswitchForm
189        self.browser.getLink("CollegePAY", index=0).click()
190        self.assertMatches('...Total Amount Authorized:...',
191                           self.browser.contents)
192        self.assertMatches(
193            '...<input type="hidden" name="amount" value="100000.0" />...',
194            self.browser.contents)
195
196    @external_test
197    def test_webservice(self):
198
199        self.browser.open(self.payment_url + '/request_webservice')
200        self.assertMatches('...Unsuccessful callback...',
201                          self.browser.contents)
202        # The payment is now in state failed
203        self.assertMatches('...<span>Failed</span>...',
204                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.