1 | ## $Id: tests.py 9386 2012-10-22 13:03:07Z 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.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
21 | from waeup.kofa.configuration import SessionConfiguration |
---|
22 | from waeup.futminna.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. |
---|
27 | EXTERNAL_TESTS = False |
---|
28 | |
---|
29 | def 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 | |
---|
40 | class 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(name="form.p_category").value = ['schoolfee'] |
---|
53 | self.browser.getControl("Create ticket").click() |
---|
54 | self.assertMatches('...Payment ticket created...', |
---|
55 | self.browser.contents) |
---|
56 | |
---|
57 | def test_interswitch_form(self): |
---|
58 | # School fee ticket already created in setUp method |
---|
59 | ctrl = self.browser.getControl(name='val_id') |
---|
60 | value = ctrl.options[0] |
---|
61 | self.browser.getLink(value).click() |
---|
62 | self.assertMatches('...Amount Authorized...', |
---|
63 | self.browser.contents) |
---|
64 | self.assertMatches( |
---|
65 | '...<span>131500.0</span>...', |
---|
66 | self.browser.contents) |
---|
67 | self.payment_url = self.browser.url |
---|
68 | |
---|
69 | # Manager can access InterswitchForm |
---|
70 | self.browser.getLink("CollegePAY", index=0).click() |
---|
71 | # The total amount to be processed by Interswitch |
---|
72 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
73 | self.assertMatches('...Total Amount Authorized:...', |
---|
74 | self.browser.contents) |
---|
75 | self.assertMatches( |
---|
76 | '...<input type="hidden" name="amount" value="13150000.0" />...', |
---|
77 | self.browser.contents) |
---|
78 | self.assertMatches( |
---|
79 | '...item_name="School Fee" item_amt="12970000" bank_id="89" acct_num="0030001000017110"...', |
---|
80 | self.browser.contents) |
---|
81 | self.assertMatches( |
---|
82 | '...item_name="BT Education" item_amt="150000" bank_id="89" acct_num="0061001000021095"...', |
---|
83 | self.browser.contents) |
---|
84 | |
---|
85 | # Create clearance fee ticket |
---|
86 | self.browser.open(self.payments_path + '/addop') |
---|
87 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
88 | self.browser.getControl("Create ticket").click() |
---|
89 | self.assertMatches('...ticket created...', |
---|
90 | self.browser.contents) |
---|
91 | ctrl = self.browser.getControl(name='val_id') |
---|
92 | value = ctrl.options[1] |
---|
93 | self.browser.getLink(value).click() |
---|
94 | self.assertMatches('...Amount Authorized...', |
---|
95 | self.browser.contents) |
---|
96 | self.assertMatches( |
---|
97 | '...<span>20000.0</span>...', |
---|
98 | self.browser.contents) |
---|
99 | # Manager can access InterswitchForm |
---|
100 | self.browser.getLink("CollegePAY", index=0).click() |
---|
101 | self.assertMatches('...Total Amount Authorized:...', |
---|
102 | self.browser.contents) |
---|
103 | # The total amount to be processed by Interswitch |
---|
104 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
105 | self.assertMatches('...Total Amount Authorized:...', |
---|
106 | self.browser.contents) |
---|
107 | self.assertMatches( |
---|
108 | '...<input type="hidden" name="amount" value="2000000.0" />...', |
---|
109 | self.browser.contents) |
---|
110 | self.assertMatches( |
---|
111 | '...item_name="Acceptance Fee" item_amt="1970000" bank_id="120" acct_num="1750005063"...', |
---|
112 | self.browser.contents) |
---|
113 | # BT does nor charge a fee for clearance |
---|
114 | self.assertFalse("BT Education" in self.browser.contents) |
---|
115 | |
---|
116 | |
---|
117 | @external_test |
---|
118 | def test_webservice(self): |
---|
119 | self.browser.open(self.payment_url + '/request_webservice') |
---|
120 | self.assertMatches('...Unsuccessful callback...', |
---|
121 | self.browser.contents) |
---|
122 | # The payment is now in state failed |
---|
123 | self.assertMatches('...<span>Failed</span>...', |
---|
124 | self.browser.contents) |
---|