source: main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py @ 8480

Last change on this file since 8480 was 8460, checked in by Henrik Bettermann, 13 years ago

Rename uniben to fceokene (completely untested).

Configure h2 ports.

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