1 | ## $Id: tests.py 8256 2012-04-23 07:36:46Z 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 | ## |
---|
18 | from hurry.workflow.interfaces import IWorkflowState |
---|
19 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
20 | from waeup.uniben.testing import FunctionalLayer |
---|
21 | |
---|
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. |
---|
25 | EXTERNAL_TESTS = True |
---|
26 | |
---|
27 | def 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 | |
---|
38 | class InterswitchTests(StudentsFullSetup): |
---|
39 | """Tests for the Interswitch payment gateway. |
---|
40 | """ |
---|
41 | |
---|
42 | layer = FunctionalLayer |
---|
43 | |
---|
44 | def setUp(self): |
---|
45 | super(InterswitchTests, self).setUp() |
---|
46 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
47 | self.browser.open(self.payments_path) |
---|
48 | IWorkflowState(self.student).setState('cleared') |
---|
49 | self.browser.open(self.payments_path + '/addop') |
---|
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 | |
---|
61 | def callback_url(self, payment_url, resp, apprAmt): |
---|
62 | return payment_url + ( |
---|
63 | '/isw_callback?echo=' + |
---|
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 | |
---|
72 | def test_interswitch_form(self): |
---|
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( |
---|
79 | '...<input type="hidden" name="amount" value="4000000.0" />...', |
---|
80 | self.browser.contents) |
---|
81 | |
---|
82 | @external_test |
---|
83 | def test_callback(self): |
---|
84 | |
---|
85 | # Manager can call callback manually |
---|
86 | self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
87 | self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
88 | self.browser.contents) |
---|
89 | self.assertMatches('...Failed...', |
---|
90 | self.browser.contents) |
---|
91 | self.browser.open(self.payment_url + '/isw_callback') |
---|
92 | self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
93 | self.browser.contents) |
---|
94 | self.assertMatches('...Failed...', |
---|
95 | self.browser.contents) |
---|
96 | self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
97 | self.assertMatches('...Wrong amount...', |
---|
98 | self.browser.contents) |
---|
99 | self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
100 | self.assertMatches('...Valid callback received...', |
---|
101 | self.browser.contents) |
---|
102 | |
---|
103 | @external_test |
---|
104 | def test_webservice(self): |
---|
105 | |
---|
106 | self.browser.open(self.payment_url + '/request_webservice') |
---|
107 | self.assertMatches('...Unsuccessful callback...', |
---|
108 | self.browser.contents) |
---|