[12730] | 1 | ## $Id: tests.py 15084 2018-07-11 04:18:55Z 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() |
---|
| 52 | configuration = SessionConfiguration() |
---|
| 53 | configuration.academic_session = datetime.now().year - 2 |
---|
| 54 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
| 55 | self.configuration = configuration |
---|
| 56 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 57 | self.browser.open(self.manage_path) |
---|
| 58 | #IWorkflowState(self.student).setState('started') |
---|
| 59 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
[13977] | 60 | #self.browser.getControl(name="form.programme_type").value = ['regular'] |
---|
[13532] | 61 | self.applicantscontainer.application_fee = 10000.0 |
---|
[11846] | 62 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
| 63 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 64 | self.browser.getControl("Save").click() |
---|
[13532] | 65 | |
---|
| 66 | def test_interswitch_form_regular(self): |
---|
[11846] | 67 | self.browser.getControl("Add online").click() |
---|
[13381] | 68 | self.assertTrue('ticket created' in self.browser.contents) |
---|
[11846] | 69 | #self.browser.getLink(value).click() |
---|
[13381] | 70 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
[13532] | 71 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
[11846] | 72 | self.payment_url = self.browser.url |
---|
| 73 | # Manager can access InterswitchForm |
---|
| 74 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 75 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 76 | self.assertTrue( |
---|
[13532] | 77 | '<input type="hidden" name="amount" value="1000000" />' |
---|
[13381] | 78 | in self.browser.contents) |
---|
[13532] | 79 | self.assertTrue( |
---|
[15084] | 80 | 'item_name="WAeAC" item_amt="100000"' |
---|
[13532] | 81 | in self.browser.contents) |
---|
| 82 | self.assertTrue( |
---|
[15084] | 83 | 'item_name="Application Fee" item_amt="875000" bank_id="117" acct_num="1010835352"' |
---|
[13532] | 84 | in self.browser.contents) |
---|
| 85 | self.assertTrue( |
---|
| 86 | '<input type="hidden" name="product_id" value="5845" />' |
---|
| 87 | in self.browser.contents) |
---|
[13017] | 88 | delta = timedelta(days=8) |
---|
[12977] | 89 | self.applicant.values()[0].creation_date -= delta |
---|
| 90 | self.browser.open(self.payment_url) |
---|
| 91 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 92 | self.assertTrue( |
---|
| 93 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 94 | in self.browser.contents) |
---|
[11846] | 95 | |
---|
[14121] | 96 | def test_interswitch_form_pg(self): |
---|
| 97 | self.applicant.applicant_id = u'pg_anything' |
---|
| 98 | self.browser.getControl("Add online").click() |
---|
| 99 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 100 | #self.browser.getLink(value).click() |
---|
| 101 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 102 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
| 103 | self.payment_url = self.browser.url |
---|
| 104 | # Manager can access InterswitchForm |
---|
| 105 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 106 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 107 | self.assertTrue( |
---|
| 108 | '<input type="hidden" name="amount" value="1000000" />' |
---|
| 109 | in self.browser.contents) |
---|
| 110 | self.assertTrue( |
---|
[15084] | 111 | 'item_name="WAeAC" item_amt="100000"' |
---|
[14121] | 112 | in self.browser.contents) |
---|
| 113 | self.assertTrue( |
---|
[15084] | 114 | 'item_name="Application Fee" item_amt="675000" bank_id="117" acct_num="1010835352"' |
---|
[14121] | 115 | in self.browser.contents) |
---|
| 116 | self.assertTrue( |
---|
[14945] | 117 | 'item_name="PG Handbook" item_amt="200000" bank_id="117" acct_num="1010827641"' |
---|
[14121] | 118 | in self.browser.contents) |
---|
| 119 | self.assertTrue( |
---|
| 120 | '<input type="hidden" name="product_id" value="5845" />' |
---|
| 121 | in self.browser.contents) |
---|
| 122 | delta = timedelta(days=8) |
---|
| 123 | self.applicant.values()[0].creation_date -= delta |
---|
| 124 | self.browser.open(self.payment_url) |
---|
| 125 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 126 | self.assertTrue( |
---|
| 127 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 128 | in self.browser.contents) |
---|
| 129 | |
---|
[14122] | 130 | def test_interswitch_form_utme(self): |
---|
| 131 | self.applicant.applicant_id = u'utme_anything' |
---|
| 132 | self.browser.getControl("Add online").click() |
---|
| 133 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 134 | #self.browser.getLink(value).click() |
---|
| 135 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 136 | self.assertTrue('<span>10000.0</span>' in self.browser.contents) |
---|
| 137 | self.payment_url = self.browser.url |
---|
| 138 | # Manager can access InterswitchForm |
---|
| 139 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 140 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 141 | self.assertTrue( |
---|
| 142 | '<input type="hidden" name="amount" value="1000000" />' |
---|
| 143 | in self.browser.contents) |
---|
| 144 | self.assertTrue( |
---|
[15084] | 145 | 'item_name="WAeAC" item_amt="100000"' |
---|
[14122] | 146 | in self.browser.contents) |
---|
| 147 | self.assertTrue( |
---|
[15084] | 148 | 'item_name="Application Fee" item_amt="875000" bank_id="117" acct_num="1010835352"' |
---|
[14122] | 149 | in self.browser.contents) |
---|
| 150 | self.assertTrue( |
---|
| 151 | '<input type="hidden" name="product_id" value="5845" />' |
---|
| 152 | in self.browser.contents) |
---|
| 153 | delta = timedelta(days=8) |
---|
| 154 | self.applicant.values()[0].creation_date -= delta |
---|
| 155 | self.browser.open(self.payment_url) |
---|
| 156 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 157 | self.assertTrue( |
---|
| 158 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 159 | in self.browser.contents) |
---|
| 160 | |
---|
[11846] | 161 | @external_test |
---|
| 162 | def test_webservice(self): |
---|
| 163 | |
---|
| 164 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 165 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
[11846] | 166 | # The payment is now in state failed |
---|
[13381] | 167 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 168 | |
---|
| 169 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
| 170 | """Tests for the Interswitch payment gateway. |
---|
| 171 | """ |
---|
| 172 | |
---|
| 173 | layer = FunctionalLayer |
---|
| 174 | |
---|
| 175 | def setUp(self): |
---|
| 176 | super(InterswitchTestsStudents, self).setUp() |
---|
| 177 | |
---|
[13378] | 178 | def test_interswitch_form_pt_school_fees(self): |
---|
| 179 | self.certificate.study_mode = 'ug_pt' |
---|
[12975] | 180 | self.student['studycourse'].entry_session = 2013 |
---|
[13400] | 181 | self.student['studycourse'].certificate.school_fee_1 = 50250.0 |
---|
| 182 | self.app['configuration']['2004'].union_fee = 1000.0 |
---|
| 183 | self.app['configuration']['2004'].welfare_fee = 500.0 |
---|
[11868] | 184 | # Manager can access InterswitchForm |
---|
| 185 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 186 | self.browser.open(self.payments_path) |
---|
| 187 | IWorkflowState(self.student).setState('cleared') |
---|
| 188 | self.student.nationality = u'NG' |
---|
| 189 | self.browser.open(self.payments_path + '/addop') |
---|
[13400] | 190 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[11868] | 191 | self.browser.getControl("Create ticket").click() |
---|
[13381] | 192 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 193 | ctrl = self.browser.getControl(name='val_id') |
---|
| 194 | self.value = ctrl.options[0] |
---|
| 195 | self.browser.getLink(self.value).click() |
---|
| 196 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
[13438] | 197 | # 50250 + 1000 + 500 -500 |
---|
| 198 | self.assertTrue('<span>51250.0</span>' in self.browser.contents) |
---|
[13381] | 199 | self.payment_url = self.browser.url |
---|
| 200 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 201 | self.assertTrue( |
---|
| 202 | 'Please pay acceptance fee first' in self.browser.contents) |
---|
| 203 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
| 204 | acc_payment.p_state = 'paid' |
---|
| 205 | acc_payment.p_category = 'clearance' |
---|
| 206 | self.student['payments']['xyz'] = acc_payment |
---|
| 207 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 208 | self.assertTrue('<input type="hidden" name="pay_item_id" value="105" />' |
---|
| 209 | in self.browser.contents) |
---|
| 210 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 211 | self.assertEqual(self.student.current_mode, 'ug_pt') |
---|
| 212 | self.assertTrue( |
---|
[13438] | 213 | '<input type="hidden" name="amount" value="5125000" />' |
---|
[13381] | 214 | in self.browser.contents) |
---|
| 215 | self.assertTrue( |
---|
[13410] | 216 | 'item_name="School Fee Plus" ' |
---|
[14920] | 217 | 'item_amt="4600000" bank_id="117" ' |
---|
| 218 | 'acct_num="1010827641"' in self.browser.contents) |
---|
[13381] | 219 | |
---|
| 220 | def test_interswitch_form_regular_school_fees(self): |
---|
| 221 | self.certificate.study_mode = 'ug_ft' |
---|
| 222 | self.student['studycourse'].entry_session = 2013 |
---|
| 223 | self.student['studycourse'].certificate.school_fee_1 = 51750.0 |
---|
| 224 | # Manager can access InterswitchForm |
---|
| 225 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 226 | self.browser.open(self.payments_path) |
---|
| 227 | IWorkflowState(self.student).setState('cleared') |
---|
| 228 | self.student.nationality = u'NG' |
---|
| 229 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 230 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[13381] | 231 | self.browser.getControl("Create ticket").click() |
---|
| 232 | self.assertTrue('ticket created' in |
---|
[11868] | 233 | self.browser.contents) |
---|
| 234 | ctrl = self.browser.getControl(name='val_id') |
---|
| 235 | self.value = ctrl.options[0] |
---|
| 236 | self.browser.getLink(self.value).click() |
---|
[13381] | 237 | self.assertTrue('Amount Authorized' in |
---|
[11868] | 238 | self.browser.contents) |
---|
[13381] | 239 | self.assertTrue('<span>51750.0</span>' in self.browser.contents) |
---|
[11868] | 240 | self.payment_url = self.browser.url |
---|
| 241 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[12975] | 242 | self.assertTrue( |
---|
| 243 | 'Please pay acceptance fee first' in self.browser.contents) |
---|
| 244 | acc_payment = createObject('waeup.StudentOnlinePayment') |
---|
| 245 | acc_payment.p_state = 'paid' |
---|
| 246 | acc_payment.p_category = 'clearance' |
---|
| 247 | self.student['payments']['xyz'] = acc_payment |
---|
| 248 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13652] | 249 | self.assertTrue('<input type="hidden" name="pay_item_id" value="107" />' |
---|
[13381] | 250 | in self.browser.contents) |
---|
| 251 | self.assertTrue('Total Amount Authorized:' |
---|
| 252 | in self.browser.contents) |
---|
| 253 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
| 254 | self.assertTrue( |
---|
| 255 | '<input type="hidden" name="amount" value="5175000" />' |
---|
| 256 | in self.browser.contents) |
---|
| 257 | self.assertTrue( |
---|
[13421] | 258 | 'item_name="School Fee Plus" item_amt="4750000" bank_id="117" ' |
---|
[13381] | 259 | 'acct_num="1010827641"' in self.browser.contents) |
---|
[11868] | 260 | |
---|
[12975] | 261 | |
---|
[13378] | 262 | def test_interswitch_form_pt_acceptance_fees(self): |
---|
| 263 | self.certificate.study_mode = 'ug_pt' |
---|
[13678] | 264 | self.app['configuration']['2004'].clearance_fee_ug_pt = 40250.0 |
---|
[13400] | 265 | self.app['configuration']['2004'].matric_gown_fee = 2000.0 |
---|
| 266 | self.app['configuration']['2004'].lapel_fee = 800.0 |
---|
[12729] | 267 | # Manager can access InterswitchForm |
---|
| 268 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 269 | self.browser.open(self.payments_path) |
---|
| 270 | IWorkflowState(self.student).setState('admitted') |
---|
| 271 | self.student.nationality = u'NG' |
---|
| 272 | self.browser.open(self.payments_path + '/addop') |
---|
[13400] | 273 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
[12729] | 274 | self.browser.getControl("Create ticket").click() |
---|
[13381] | 275 | self.assertTrue('ticket created' in self.browser.contents) |
---|
[12729] | 276 | ctrl = self.browser.getControl(name='val_id') |
---|
| 277 | self.value = ctrl.options[0] |
---|
| 278 | self.browser.getLink(self.value).click() |
---|
[13381] | 279 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
[13438] | 280 | # 40250 + 2000 + 800 - 500 |
---|
| 281 | self.assertTrue('<span>42550.0</span>' in self.browser.contents) |
---|
[12729] | 282 | self.payment_url = self.browser.url |
---|
| 283 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 284 | self.assertTrue('<input type="hidden" name="pay_item_id" value="104" />' in |
---|
[12729] | 285 | self.browser.contents) |
---|
[13381] | 286 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 287 | self.assertTrue( |
---|
[13438] | 288 | '<input type="hidden" name="amount" value="4255000" />' |
---|
[13381] | 289 | in self.browser.contents) |
---|
| 290 | self.assertTrue( |
---|
[13410] | 291 | 'item_name="Acceptance Fee Plus" ' |
---|
[13400] | 292 | 'item_amt="4000000" bank_id="117" ' |
---|
[14920] | 293 | 'acct_num="1010827641"' in self.browser.contents) |
---|
[12729] | 294 | |
---|
[13381] | 295 | def test_interswitch_form_regular_acceptance_fees(self): |
---|
| 296 | self.certificate.study_mode = 'ug_ft' |
---|
| 297 | self.app['configuration']['2004'].clearance_fee = 43050.0 |
---|
| 298 | # Manager can access InterswitchForm |
---|
| 299 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 300 | self.browser.open(self.payments_path) |
---|
| 301 | IWorkflowState(self.student).setState('admitted') |
---|
| 302 | self.student.nationality = u'NG' |
---|
| 303 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 304 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
[13381] | 305 | self.browser.getControl("Create ticket").click() |
---|
| 306 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 307 | ctrl = self.browser.getControl(name='val_id') |
---|
| 308 | self.value = ctrl.options[0] |
---|
| 309 | self.browser.getLink(self.value).click() |
---|
| 310 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 311 | self.assertTrue('<span>43050.0</span>' in self.browser.contents) |
---|
| 312 | self.payment_url = self.browser.url |
---|
| 313 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 314 | self.assertTrue('<input type="hidden" name="pay_item_id" value="102" />' |
---|
| 315 | in self.browser.contents) |
---|
| 316 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
| 317 | self.assertTrue( |
---|
| 318 | '<input type="hidden" name="amount" value="4305000" />' |
---|
| 319 | in self.browser.contents) |
---|
| 320 | self.assertTrue( |
---|
[13421] | 321 | 'item_name="Acceptance Fee Plus" item_amt="4280000" bank_id="117" ' |
---|
[13381] | 322 | 'acct_num="1010827641"' in self.browser.contents) |
---|
| 323 | |
---|
[13464] | 324 | def test_interswitch_form_concessional_fees(self): |
---|
[13381] | 325 | self.certificate.study_mode = 'ug_pt' |
---|
[13464] | 326 | self.app['configuration']['2004'].concessional_fee = 1567.0 |
---|
[13381] | 327 | # Manager can access InterswitchForm |
---|
| 328 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 329 | self.browser.open(self.payments_path) |
---|
| 330 | IWorkflowState(self.student).setState('admitted') |
---|
| 331 | self.student.nationality = u'NG' |
---|
| 332 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 333 | self.browser.getControl(name="form.p_category").value = ['concessional'] |
---|
[13381] | 334 | self.browser.getControl("Create ticket").click() |
---|
| 335 | self.assertTrue('ticket created' in self.browser.contents) |
---|
| 336 | ctrl = self.browser.getControl(name='val_id') |
---|
| 337 | self.value = ctrl.options[0] |
---|
| 338 | self.browser.getLink(self.value).click() |
---|
| 339 | self.assertTrue('Amount Authorized' in self.browser.contents) |
---|
| 340 | self.assertTrue( |
---|
| 341 | '<span>1567.0</span>' in self.browser.contents) |
---|
| 342 | self.payment_url = self.browser.url |
---|
| 343 | self.certificate.study_mode = 'ug_ft' |
---|
| 344 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13421] | 345 | self.assertTrue('<input type="hidden" name="pay_item_id" value="107" />' |
---|
[13381] | 346 | in self.browser.contents) |
---|
| 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( |
---|
[13438] | 352 | 'item_name="Concessional Fee" item_amt="131700" ' |
---|
[14920] | 353 | 'bank_id="117" acct_num="1010827641"' |
---|
[13381] | 354 | in self.browser.contents) |
---|
| 355 | |
---|
[12977] | 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') |
---|
| 368 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 369 | self.assertTrue('<input type="hidden" name="pay_item_id" value="104" />' |
---|
| 370 | in self.browser.contents) |
---|
| 371 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
[13379] | 372 | self.assertEqual(self.student.current_mode, 'ug_pt') |
---|
[13381] | 373 | self.assertTrue( |
---|
| 374 | '<input type="hidden" name="amount" value="87600" />' |
---|
| 375 | in self.browser.contents) |
---|
[13017] | 376 | delta = timedelta(days=8) |
---|
[12977] | 377 | acc_payment.creation_date -= delta |
---|
| 378 | self.browser.open(self.payments_path + '/xyz') |
---|
| 379 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 380 | self.assertTrue( |
---|
| 381 | 'This payment ticket is too old. Please create a new ticket' |
---|
| 382 | in self.browser.contents) |
---|
[13017] | 383 | delta = timedelta(days=2) |
---|
[12977] | 384 | acc_payment.creation_date += delta |
---|
| 385 | self.browser.open(self.payments_path + '/xyz') |
---|
| 386 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[13381] | 387 | self.assertTrue('Total Amount Authorized:' in self.browser.contents) |
---|
[12977] | 388 | |
---|
[11868] | 389 | @external_test |
---|
| 390 | def test_webservice(self): |
---|
| 391 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 392 | self.browser.open(self.payments_path) |
---|
| 393 | IWorkflowState(self.student).setState('cleared') |
---|
| 394 | self.student.nationality = u'NG' |
---|
| 395 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 396 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[11868] | 397 | self.browser.getControl("Create ticket").click() |
---|
[13381] | 398 | self.assertTrue('ticket created' in self.browser.contents) |
---|
[11868] | 399 | ctrl = self.browser.getControl(name='val_id') |
---|
| 400 | self.value = ctrl.options[0] |
---|
| 401 | self.browser.getLink(self.value).click() |
---|
| 402 | self.payment_url = self.browser.url |
---|
[13388] | 403 | # First we have to open InterswitchPageStudent to set provider_amt |
---|
[11868] | 404 | # and gateway_amt |
---|
| 405 | self.browser.open(self.payment_url + '/goto_interswitch') |
---|
| 406 | # Now we can call the webservice |
---|
| 407 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 408 | self.assertTrue('Unsuccessful callback' in self.browser.contents) |
---|
[11868] | 409 | # The payment is now in state failed ... |
---|
[13381] | 410 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 411 | # ... and the catalog has been updated |
---|
| 412 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 413 | results = list( |
---|
| 414 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 415 | self.assertEqual(len(results), 1) |
---|
| 416 | self.assertEqual(results[0].p_state, 'failed') |
---|
| 417 | |
---|
[13385] | 418 | # Let's replace the p_id with a valid p_id of the AAUE |
---|
[11868] | 419 | # live system. This is definitely not an appropriate |
---|
| 420 | # solution for testing, but we have no choice since |
---|
| 421 | # Interswitch doesn't provide any interface |
---|
| 422 | # for testing. |
---|
| 423 | payment = self.student['payments'][self.value] |
---|
[13385] | 424 | payment.p_id = 'p4465649308559' |
---|
[11868] | 425 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13388] | 426 | self.assertTrue('Unsuccessful callback: Amount Inconsistency' in |
---|
[11868] | 427 | self.browser.contents) |
---|
| 428 | # The payment is now in state failed ... |
---|
[13381] | 429 | self.assertTrue('<span>Failed</span>' in self.browser.contents) |
---|
[11868] | 430 | # Let's replace the amount autorized with the amount of the |
---|
| 431 | # live system payment |
---|
[13388] | 432 | payment.amount_auth = 60250.0 |
---|
[11868] | 433 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[13381] | 434 | self.assertTrue('Successful payment' in |
---|
[11868] | 435 | self.browser.contents) |
---|
| 436 | # The payment is now in state paid ... |
---|
[13381] | 437 | self.assertTrue('<span>Paid</span>' in self.browser.contents) |
---|
[11868] | 438 | # ... and the catalog has been updated |
---|
| 439 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 440 | results = list( |
---|
| 441 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
| 442 | self.assertEqual(len(results), 1) |
---|
| 443 | self.assertEqual(results[0].p_state, 'paid') |
---|
| 444 | # Approval is logged in students.log ... |
---|
| 445 | logfile = os.path.join( |
---|
| 446 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 447 | logcontent = open(logfile).read() |
---|
| 448 | self.assertTrue( |
---|
| 449 | 'zope.mgr - ' |
---|
| 450 | 'waeup.aaue.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - ' |
---|
[13530] | 451 | 'E1000000 - successful schoolfee_incl payment: p4465649308559\n' |
---|
[11868] | 452 | in logcontent) |
---|
| 453 | # ... and in payments.log |
---|
| 454 | logfile = os.path.join( |
---|
| 455 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
| 456 | logcontent = open(logfile).read() |
---|
| 457 | self.assertTrue( |
---|
[13530] | 458 | '"zope.mgr",E1000000,p4465649308559,schoolfee_incl,' |
---|
[13385] | 459 | '60250.0,00,1500.0,250.0,0.0,,,\n' |
---|
[11868] | 460 | in logcontent) |
---|