[12730] | 1 | ## $Id: tests.py 17837 2024-07-08 17:41:00Z henrik $ |
---|
[11846] | 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. |
---|
[13388] | 31 | EXTERNAL_TESTS = False |
---|
[11846] | 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() |
---|
[15455] | 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) |
---|
[11846] | 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() |
---|
[13977] | 66 | #self.browser.getControl(name="form.programme_type").value = ['regular'] |
---|
[13532] | 67 | self.applicantscontainer.application_fee = 10000.0 |
---|
[11846] | 68 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
[15455] | 69 | self.browser.getControl(name="form.course2").value = ['CERT2'] |
---|
[11846] | 70 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 71 | self.browser.getControl("Save").click() |
---|
[13532] | 72 | |
---|
[17469] | 73 | def test_interswitch_form_regular(self): |
---|
[11846] | 74 | self.browser.getControl("Add online").click() |
---|
[13381] | 75 | self.assertTrue('ticket created' in self.browser.contents) |
---|
[11846] | 76 | #self.browser.getLink(value).click() |
---|
[13381] | 77 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
[13532] | 78 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
[11846] | 79 | self.payment_url = self.browser.url |
---|
| 80 | # Manager can access InterswitchForm |
---|
[15712] | 81 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 82 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 83 | self.assertTrue( |
---|
[17481] | 84 | '<input type="hidden" name="amount" value="1220000" />' |
---|
[13381] | 85 | in self.browser.contents) |
---|
[13532] | 86 | self.assertTrue( |
---|
[17481] | 87 | 'item_name="WAeAC Portal Fee" item_amt="200000"' |
---|
[13532] | 88 | in self.browser.contents) |
---|
| 89 | self.assertTrue( |
---|
[17657] | 90 | 'item_name="Application Fee" item_amt="1000000" bank_id="8" acct_num="2043582644"' |
---|
[13532] | 91 | in self.browser.contents) |
---|
| 92 | self.assertTrue( |
---|
| 93 | '<input type="hidden" name="product_id" value="5845" />' |
---|
| 94 | in self.browser.contents) |
---|
[13017] | 95 | delta = timedelta(days=8) |
---|
[12977] | 96 | self.applicant.values()[0].creation_date -= delta |
---|
| 97 | self.browser.open(self.payment_url) |
---|
[15712] | 98 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 99 | self.assertTrue( |
---|
| 100 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 101 | in self.browser.contents) |
---|
[11846] | 102 | |
---|
[17431] | 103 | def deactivated_test_interswitch_form_pg(self): |
---|
[14121] | 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 |
---|
[15712] | 112 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[14121] | 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( |
---|
[15260] | 118 | 'item_name="WAeAC" item_amt="200000"' |
---|
[14121] | 119 | in self.browser.contents) |
---|
| 120 | self.assertTrue( |
---|
[16898] | 121 | 'item_name="Application Fee" item_amt="580000" bank_id="51" acct_num="5210006575"' |
---|
[14121] | 122 | in self.browser.contents) |
---|
| 123 | self.assertTrue( |
---|
[16897] | 124 | 'item_name="PG Handbook" item_amt="200000" bank_id="51" acct_num="5210006575"' |
---|
[14121] | 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) |
---|
[15712] | 132 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[14121] | 133 | self.assertTrue( |
---|
| 134 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 135 | in self.browser.contents) |
---|
| 136 | |
---|
[17431] | 137 | def deactivated_test_interswitch_form_utme(self): |
---|
[14122] | 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 |
---|
[15712] | 146 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[14122] | 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( |
---|
[15260] | 152 | 'item_name="WAeAC" item_amt="200000"' |
---|
[14122] | 153 | in self.browser.contents) |
---|
| 154 | self.assertTrue( |
---|
[15867] | 155 | 'item_name="Application Fee" item_amt="780000" bank_id="117" acct_num="1010835352"' |
---|
[14122] | 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) |
---|
[15712] | 163 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[14122] | 164 | self.assertTrue( |
---|
| 165 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 166 | in self.browser.contents) |
---|
| 167 | |
---|
[17431] | 168 | def deactivated_test_interswitch_form_bridge(self): |
---|
[15224] | 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 |
---|
[15712] | 177 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[15224] | 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( |
---|
[15867] | 186 | 'item_name="Application Fee" item_amt="780000" bank_id="7" acct_num="1014847058"' |
---|
[15224] | 187 | in self.browser.contents) |
---|
| 188 | |
---|
[11846] | 189 | @external_test |
---|
| 190 | def test_webservice(self): |
---|
| 191 | |
---|
| 192 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 193 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
[11846] | 194 | # The payment is now in state failed |
---|
[13381] | 195 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 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() |
---|
[15763] | 205 | self.app['configuration']['2004'].interswitch_enabled = True |
---|
[11868] | 206 | |
---|
[13381] | 207 | def test_interswitch_form_regular_school_fees(self): |
---|
| 208 | self.certificate.study_mode = 'ug_ft' |
---|
[17431] | 209 | #self.student['studycourse'].entry_session = 2013 |
---|
| 210 | #self.student['studycourse'].certificate.school_fee_3 = 51750.0 |
---|
[13381] | 211 | # Manager can access InterswitchForm |
---|
| 212 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 213 | self.browser.open(self.payments_path) |
---|
| 214 | IWorkflowState(self.student).setState('cleared') |
---|
| 215 | self.student.nationality = u'NG' |
---|
| 216 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 217 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[13381] | 218 | self.browser.getControl("Create ticket").click() |
---|
| 219 | self.assertTrue('ticket created' in |
---|
[11868] | 220 | self.browser.contents) |
---|
[13381] | 221 | self.assertTrue('Amount Authorized' in |
---|
[11868] | 222 | self.browser.contents) |
---|
[17503] | 223 | self.assertTrue('<span>240500.0</span>' in self.browser.contents) |
---|
[11868] | 224 | self.payment_url = self.browser.url |
---|
[15712] | 225 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 226 | self.assertTrue('Total Amount Authorized:' |
---|
| 227 | in self.browser.contents) |
---|
| 228 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
| 229 | self.assertTrue( |
---|
[17503] | 230 | '<input type="hidden" name="amount" value="24320000" />' |
---|
[13381] | 231 | in self.browser.contents) |
---|
| 232 | self.assertTrue( |
---|
[17437] | 233 | 'item_name="Tuition" item_amt="18400000" bank_id="7" ' |
---|
[17431] | 234 | 'acct_num="1022438743"' in self.browser.contents) |
---|
[11868] | 235 | |
---|
[17431] | 236 | self.student['studycourse'].entry_session = 2015 |
---|
| 237 | self.browser.open(self.payments_path + '/addop') |
---|
| 238 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
| 239 | self.browser.getControl("Create ticket").click() |
---|
| 240 | self.assertTrue('ticket created' in |
---|
| 241 | self.browser.contents) |
---|
| 242 | self.assertTrue('<span>92000.0</span>' in self.browser.contents) |
---|
| 243 | self.payment_url = self.browser.url |
---|
| 244 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
| 245 | self.assertTrue( |
---|
[17434] | 246 | 'Please pay acceptance fee first' in self.browser.contents) |
---|
| 247 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
| 248 | acc_payment.p_state = 'paid' |
---|
| 249 | acc_payment.p_category = 'clearance' |
---|
| 250 | self.student['payments']['xyz'] = acc_payment |
---|
| 251 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
| 252 | self.assertTrue( |
---|
[17431] | 253 | '<input type="hidden" name="amount" value="9220000" />' |
---|
| 254 | in self.browser.contents) |
---|
| 255 | self.assertTrue( |
---|
[17440] | 256 | 'item_name="School Fees (2nd instalment)" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
[17431] | 257 | |
---|
| 258 | self.browser.open(self.payments_path + '/addop') |
---|
| 259 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
| 260 | self.browser.getControl("Create ticket").click() |
---|
| 261 | self.assertTrue('ticket created' in |
---|
| 262 | self.browser.contents) |
---|
[17837] | 263 | self.assertTrue('<span>148500.0</span>' in self.browser.contents) |
---|
[17431] | 264 | self.payment_url = self.browser.url |
---|
| 265 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
| 266 | self.assertTrue( |
---|
[17837] | 267 | '<input type="hidden" name="amount" value="15120000" />' |
---|
[17431] | 268 | in self.browser.contents) |
---|
| 269 | self.assertTrue( |
---|
[17445] | 270 | 'item_name="Student Union Dues" item_amt="3000000" bank_id="7" acct_num="1019763348"' in self.browser.contents) |
---|
[17431] | 271 | self.assertTrue( |
---|
[17437] | 272 | 'item_name="Tuition" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
[17431] | 273 | |
---|
| 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 | '<input type="hidden" name="amount" value="9220000" />' |
---|
| 284 | in self.browser.contents) |
---|
| 285 | self.assertTrue( |
---|
[17440] | 286 | 'item_name="School Fees (2nd instalment)" item_amt="9200000" bank_id="7" acct_num="1022438743"' in self.browser.contents) |
---|
[17431] | 287 | |
---|
[13381] | 288 | def test_interswitch_form_regular_acceptance_fees(self): |
---|
| 289 | self.certificate.study_mode = 'ug_ft' |
---|
[17431] | 290 | #self.app['configuration']['2004'].clearance_fee = 43050.0 |
---|
[13381] | 291 | # Manager can access InterswitchForm |
---|
| 292 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 293 | self.browser.open(self.payments_path) |
---|
| 294 | IWorkflowState(self.student).setState('admitted') |
---|
| 295 | self.student.nationality = u'NG' |
---|
| 296 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 297 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
[13381] | 298 | self.browser.getControl("Create ticket").click() |
---|
| 299 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 300 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
[17431] | 301 | self.assertTrue('<span>16800.0</span>' in self.browser.contents) |
---|
[15712] | 302 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 303 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 304 | self.assertTrue( |
---|
[17431] | 305 | '<input type="hidden" name="amount" value="1850000" />' |
---|
[13381] | 306 | in self.browser.contents) |
---|
[17431] | 307 | self.assertTrue(self.student['payments'].values()[0].net_amt == 16800) |
---|
[13381] | 308 | self.assertTrue( |
---|
[17437] | 309 | 'item_name="Acceptance Fee" item_amt="1400000" bank_id="8" ' |
---|
[17657] | 310 | 'acct_num="2043582644"' in self.browser.contents) |
---|
[13381] | 311 | |
---|
[17431] | 312 | self.certificate.study_mode = 'bridge' |
---|
| 313 | self.browser.open(self.payments_path + '/addop') |
---|
| 314 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
| 315 | self.browser.getControl("Create ticket").click() |
---|
| 316 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 317 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 318 | self.assertTrue('<span>14000.0</span>' in self.browser.contents) |
---|
| 319 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
| 320 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 321 | self.assertTrue( |
---|
| 322 | '<input type="hidden" name="amount" value="1570000" />' |
---|
| 323 | in self.browser.contents) |
---|
| 324 | self.assertTrue(self.student['payments'].values()[1].net_amt == 14000) |
---|
| 325 | self.assertTrue( |
---|
| 326 | 'item_name="Acceptance Fee" item_amt="1400000" bank_id="8" ' |
---|
[17657] | 327 | 'acct_num="2043582644"' in self.browser.contents) |
---|
[17431] | 328 | |
---|
| 329 | def deactivated_test_interswitch_form_concessional_fees(self): |
---|
[15388] | 330 | self.certificate.study_mode = 'ug_ft' |
---|
[13464] | 331 | self.app['configuration']['2004'].concessional_fee = 1567.0 |
---|
[13381] | 332 | # Manager can access InterswitchForm |
---|
| 333 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 334 | self.browser.open(self.payments_path) |
---|
| 335 | IWorkflowState(self.student).setState('admitted') |
---|
| 336 | self.student.nationality = u'NG' |
---|
| 337 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 338 | self.browser.getControl(name="form.p_category").value = ['concessional'] |
---|
[13381] | 339 | self.browser.getControl("Create ticket").click() |
---|
| 340 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 341 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 342 | self.assertTrue( |
---|
| 343 | '<span>1567.0</span>' in self.browser.contents) |
---|
| 344 | self.payment_url = self.browser.url |
---|
| 345 | self.certificate.study_mode = 'ug_ft' |
---|
[15712] | 346 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 347 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 348 | self.assertTrue( |
---|
| 349 | '<input type="hidden" name="amount" value="156700" />' |
---|
| 350 | in self.browser.contents) |
---|
| 351 | self.assertTrue( |
---|
[15867] | 352 | 'item_name="Concessional Fee" item_amt="136700" ' |
---|
[14920] | 353 | 'bank_id="117" acct_num="1010827641"' |
---|
[13381] | 354 | in self.browser.contents) |
---|
| 355 | |
---|
[17456] | 356 | def test_interswitch_form_ticket_expired(self): |
---|
[13379] | 357 | self.certificate.study_mode = 'ug_pt' |
---|
[12977] | 358 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 359 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
| 360 | acc_payment.p_state = 'unpaid' |
---|
[13408] | 361 | acc_payment.p_session = 2004 |
---|
[12977] | 362 | acc_payment.p_category = 'clearance' |
---|
| 363 | acc_payment.p_id = 'xyz' |
---|
| 364 | acc_payment.pay_item_id = '123' |
---|
| 365 | acc_payment.amount_auth = 876.0 |
---|
| 366 | self.student['payments']['xyz'] = acc_payment |
---|
| 367 | self.browser.open(self.payments_path + '/xyz') |
---|
[15712] | 368 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 369 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
[13379] | 370 | self.assertEqual(self.student.current_mode, 'ug_pt') |
---|
[13381] | 371 | self.assertTrue( |
---|
[17456] | 372 | '<input type="hidden" name="amount" value="257600" />' |
---|
[13381] | 373 | in self.browser.contents) |
---|
[13017] | 374 | delta = timedelta(days=8) |
---|
[12977] | 375 | acc_payment.creation_date -= delta |
---|
| 376 | self.browser.open(self.payments_path + '/xyz') |
---|
[15712] | 377 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 378 | self.assertTrue( |
---|
| 379 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 380 | in self.browser.contents) |
---|
[13017] | 381 | delta = timedelta(days=2) |
---|
[12977] | 382 | acc_payment.creation_date += delta |
---|
| 383 | self.browser.open(self.payments_path + '/xyz') |
---|
[15712] | 384 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
[13381] | 385 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
[12977] | 386 | |
---|
[11868] | 387 | @external_test |
---|
| 388 | def test_webservice(self): |
---|
| 389 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 390 | self.browser.open(self.payments_path) |
---|
| 391 | IWorkflowState(self.student).setState('cleared') |
---|
| 392 | self.student.nationality = u'NG' |
---|
| 393 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 394 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[11868] | 395 | self.browser.getControl("Create ticket").click() |
---|
[13381] | 396 | self.assertTrue('ticket created' in self.browser.contents) |
---|
[11868] | 397 | ctrl = self.browser.getControl(name='val_id') |
---|
| 398 | self.value = ctrl.options[0] |
---|
| 399 | self.browser.getLink(self.value).click() |
---|
| 400 | self.payment_url = self.browser.url |
---|
[13388] | 401 | # First we have to open InterswitchPageStudent to set provider_amt |
---|
[11868] | 402 | # and gateway_amt |
---|
| 403 | self.browser.open(self.payment_url + '/goto_interswitch') |
---|
| 404 | # Now we can call the webservice |
---|
| 405 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 406 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
[11868] | 407 | # The payment is now in state failed ... |
---|
[13381] | 408 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 409 | # ... and the catalog has been updated |
---|
| 410 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 411 | results = list( |
---|
| 412 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 413 | self.assertEqual(len(results), 1) |
---|
| 414 | self.assertEqual(results[0].p_state, 'failed') |
---|
| 415 | |
---|
[13385] | 416 | # Let's replace the p_id with a valid p_id of the AAUE |
---|
[11868] | 417 | # live system. This is definitely not an appropriate |
---|
| 418 | # solution for testing, but we have no choice since |
---|
| 419 | # Interswitch doesn't provide any interface |
---|
| 420 | # for testing. |
---|
| 421 | payment = self.student['payments'][self.value] |
---|
[13385] | 422 | payment.p_id = 'p4465649308559' |
---|
[11868] | 423 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13388] | 424 | self.assertTrue('Unsuccessful callback: Amount Inconsistency' in |
---|
[11868] | 425 | self.browser.contents) |
---|
| 426 | # The payment is now in state failed ... |
---|
[13381] | 427 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 428 | # Let's replace the amount autorized with the amount of the |
---|
| 429 | # live system payment |
---|
[13388] | 430 | payment.amount_auth = 60250.0 |
---|
[11868] | 431 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 432 | self.assertTrue('Successful payment' in |
---|
[11868] | 433 | self.browser.contents) |
---|
| 434 | # The payment is now in state paid ... |
---|
[13381] | 435 | self.assertTrue('<span>Paid</span>' in self.browser.contents) |
---|
[11868] | 436 | # ... and the catalog has been updated |
---|
| 437 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 438 | results = list( |
---|
| 439 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
| 440 | self.assertEqual(len(results), 1) |
---|
| 441 | self.assertEqual(results[0].p_state, 'paid') |
---|
| 442 | # Approval is logged in students.log ... |
---|
| 443 | logfile = os.path.join( |
---|
| 444 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 445 | logcontent = open(logfile).read() |
---|
| 446 | self.assertTrue( |
---|
| 447 | 'zope.mgr - ' |
---|
| 448 | 'waeup.aaue.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - ' |
---|
[13530] | 449 | 'E1000000 - successful schoolfee_incl payment: p4465649308559\n' |
---|
[11868] | 450 | in logcontent) |
---|
| 451 | # ... and in payments.log |
---|
| 452 | logfile = os.path.join( |
---|
| 453 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
| 454 | logcontent = open(logfile).read() |
---|
| 455 | self.assertTrue( |
---|
[13530] | 456 | '"zope.mgr",E1000000,p4465649308559,schoolfee_incl,' |
---|
[13385] | 457 | '60250.0,00,1500.0,250.0,0.0,,,\n' |
---|
[11868] | 458 | in logcontent) |
---|