1 | ## $Id: tests.py 9515 2012-11-03 08:57:35Z 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 zope.component import createObject |
---|
19 | from hurry.workflow.interfaces import IWorkflowState |
---|
20 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
21 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
22 | from waeup.kofa.configuration import SessionConfiguration |
---|
23 | from waeup.uniben.testing import FunctionalLayer |
---|
24 | |
---|
25 | # Also run tests that send requests to external servers? |
---|
26 | # If you enable this, please make sure the external services |
---|
27 | # do exist really and are not bothered by being spammed by a test programme. |
---|
28 | EXTERNAL_TESTS = False |
---|
29 | |
---|
30 | def external_test(func): |
---|
31 | if not EXTERNAL_TESTS: |
---|
32 | myself = __file__ |
---|
33 | if myself.endswith('.pyc'): |
---|
34 | myself = myself[:-2] |
---|
35 | print "WARNING: external tests are skipped!" |
---|
36 | print "WARNING: edit %s to enable them." % myself |
---|
37 | return |
---|
38 | return func |
---|
39 | |
---|
40 | |
---|
41 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
42 | """Tests for the Interswitch payment gateway. |
---|
43 | """ |
---|
44 | |
---|
45 | layer = FunctionalLayer |
---|
46 | |
---|
47 | def setUp(self): |
---|
48 | super(InterswitchTestsStudents, self).setUp() |
---|
49 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
50 | self.browser.open(self.payments_path) |
---|
51 | IWorkflowState(self.student).setState('cleared') |
---|
52 | self.student.nationality = u'NG' |
---|
53 | self.browser.open(self.payments_path + '/addop') |
---|
54 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
55 | self.browser.getControl("Create ticket").click() |
---|
56 | self.assertMatches('...ticket created...', |
---|
57 | self.browser.contents) |
---|
58 | ctrl = self.browser.getControl(name='val_id') |
---|
59 | value = ctrl.options[0] |
---|
60 | self.browser.getLink(value).click() |
---|
61 | self.assertMatches('...Amount Authorized...', |
---|
62 | self.browser.contents) |
---|
63 | self.assertMatches( |
---|
64 | '...<span>40000.0</span>...', |
---|
65 | self.browser.contents) |
---|
66 | self.payment_url = self.browser.url |
---|
67 | |
---|
68 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
69 | # return payment_url + ( |
---|
70 | # '/isw_callback?echo=' + |
---|
71 | # '&resp=%s' + |
---|
72 | # '&desc=Something went wrong' + |
---|
73 | # '&txnRef=p1331792385335' + |
---|
74 | # '&payRef=' + '&retRef=' + |
---|
75 | # '&cardNum=0' + |
---|
76 | # '&apprAmt=%s' + |
---|
77 | # '&url=http://xyz') % (resp, apprAmt) |
---|
78 | |
---|
79 | def test_interswitch_form(self): |
---|
80 | # Manager can access InterswitchForm |
---|
81 | self.browser.getLink("CollegePAY", index=0).click() |
---|
82 | # The total amount to be processed by Interswitch |
---|
83 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
84 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5700" />...', |
---|
85 | self.browser.contents) |
---|
86 | self.assertMatches('...Total Amount Authorized:...', |
---|
87 | self.browser.contents) |
---|
88 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
89 | self.assertMatches( |
---|
90 | '...<input type="hidden" name="amount" value="4000000.0" />...', |
---|
91 | self.browser.contents) |
---|
92 | self.assertMatches( |
---|
93 | '...item_name="School Fee" item_amt="3835000" bank_id="8" acct_num="2017506430"...', |
---|
94 | self.browser.contents) |
---|
95 | self.assertMatches( |
---|
96 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
97 | self.browser.contents) |
---|
98 | |
---|
99 | # Create school fee ticket for returning students |
---|
100 | self.certificate.study_mode = u'ug_pt' |
---|
101 | IWorkflowState(self.student).setState('returning') |
---|
102 | configuration = createObject('waeup.SessionConfiguration') |
---|
103 | configuration.academic_session = 2005 |
---|
104 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
105 | self.browser.open(self.payments_path + '/addop') |
---|
106 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
107 | self.browser.getControl("Create ticket").click() |
---|
108 | ctrl = self.browser.getControl(name='val_id') |
---|
109 | value = ctrl.options[1] |
---|
110 | self.browser.getLink(value).click() |
---|
111 | self.browser.getLink("CollegePAY", index=0).click() |
---|
112 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...', |
---|
113 | self.browser.contents) |
---|
114 | self.assertMatches( |
---|
115 | '...<input type="hidden" name="amount" value="2000000.0" />...', |
---|
116 | self.browser.contents) |
---|
117 | self.assertMatches( |
---|
118 | '...item_name="School Fee" item_amt="1835000" bank_id="16" acct_num="0122009929"...', |
---|
119 | self.browser.contents) |
---|
120 | self.assertMatches( |
---|
121 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
122 | self.browser.contents) |
---|
123 | |
---|
124 | # Create clearance fee ticket |
---|
125 | self.browser.open(self.payments_path + '/addop') |
---|
126 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
127 | self.browser.getControl("Create ticket").click() |
---|
128 | ctrl = self.browser.getControl(name='val_id') |
---|
129 | value = ctrl.options[2] |
---|
130 | self.browser.getLink(value).click() |
---|
131 | self.assertMatches( |
---|
132 | '...<span>45000.0</span>...', |
---|
133 | self.browser.contents) |
---|
134 | # Manager can access InterswitchForm |
---|
135 | self.browser.getLink("CollegePAY", index=0).click() |
---|
136 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...', |
---|
137 | self.browser.contents) |
---|
138 | self.assertMatches('...Total Amount Authorized:...', |
---|
139 | self.browser.contents) |
---|
140 | self.assertMatches( |
---|
141 | '...<input type="hidden" name="amount" value="4500000.0" />...', |
---|
142 | self.browser.contents) |
---|
143 | self.assertMatches( |
---|
144 | '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...', |
---|
145 | self.browser.contents) |
---|
146 | self.assertMatches( |
---|
147 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
148 | self.browser.contents) |
---|
149 | |
---|
150 | # Create gown fee ticket |
---|
151 | configuration.maint_fee = 987.0 |
---|
152 | self.app['configuration']['2004'].gown_fee = 234.0 |
---|
153 | self.browser.open(self.payments_path + '/addop') |
---|
154 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
155 | self.browser.getControl("Create ticket").click() |
---|
156 | ctrl = self.browser.getControl(name='val_id') |
---|
157 | value = ctrl.options[3] |
---|
158 | self.browser.getLink(value).click() |
---|
159 | self.assertMatches( |
---|
160 | '...<span>234.0</span>...', |
---|
161 | self.browser.contents) |
---|
162 | # Manager can access InterswitchForm |
---|
163 | self.browser.getLink("CollegePAY", index=0).click() |
---|
164 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5704" />...', |
---|
165 | self.browser.contents) |
---|
166 | self.assertMatches('...Total Amount Authorized:...', |
---|
167 | self.browser.contents) |
---|
168 | self.assertMatches( |
---|
169 | '...<input type="hidden" name="amount" value="23400.0" />...', |
---|
170 | self.browser.contents) |
---|
171 | self.assertMatches( |
---|
172 | '...<item_detail item_id="1" item_name="Gown Hire Fee" item_amt="8400" bank_id="7" acct_num="1016232382" />...', |
---|
173 | self.browser.contents) |
---|
174 | self.assertFalse( |
---|
175 | 'item_name="BT Education"' in self.browser.contents) |
---|
176 | |
---|
177 | # @external_test |
---|
178 | # def test_callback(self): |
---|
179 | |
---|
180 | # Manager can call callback manually |
---|
181 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
182 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
183 | # self.browser.contents) |
---|
184 | # self.assertMatches('...Failed...', |
---|
185 | # self.browser.contents) |
---|
186 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
187 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
188 | # self.browser.contents) |
---|
189 | # self.assertMatches('...Failed...', |
---|
190 | # self.browser.contents) |
---|
191 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
192 | # self.assertMatches('...Wrong amount...', |
---|
193 | # self.browser.contents) |
---|
194 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
195 | # self.assertMatches('...Valid callback received...', |
---|
196 | # self.browser.contents) |
---|
197 | |
---|
198 | @external_test |
---|
199 | def test_webservice(self): |
---|
200 | |
---|
201 | self.browser.open(self.payment_url + '/request_webservice') |
---|
202 | self.assertMatches('...Unsuccessful callback...', |
---|
203 | self.browser.contents) |
---|
204 | # The payment is now in state failed |
---|
205 | self.assertMatches('...<span>Failed</span>...', |
---|
206 | self.browser.contents) |
---|
207 | |
---|
208 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
209 | """Tests for the Interswitch payment gateway. |
---|
210 | """ |
---|
211 | |
---|
212 | layer = FunctionalLayer |
---|
213 | |
---|
214 | def setUp(self): |
---|
215 | super(InterswitchTestsApplicants, self).setUp() |
---|
216 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
217 | self.browser.open(self.manage_path) |
---|
218 | #IWorkflowState(self.student).setState('started') |
---|
219 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
220 | self.applicantscontainer.application_fee = 1000.0 |
---|
221 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
222 | self.browser.getControl(name="transition").value = ['start'] |
---|
223 | self.browser.getControl("Save").click() |
---|
224 | self.browser.getControl("Add online").click() |
---|
225 | self.assertMatches('...ticket created...', |
---|
226 | self.browser.contents) |
---|
227 | #ctrl = self.browser.getControl(name='val_id') |
---|
228 | #value = ctrl.options[0] |
---|
229 | #self.browser.getLink(value).click() |
---|
230 | self.assertMatches('...Amount Authorized...', |
---|
231 | self.browser.contents) |
---|
232 | self.assertMatches( |
---|
233 | '...<span>1000.0</span>...', |
---|
234 | self.browser.contents) |
---|
235 | self.payment_url = self.browser.url |
---|
236 | |
---|
237 | |
---|
238 | def test_interswitch_form(self): |
---|
239 | |
---|
240 | # Manager can access InterswitchForm |
---|
241 | self.browser.getLink("CollegePAY", index=0).click() |
---|
242 | self.assertMatches('...Total Amount Authorized:...', |
---|
243 | self.browser.contents) |
---|
244 | self.assertMatches( |
---|
245 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
246 | self.browser.contents) |
---|
247 | |
---|
248 | @external_test |
---|
249 | def test_webservice(self): |
---|
250 | |
---|
251 | self.browser.open(self.payment_url + '/request_webservice') |
---|
252 | self.assertMatches('...Unsuccessful callback...', |
---|
253 | self.browser.contents) |
---|
254 | # The payment is now in state failed |
---|
255 | self.assertMatches('...<span>Failed</span>...', |
---|
256 | self.browser.contents) |
---|