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

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

Disable school fee payment so that no KwaraPoly? student accidentally pays FCEOkene school fees.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: tests.py 9370 2012-10-20 19:58:10Z 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.kwarapoly.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("Create ticket").click()
53
54
55#    def callback_url(self, payment_url, resp, apprAmt):
56#        return payment_url + (
57#            '/isw_callback?echo=' +
58#            '&resp=%s' +
59#            '&desc=Something went wrong' +
60#            '&txnRef=p1331792385335' +
61#            '&payRef=' + '&retRef=' +
62#            '&cardNum=0' +
63#            '&apprAmt=%s' +
64#            '&url=http://xyz') % (resp, apprAmt)
65
66    def test_interswitch_form(self):
67
68        # In the setup method we created the ticket
69        self.assertMatches('...ticket created...',
70                           self.browser.contents)
71        ctrl = self.browser.getControl(name='val_id')
72        value = ctrl.options[0]
73        self.browser.getLink(value).click()
74        self.assertMatches('...Amount Authorized...',
75                           self.browser.contents)
76        self.assertMatches(
77            '...<span>12495.0</span>...',
78            self.browser.contents)
79        self.payment_url = self.browser.url
80
81        # Manager can access InterswitchForm
82        self.browser.getLink("CollegePAY", index=0).click()
83        self.assertMatches('...Total Amount Authorized:...',
84                           self.browser.contents)
85        self.assertMatches(
86            '...<input type="hidden" name="amount" value="1249500.0" />...',
87            self.browser.contents)
88        self.assertMatches(
89            '...item_name="schoolfee" item_amt="1044500" bank_id="117" acct_num="6216801033"...',
90            self.browser.contents)
91        self.assertMatches(
92            '...item_name="KwaraPoly Split" item_amt="140000" bank_id="117" acct_num="6216801058"...',
93            self.browser.contents)
94        self.assertMatches(
95            '...item_name="BT Education" item_amt="50000" bank_id="31" acct_num="0026781725"...',
96            self.browser.contents)
97
98#    @external_test
99#    def test_callback(self):
100
101        # Manager can call callback manually
102#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
103#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
104#                          self.browser.contents)
105#        self.assertMatches('...Failed...',
106#                           self.browser.contents)
107#        self.browser.open(self.payment_url + '/isw_callback')
108#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
109#                          self.browser.contents)
110#        self.assertMatches('...Failed...',
111#                           self.browser.contents)
112#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
113#        self.assertMatches('...Wrong amount...',
114#                          self.browser.contents)
115#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
116#        self.assertMatches('...Valid callback received...',
117#                          self.browser.contents)
118
119    @external_test
120    def test_webservice(self):
121
122        self.browser.open(self.payment_url + '/request_webservice')
123        self.assertMatches('...Unsuccessful callback...',
124                          self.browser.contents)
125        # The payment is now in state failed
126        self.assertMatches('...<span>Failed</span>...',
127                          self.browser.contents)
128
129class InterswitchTestsApplicants(ApplicantsFullSetup):
130    """Tests for the Interswitch payment gateway.
131    """
132
133    layer = FunctionalLayer
134
135    def setUp(self):
136        super(InterswitchTestsApplicants, self).setUp()
137        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
138        self.browser.open(self.manage_path)
139        #IWorkflowState(self.student).setState('started')
140        super(InterswitchTestsApplicants, self).fill_correct_values()
141        self.applicantscontainer.application_fee = 1000.0
142        self.browser.getControl(name="transition").value = ['start']
143        self.browser.getControl("Save").click()
144        self.browser.getControl("Add online").click()
145        self.assertMatches('...ticket created...',
146                           self.browser.contents)
147        #ctrl = self.browser.getControl(name='val_id')
148        #value = ctrl.options[0]
149        #self.browser.getLink(value).click()
150        self.assertMatches('...Amount Authorized...',
151                           self.browser.contents)
152        self.assertMatches(
153            '...<span>1000.0</span>...',
154            self.browser.contents)
155        self.payment_url = self.browser.url
156
157
158    def test_interswitch_form(self):
159
160        # Manager can access InterswitchForm
161        self.browser.getLink("CollegePAY", index=0).click()
162        self.assertMatches('...Total Amount Authorized:...',
163                           self.browser.contents)
164        self.assertMatches(
165            '...<input type="hidden" name="amount" value="100000.0" />...',
166            self.browser.contents)
167
168    @external_test
169    def test_webservice(self):
170
171        self.browser.open(self.payment_url + '/request_webservice')
172        self.assertMatches('...Unsuccessful callback...',
173                          self.browser.contents)
174        # The payment is now in state failed
175        self.assertMatches('...<span>Failed</span>...',
176                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.