source: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py @ 9169

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

Add special school fee regulations for staff members and foreign students.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: tests.py 9006 2012-07-16 07:36:13Z 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.uniben.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.student.nationality = u'NG'
52        self.browser.open(self.payments_path + '/addop')
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>40000.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
81        self.browser.getLink("CollegePAY", index=0).click()
82        self.assertMatches('...Total Amount Authorized:...',
83                           self.browser.contents)
84        # The total amount to be processed by Interswitch
85        # has been reduced by the Interswitch fee of 150 Nairas
86        self.assertMatches(
87            '...<input type="hidden" name="amount" value="4000000.0" />...',
88            self.browser.contents)
89
90#    @external_test
91#    def test_callback(self):
92
93        # Manager can call callback manually
94#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
95#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
96#                          self.browser.contents)
97#        self.assertMatches('...Failed...',
98#                           self.browser.contents)
99#        self.browser.open(self.payment_url + '/isw_callback')
100#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
101#                          self.browser.contents)
102#        self.assertMatches('...Failed...',
103#                           self.browser.contents)
104#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
105#        self.assertMatches('...Wrong amount...',
106#                          self.browser.contents)
107#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
108#        self.assertMatches('...Valid callback received...',
109#                          self.browser.contents)
110
111    @external_test
112    def test_webservice(self):
113
114        self.browser.open(self.payment_url + '/request_webservice')
115        self.assertMatches('...Unsuccessful callback...',
116                          self.browser.contents)
117        # The payment is now in state failed
118        self.assertMatches('...<span>Failed</span>...',
119                          self.browser.contents)
120
121class InterswitchTestsApplicants(ApplicantsFullSetup):
122    """Tests for the Interswitch payment gateway.
123    """
124
125    layer = FunctionalLayer
126
127    def setUp(self):
128        super(InterswitchTestsApplicants, self).setUp()
129        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
130        self.browser.open(self.manage_path)
131        #IWorkflowState(self.student).setState('started')
132        super(InterswitchTestsApplicants, self).fill_correct_values()
133        self.applicantscontainer.application_fee = 1000.0
134        self.browser.getControl(name="transition").value = ['start']
135        self.browser.getControl("Save").click()
136        self.browser.getControl("Add online").click()
137        self.assertMatches('...ticket created...',
138                           self.browser.contents)
139        #ctrl = self.browser.getControl(name='val_id')
140        #value = ctrl.options[0]
141        #self.browser.getLink(value).click()
142        self.assertMatches('...Amount Authorized...',
143                           self.browser.contents)
144        self.assertMatches(
145            '...<span>1000.0</span>...',
146            self.browser.contents)
147        self.payment_url = self.browser.url
148
149
150    def test_interswitch_form(self):
151
152        # Manager can access InterswitchForm
153        self.browser.getLink("CollegePAY", index=0).click()
154        self.assertMatches('...Total Amount Authorized:...',
155                           self.browser.contents)
156        self.assertMatches(
157            '...<input type="hidden" name="amount" value="100000.0" />...',
158            self.browser.contents)
159
160    @external_test
161    def test_webservice(self):
162
163        self.browser.open(self.payment_url + '/request_webservice')
164        self.assertMatches('...Unsuccessful callback...',
165                          self.browser.contents)
166        # The payment is now in state failed
167        self.assertMatches('...<span>Failed</span>...',
168                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.