source: main/waeup.custom/trunk/src/waeup/custom/interswitch/tests.py @ 8018

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

Neutralize callback simulation components in base package.

  • Property svn:keywords set to Id
File size: 4.3 KB
RevLine 
[7894]1## $Id: tests.py 7998 2012-03-28 20:50:45Z 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.custom.testing import FunctionalLayer
21
[7970]22# Also run tests that send requests to external servers?
23#   If you enable this, please make sure the external services
24#   do exist really and are not bothered by being spammed by a test programme.
25EXTERNAL_TESTS = False
26
27def external_test(func):
28    if not EXTERNAL_TESTS:
29        myself = __file__
30        if myself.endswith('.pyc'):
31            myself = myself[:-2]
32        print "WARNING: external tests are skipped!"
33        print "WARNING: edit %s to enable them." % myself
34        return
35    return func
36
37
[7929]38class InterswitchTests(StudentsFullSetup):
39    """Tests for the Interswitch payment gateway.
[7894]40    """
41
42    layer = FunctionalLayer
43
[7970]44    def setUp(self):
45        super(InterswitchTests, self).setUp()
46        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[7995]47        self.browser.open(self.payments_path)
[7970]48        IWorkflowState(self.student).setState('cleared')
[7995]49        self.browser.open(self.payments_path + '/addop')
[7970]50        self.browser.getControl("Create ticket").click()
51        self.assertMatches('...ticket created...',
52                           self.browser.contents)
53        ctrl = self.browser.getControl(name='val_id')
54        value = ctrl.options[0]
55        self.browser.getLink(value).click()
56        self.assertMatches('...Amount Authorized...',
57                           self.browser.contents)
58        self.payment_url = self.browser.url
59
60
[7894]61    def callback_url(self, payment_url, resp, apprAmt):
62        return payment_url + (
[7998]63            '/isw_callback?echo=' +
[7894]64            '&resp=%s' +
65            '&desc=Something went wrong' +
66            '&txnRef=p1331792385335' +
67            '&payRef=' + '&retRef=' +
68            '&cardNum=0' +
69            '&apprAmt=%s' +
70            '&url=http://xyz') % (resp, apprAmt)
71
[7970]72    def test_interswitch_form(self):
[7894]73
74        # Manager can access InterswitchForm
75        self.browser.getLink("CollegePAY", index=0).click()
76        self.assertMatches('...Total Amount Authorized:...',
77                           self.browser.contents)
78        self.assertMatches(
[7928]79            '...<input type="hidden" name="amount" value="4000000.0" />...',
[7894]80            self.browser.contents)
81
[7970]82    @external_test
83    def test_callback(self):
84
[7894]85        # Manager can call callback manually
[7970]86        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
[7894]87        self.assertMatches('...Unsuccessful callback: Something went wrong...',
88                          self.browser.contents)
89        self.assertMatches('...Failed...',
90                           self.browser.contents)
[7998]91        self.browser.open(self.payment_url + '/isw_callback')
[7894]92        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
93                          self.browser.contents)
94        self.assertMatches('...Failed...',
95                           self.browser.contents)
[7970]96        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
[7896]97        self.assertMatches('...Wrong amount...',
98                          self.browser.contents)
[7970]99        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
[7894]100        self.assertMatches('...Valid callback received...',
[7930]101                          self.browser.contents)
102
[7970]103    @external_test
[7930]104    def test_webservice(self):
105
[7970]106        self.browser.open(self.payment_url + '/request_webservice')
[7930]107        self.assertMatches('...Unsuccessful callback...',
108                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.