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

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

One more test. Unfortunately, we can't test more UI components with the demo portals of Interswitch and eTranzact.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1## $Id: tests.py 7930 2012-03-20 17:57:00Z 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
22class InterswitchTests(StudentsFullSetup):
23    """Tests for the Interswitch payment gateway.
24    """
25
26    layer = FunctionalLayer
27
28    def callback_url(self, payment_url, resp, apprAmt):
29        return payment_url + (
30            '/callback?echo=' +
31            '&resp=%s' +
32            '&desc=Something went wrong' +
33            '&txnRef=p1331792385335' +
34            '&payRef=' + '&retRef=' +
35            '&cardNum=0' +
36            '&apprAmt=%s' +
37            '&url=http://xyz') % (resp, apprAmt)
38
39    def test_callback(self):
40
41        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
42        self.browser.open(self.payments_student_path)
43        IWorkflowState(self.student).setState('cleared')
44        self.browser.open(self.payments_student_path + '/addop')
45        self.browser.getControl("Create ticket").click()
46        self.assertMatches('...ticket created...',
47                           self.browser.contents)
48        ctrl = self.browser.getControl(name='val_id')
49        value = ctrl.options[0]
50        self.browser.getLink(value).click()
51        self.assertMatches('...Amount Authorized...',
52                           self.browser.contents)
53        payment_url = self.browser.url
54       
55        # Manager can access InterswitchForm
56        self.browser.getLink("CollegePAY", index=0).click()
57        self.assertMatches('...Total Amount Authorized:...',
58                           self.browser.contents)
59        self.assertMatches(
60            '...<input type="hidden" name="amount" value="4000000.0" />...',
61            self.browser.contents)
62
63        # Manager can call callback manually
64        self.browser.open(self.callback_url(payment_url, 'XX', '300'))
65        self.assertMatches('...Unsuccessful callback: Something went wrong...',
66                          self.browser.contents)
67        self.assertMatches('...Failed...',
68                           self.browser.contents)
69        self.browser.open(payment_url + '/callback')
70        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
71                          self.browser.contents)
72        self.assertMatches('...Failed...',
73                           self.browser.contents)
74        self.browser.open(self.callback_url(payment_url, '00', '300000'))
75        self.assertMatches('...Wrong amount...',
76                          self.browser.contents)
77        self.browser.open(self.callback_url(payment_url, '00', '4000000'))
78        self.assertMatches('...Valid callback received...',
79                          self.browser.contents)
80
81    def test_webservice(self):
82
83        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
84        self.browser.open(self.payments_student_path)
85        IWorkflowState(self.student).setState('cleared')
86        self.browser.open(self.payments_student_path + '/addop')
87        self.browser.getControl("Create ticket").click()
88        self.assertMatches('...ticket created...',
89                           self.browser.contents)
90        ctrl = self.browser.getControl(name='val_id')
91        value = ctrl.options[0]
92        self.browser.getLink(value).click()
93        self.assertMatches('...Amount Authorized...',
94                           self.browser.contents)
95        payment_url = self.browser.url
96
97        self.browser.open(payment_url + '/request_webservice')
98        self.assertMatches('...Unsuccessful callback...',
99                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.