1 | ## $Id: tests.py 17440 2023-06-19 14:02:14Z 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 | import os |
---|
19 | from datetime import datetime, date, timedelta |
---|
20 | from zope.component import createObject, getUtility |
---|
21 | from zope.catalog.interfaces import ICatalog |
---|
22 | from hurry.workflow.interfaces import IWorkflowState |
---|
23 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
24 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
25 | from waeup.kofa.configuration import SessionConfiguration |
---|
26 | from waeup.aaue.testing import FunctionalLayer |
---|
27 | |
---|
28 | # Also run tests that send requests to external servers? |
---|
29 | # If you enable this, please make sure the external services |
---|
30 | # do exist really and are not bothered by being spammed by a test programme. |
---|
31 | EXTERNAL_TESTS = False |
---|
32 | |
---|
33 | def external_test(func): |
---|
34 | if not EXTERNAL_TESTS: |
---|
35 | myself = __file__ |
---|
36 | if myself.endswith('.pyc'): |
---|
37 | myself = myself[:-2] |
---|
38 | print "WARNING: external tests are skipped!" |
---|
39 | print "WARNING: edit %s to enable them." % myself |
---|
40 | return |
---|
41 | return func |
---|
42 | |
---|
43 | |
---|
44 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
45 | """Tests for the Interswitch payment gateway. |
---|
46 | """ |
---|
47 | |
---|
48 | layer = FunctionalLayer |
---|
49 | |
---|
50 | def setUp(self): |
---|
51 | super(InterswitchTestsApplicants, self).setUp() |
---|
52 | certificate = createObject('waeup.Certificate') |
---|
53 | certificate.code = 'CERT2' |
---|
54 | certificate.title = 'New Certificate' |
---|
55 | certificate.application_category = 'basic' |
---|
56 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
57 | certificate) |
---|
58 | configuration = SessionConfiguration() |
---|
59 | configuration.academic_session = datetime.now().year - 2 |
---|
60 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
61 | self.configuration = configuration |
---|
62 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
63 | self.browser.open(self.manage_path) |
---|
64 | #IWorkflowState(self.student).setState('started') |
---|
65 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
66 | #self.browser.getControl(name="form.programme_type").value = ['regular'] |
---|
67 | self.applicantscontainer.application_fee = 10000.0 |
---|
68 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
69 | self.browser.getControl(name="form.course2").value = ['CERT2'] |
---|
70 | self.browser.getControl(name="transition").value = ['start'] |
---|
71 | self.browser.getControl("Save").click() |
---|
72 | |
---|
73 | def deactivated_test_interswitch_form_regular(self): |
---|
74 | self.browser.getControl("Add online").click() |
---|
75 | self.assertTrue('ticket created' in self.browser.contents) |
---|
76 | #self.browser.getLink(value).click() |
---|
77 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
78 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
79 | self.payment_url = self.browser.url |
---|
80 | # Manager can access InterswitchForm |
---|
81 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
82 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
83 | self.assertTrue( |
---|
84 | '<input type="hidden" name="amount" value="1000000" />' |
---|
85 | in self.browser.contents) |
---|
86 | self.assertTrue( |
---|
87 | 'item_name="WAeAC" item_amt="200000"' |
---|
88 | in self.browser.contents) |
---|
89 | self.assertTrue( |
---|
90 | 'item_name="Application Fee" item_amt="780000" bank_id="117" acct_num="1010835352"' |
---|
91 | in self.browser.contents) |
---|
92 | self.assertTrue( |
---|
93 | '<input type="hidden" name="product_id" value="5845" />' |
---|
94 | in self.browser.contents) |
---|
95 | delta = timedelta(days=8) |
---|
96 | self.applicant.values()[0].creation_date -= delta |
---|
97 | self.browser.open(self.payment_url) |
---|
98 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
99 | self.assertTrue( |
---|
100 | 'This payment ticket is too old. Please create a new ticket' |
---|
101 | in self.browser.contents) |
---|
102 | |
---|
103 | def deactivated_test_interswitch_form_pg(self): |
---|
104 | self.applicant.applicant_id = u'pg_anything' |
---|
105 | self.browser.getControl("Add online").click() |
---|
106 | self.assertTrue('ticket created' in self.browser.contents) |
---|
107 | #self.browser.getLink(value).click() |
---|
108 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
109 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
110 | self.payment_url = self.browser.url |
---|
111 | # Manager can access InterswitchForm |
---|
112 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
113 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
114 | self.assertTrue( |
---|
115 | '<input type="hidden" name="amount" value="1000000" />' |
---|
116 | in self.browser.contents) |
---|
117 | self.assertTrue( |
---|
118 | 'item_name="WAeAC" item_amt="200000"' |
---|
119 | in self.browser.contents) |
---|
120 | self.assertTrue( |
---|
121 | 'item_name="Application Fee" item_amt="580000" bank_id="51" acct_num="5210006575"' |
---|
122 | in self.browser.contents) |
---|
123 | self.assertTrue( |
---|
124 | 'item_name="PG Handbook" item_amt="200000" bank_id="51" acct_num="5210006575"' |
---|
125 | in self.browser.contents) |
---|
126 | self.assertTrue( |
---|
127 | '<input type="hidden" name="product_id" value="5845" />' |
---|
128 | in self.browser.contents) |
---|
129 | delta = timedelta(days=8) |
---|
130 | self.applicant.values()[0].creation_date -= delta |
---|
131 | self.browser.open(self.payment_url) |
---|
132 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
133 | self.assertTrue( |
---|
134 | 'This payment ticket is too old. Please create a new ticket' |
---|
135 | in self.browser.contents) |
---|
136 | |
---|
137 | def deactivated_test_interswitch_form_utme(self): |
---|
138 | self.applicant.applicant_id = u'utme_anything' |
---|
139 | self.browser.getControl("Add online").click() |
---|
140 | self.assertTrue('ticket created' in self.browser.contents) |
---|
141 | #self.browser.getLink(value).click() |
---|
142 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
143 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
144 | self.payment_url = self.browser.url |
---|
145 | # Manager can access InterswitchForm |
---|
146 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
147 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
148 | self.assertTrue( |
---|
149 | '<input type="hidden" name="amount" value="1000000" />' |
---|
150 | in self.browser.contents) |
---|
151 | self.assertTrue( |
---|
152 | 'item_name="WAeAC" item_amt="200000"' |
---|
153 | in self.browser.contents) |
---|
154 | self.assertTrue( |
---|
155 | 'item_name="Application Fee" item_amt="780000" bank_id="117" acct_num="1010835352"' |
---|
156 | in self.browser.contents) |
---|
157 | self.assertTrue( |
---|
158 | '<input type="hidden" name="product_id" value="5845" />' |
---|
159 | in self.browser.contents) |
---|
160 | delta = timedelta(days=8) |
---|
161 | self.applicant.values()[0].creation_date -= delta |
---|
162 | self.browser.open(self.payment_url) |
---|
163 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
164 | self.assertTrue( |
---|
165 | 'This payment ticket is too old. Please create a new ticket' |
---|
166 | in self.browser.contents) |
---|
167 | |
---|
168 | def deactivated_test_interswitch_form_bridge(self): |
---|
169 | self.applicant.applicant_id = u'bridge_xyz' |
---|
170 | self.browser.getControl("Add online").click() |
---|
171 | self.assertTrue('ticket created' in self.browser.contents) |
---|
172 | #self.browser.getLink(value).click() |
---|
173 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
174 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
175 | self.payment_url = self.browser.url |
---|
176 | # Manager can access InterswitchForm |
---|
177 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
178 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
179 | self.assertTrue( |
---|
180 | '<input type="hidden" name="amount" value="1000000" />' |
---|
181 | in self.browser.contents) |
---|
182 | self.assertTrue( |
---|
183 | 'item_name="WAeAC" item_amt="200000"' |
---|
184 | in self.browser.contents) |
---|
185 | self.assertTrue( |
---|
186 | 'item_name="Application Fee" item_amt="780000" bank_id="7" acct_num="1014847058"' |
---|
187 | in self.browser.contents) |
---|
188 | |
---|
189 | @external_test |
---|
190 | def test_webservice(self): |
---|
191 | |
---|
192 | self.browser.open(self.payment_url + '/request_webservice') |
---|
193 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
194 | # The payment is now in state failed |
---|
195 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
196 | |
---|
197 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
198 | """Tests for the Interswitch payment gateway. |
---|
199 | """ |
---|
200 | |
---|
201 | layer = FunctionalLayer |
---|
202 | |
---|
203 | def setUp(self): |
---|
204 | super(InterswitchTestsStudents, self).setUp() |
---|
205 | self.app['configuration']['2004'].interswitch_enabled = True |
---|
206 | |
---|
207 | def disabled_test_interswitch_form_pt_school_fees(self): |
---|
208 | self.certificate.study_mode = 'ug_pt' |
---|
209 | self.student['studycourse'].entry_session = 2013 |
---|
210 | self.student['studycourse'].certificate.school_fee_3 = 50200.0 |
---|
211 | self.app['configuration']['2004'].union_fee = 1000.0 |
---|
212 | self.app['configuration']['2004'].welfare_fee = 500.0 |
---|
213 | # Manager can access InterswitchForm |
---|
214 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
215 | self.browser.open(self.payments_path) |
---|
216 | IWorkflowState(self.student).setState('cleared') |
---|
217 | self.student.nationality = u'NG' |
---|
218 | self.browser.open(self.payments_path + '/addop') |
---|
219 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
220 | self.browser.getControl("Create ticket").click() |
---|
221 | self.assertTrue('ticket created' in self.browser.contents) |
---|
222 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
223 | # 50200 + 1000 + 500 - 400 |
---|
224 | self.assertTrue('<span>51300.0</span>' in self.browser.contents) |
---|
225 | self.payment_url = self.browser.url |
---|
226 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
227 | self.assertTrue( |
---|
228 | 'Please pay acceptance fee first' in self.browser.contents) |
---|
229 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
230 | acc_payment.p_state = 'paid' |
---|
231 | acc_payment.p_category = 'clearance' |
---|
232 | self.student['payments']['xyz'] = acc_payment |
---|
233 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
234 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
235 | self.assertEqual(self.student.current_mode, 'ug_pt') |
---|
236 | self.assertTrue( |
---|
237 | '<input type="hidden" name="amount" value="5130000" />' |
---|
238 | in self.browser.contents) |
---|
239 | self.assertTrue( |
---|
240 | 'item_name="School Fee Plus" ' |
---|
241 | 'item_amt="4810000" bank_id="7" ' |
---|
242 | 'acct_num="1014847058"' in self.browser.contents) |
---|
243 | |
---|
244 | def test_interswitch_form_regular_school_fees(self): |
---|
245 | self.certificate.study_mode = 'ug_ft' |
---|
246 | #self.student['studycourse'].entry_session = 2013 |
---|
247 | #self.student['studycourse'].certificate.school_fee_3 = 51750.0 |
---|
248 | # Manager can access InterswitchForm |
---|
249 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
250 | self.browser.open(self.payments_path) |
---|
251 | IWorkflowState(self.student).setState('cleared') |
---|
252 | self.student.nationality = u'NG' |
---|
253 | self.browser.open(self.payments_path + '/addop') |
---|
254 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
255 | self.browser.getControl("Create ticket").click() |
---|
256 | self.assertTrue('ticket created' in |
---|
257 | self.browser.contents) |
---|
258 | self.assertTrue('Amount Authorized' in |
---|
259 | self.browser.contents) |
---|
260 | self.assertTrue('<span>239500.0</span>' in self.browser.contents) |
---|
261 | self.payment_url = self.browser.url |
---|
262 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
263 | self.assertTrue('Total Amount Authorized:' |
---|
264 | in self.browser.contents) |
---|
265 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
266 | self.assertTrue( |
---|
267 | '<input type="hidden" name="amount" value="24220000" />' |
---|
268 | in self.browser.contents) |
---|
269 | self.assertTrue( |
---|
270 | 'item_name="Tuition" item_amt="18400000" bank_id="7" ' |
---|
271 | 'acct_num="1022438743"' in self.browser.contents) |
---|
272 | |
---|
273 | self.student['studycourse'].entry_session = 2015 |
---|
274 | self.browser.open(self.payments_path + '/addop') |
---|
275 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
276 | self.browser.getControl("Create ticket").click() |
---|
277 | self.assertTrue('ticket created' in |
---|
278 | self.browser.contents) |
---|
279 | self.assertTrue('<span>92000.0</span>' in self.browser.contents) |
---|
280 | self.payment_url = self.browser.url |
---|
281 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
282 | self.assertTrue( |
---|
283 | 'Please pay acceptance fee first' in self.browser.contents) |
---|
284 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
285 | acc_payment.p_state = 'paid' |
---|
286 | acc_payment.p_category = 'clearance' |
---|
287 | self.student['payments']['xyz'] = acc_payment |
---|
288 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
289 | self.assertTrue( |
---|
290 | '<input type="hidden" name="amount" value="9220000" />' |
---|
291 | in self.browser.contents) |
---|
292 | self.assertTrue( |
---|
293 | 'item_name="School Fees (2nd instalment)" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
294 | |
---|
295 | self.browser.open(self.payments_path + '/addop') |
---|
296 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
297 | self.browser.getControl("Create ticket").click() |
---|
298 | self.assertTrue('ticket created' in |
---|
299 | self.browser.contents) |
---|
300 | self.assertTrue('<span>147500.0</span>' in self.browser.contents) |
---|
301 | self.payment_url = self.browser.url |
---|
302 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
303 | self.assertTrue( |
---|
304 | '<input type="hidden" name="amount" value="15020000" />' |
---|
305 | in self.browser.contents) |
---|
306 | self.assertTrue( |
---|
307 | 'item_name="LMS Plus Fee" item_amt="2000000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
308 | self.assertTrue( |
---|
309 | 'item_name="Tuition" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
310 | |
---|
311 | self.browser.open(self.payments_path + '/addop') |
---|
312 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
313 | self.browser.getControl("Create ticket").click() |
---|
314 | self.assertTrue('ticket created' in |
---|
315 | self.browser.contents) |
---|
316 | self.assertTrue('<span>92000.0</span>' in self.browser.contents) |
---|
317 | self.payment_url = self.browser.url |
---|
318 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
319 | self.assertTrue( |
---|
320 | '<input type="hidden" name="amount" value="9220000" />' |
---|
321 | in self.browser.contents) |
---|
322 | self.assertTrue( |
---|
323 | 'item_name="School Fees (2nd instalment)" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
324 | |
---|
325 | def disabled_test_interswitch_form_pt_acceptance_fees(self): |
---|
326 | self.certificate.study_mode = 'ug_pt' |
---|
327 | self.app['configuration']['2004'].clearance_fee_ug_pt = 40200.0 |
---|
328 | self.app['configuration']['2004'].matric_gown_fee = 2000.0 |
---|
329 | self.app['configuration']['2004'].lapel_fee = 800.0 |
---|
330 | # Manager can access InterswitchForm |
---|
331 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
332 | self.browser.open(self.payments_path) |
---|
333 | IWorkflowState(self.student).setState('admitted') |
---|
334 | self.student.nationality = u'NG' |
---|
335 | self.browser.open(self.payments_path + '/addop') |
---|
336 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
337 | self.browser.getControl("Create ticket").click() |
---|
338 | self.assertTrue('ticket created' in self.browser.contents) |
---|
339 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
340 | # 40200 + 2000 + 800 - 400 |
---|
341 | self.assertTrue('<span>42600.0</span>' in self.browser.contents) |
---|
342 | self.payment_url = self.browser.url |
---|
343 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
344 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
345 | self.assertTrue( |
---|
346 | '<input type="hidden" name="amount" value="4260000" />' |
---|
347 | in self.browser.contents) |
---|
348 | self.assertTrue( |
---|
349 | 'item_name="Acceptance Fee Plus" ' |
---|
350 | 'item_amt="4000000" bank_id="7" ' |
---|
351 | 'acct_num="1014847058"' in self.browser.contents) |
---|
352 | |
---|
353 | def test_interswitch_form_regular_acceptance_fees(self): |
---|
354 | self.certificate.study_mode = 'ug_ft' |
---|
355 | #self.app['configuration']['2004'].clearance_fee = 43050.0 |
---|
356 | # Manager can access InterswitchForm |
---|
357 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
358 | self.browser.open(self.payments_path) |
---|
359 | IWorkflowState(self.student).setState('admitted') |
---|
360 | self.student.nationality = u'NG' |
---|
361 | self.browser.open(self.payments_path + '/addop') |
---|
362 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
363 | self.browser.getControl("Create ticket").click() |
---|
364 | self.assertTrue('ticket created' in self.browser.contents) |
---|
365 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
366 | self.assertTrue('<span>16800.0</span>' in self.browser.contents) |
---|
367 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
368 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
369 | self.assertTrue( |
---|
370 | '<input type="hidden" name="amount" value="1850000" />' |
---|
371 | in self.browser.contents) |
---|
372 | self.assertTrue(self.student['payments'].values()[0].net_amt == 16800) |
---|
373 | self.assertTrue( |
---|
374 | 'item_name="Acceptance Fee" item_amt="1400000" bank_id="8" ' |
---|
375 | 'acct_num="2000249757"' in self.browser.contents) |
---|
376 | |
---|
377 | self.certificate.study_mode = 'bridge' |
---|
378 | self.browser.open(self.payments_path + '/addop') |
---|
379 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
380 | self.browser.getControl("Create ticket").click() |
---|
381 | self.assertTrue('ticket created' in self.browser.contents) |
---|
382 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
383 | self.assertTrue('<span>14000.0</span>' in self.browser.contents) |
---|
384 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
385 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
386 | self.assertTrue( |
---|
387 | '<input type="hidden" name="amount" value="1570000" />' |
---|
388 | in self.browser.contents) |
---|
389 | self.assertTrue(self.student['payments'].values()[1].net_amt == 14000) |
---|
390 | self.assertTrue( |
---|
391 | 'item_name="Acceptance Fee" item_amt="1400000" bank_id="8" ' |
---|
392 | 'acct_num="2000249757"' in self.browser.contents) |
---|
393 | |
---|
394 | def deactivated_test_interswitch_form_concessional_fees(self): |
---|
395 | self.certificate.study_mode = 'ug_ft' |
---|
396 | self.app['configuration']['2004'].concessional_fee = 1567.0 |
---|
397 | # Manager can access InterswitchForm |
---|
398 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
399 | self.browser.open(self.payments_path) |
---|
400 | IWorkflowState(self.student).setState('admitted') |
---|
401 | self.student.nationality = u'NG' |
---|
402 | self.browser.open(self.payments_path + '/addop') |
---|
403 | self.browser.getControl(name="form.p_category").value = ['concessional'] |
---|
404 | self.browser.getControl("Create ticket").click() |
---|
405 | self.assertTrue('ticket created' in self.browser.contents) |
---|
406 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
407 | self.assertTrue( |
---|
408 | '<span>1567.0</span>' in self.browser.contents) |
---|
409 | self.payment_url = self.browser.url |
---|
410 | self.certificate.study_mode = 'ug_ft' |
---|
411 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
412 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
413 | self.assertTrue( |
---|
414 | '<input type="hidden" name="amount" value="156700" />' |
---|
415 | in self.browser.contents) |
---|
416 | self.assertTrue( |
---|
417 | 'item_name="Concessional Fee" item_amt="136700" ' |
---|
418 | 'bank_id="117" acct_num="1010827641"' |
---|
419 | in self.browser.contents) |
---|
420 | |
---|
421 | def deactivated_test_interswitch_form_ticket_expired(self): |
---|
422 | self.certificate.study_mode = 'ug_pt' |
---|
423 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
424 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
425 | acc_payment.p_state = 'unpaid' |
---|
426 | acc_payment.p_session = 2004 |
---|
427 | acc_payment.p_category = 'clearance' |
---|
428 | acc_payment.p_id = 'xyz' |
---|
429 | acc_payment.pay_item_id = '123' |
---|
430 | acc_payment.amount_auth = 876.0 |
---|
431 | self.student['payments']['xyz'] = acc_payment |
---|
432 | self.browser.open(self.payments_path + '/xyz') |
---|
433 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
434 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
435 | self.assertEqual(self.student.current_mode, 'ug_pt') |
---|
436 | self.assertTrue( |
---|
437 | '<input type="hidden" name="amount" value="87600" />' |
---|
438 | in self.browser.contents) |
---|
439 | delta = timedelta(days=8) |
---|
440 | acc_payment.creation_date -= delta |
---|
441 | self.browser.open(self.payments_path + '/xyz') |
---|
442 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
443 | self.assertTrue( |
---|
444 | 'This payment ticket is too old. Please create a new ticket' |
---|
445 | in self.browser.contents) |
---|
446 | delta = timedelta(days=2) |
---|
447 | acc_payment.creation_date += delta |
---|
448 | self.browser.open(self.payments_path + '/xyz') |
---|
449 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
450 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
451 | |
---|
452 | @external_test |
---|
453 | def test_webservice(self): |
---|
454 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
455 | self.browser.open(self.payments_path) |
---|
456 | IWorkflowState(self.student).setState('cleared') |
---|
457 | self.student.nationality = u'NG' |
---|
458 | self.browser.open(self.payments_path + '/addop') |
---|
459 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
460 | self.browser.getControl("Create ticket").click() |
---|
461 | self.assertTrue('ticket created' in self.browser.contents) |
---|
462 | ctrl = self.browser.getControl(name='val_id') |
---|
463 | self.value = ctrl.options[0] |
---|
464 | self.browser.getLink(self.value).click() |
---|
465 | self.payment_url = self.browser.url |
---|
466 | # First we have to open InterswitchPageStudent to set provider_amt |
---|
467 | # and gateway_amt |
---|
468 | self.browser.open(self.payment_url + '/goto_interswitch') |
---|
469 | # Now we can call the webservice |
---|
470 | self.browser.open(self.payment_url + '/request_webservice') |
---|
471 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
472 | # The payment is now in state failed ... |
---|
473 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
474 | # ... and the catalog has been updated |
---|
475 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
476 | results = list( |
---|
477 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
478 | self.assertEqual(len(results), 1) |
---|
479 | self.assertEqual(results[0].p_state, 'failed') |
---|
480 | |
---|
481 | # Let's replace the p_id with a valid p_id of the AAUE |
---|
482 | # live system. This is definitely not an appropriate |
---|
483 | # solution for testing, but we have no choice since |
---|
484 | # Interswitch doesn't provide any interface |
---|
485 | # for testing. |
---|
486 | payment = self.student['payments'][self.value] |
---|
487 | payment.p_id = 'p4465649308559' |
---|
488 | self.browser.open(self.payment_url + '/request_webservice') |
---|
489 | self.assertTrue('Unsuccessful callback: Amount Inconsistency' in |
---|
490 | self.browser.contents) |
---|
491 | # The payment is now in state failed ... |
---|
492 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
493 | # Let's replace the amount autorized with the amount of the |
---|
494 | # live system payment |
---|
495 | payment.amount_auth = 60250.0 |
---|
496 | self.browser.open(self.payment_url + '/request_webservice') |
---|
497 | self.assertTrue('Successful payment' in |
---|
498 | self.browser.contents) |
---|
499 | # The payment is now in state paid ... |
---|
500 | self.assertTrue('<span>Paid</span>' in self.browser.contents) |
---|
501 | # ... and the catalog has been updated |
---|
502 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
503 | results = list( |
---|
504 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
505 | self.assertEqual(len(results), 1) |
---|
506 | self.assertEqual(results[0].p_state, 'paid') |
---|
507 | # Approval is logged in students.log ... |
---|
508 | logfile = os.path.join( |
---|
509 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
510 | logcontent = open(logfile).read() |
---|
511 | self.assertTrue( |
---|
512 | 'zope.mgr - ' |
---|
513 | 'waeup.aaue.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - ' |
---|
514 | 'E1000000 - successful schoolfee_incl payment: p4465649308559\n' |
---|
515 | in logcontent) |
---|
516 | # ... and in payments.log |
---|
517 | logfile = os.path.join( |
---|
518 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
519 | logcontent = open(logfile).read() |
---|
520 | self.assertTrue( |
---|
521 | '"zope.mgr",E1000000,p4465649308559,schoolfee_incl,' |
---|
522 | '60250.0,00,1500.0,250.0,0.0,,,\n' |
---|
523 | in logcontent) |
---|