[7894] | 1 | ## $Id: tests.py 10736 2013-11-10 07:46:56Z 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 | ## |
---|
[9789] | 18 | import os |
---|
[9387] | 19 | import grok |
---|
[7894] | 20 | from hurry.workflow.interfaces import IWorkflowState |
---|
[9710] | 21 | from zope.component import createObject, getUtility |
---|
| 22 | from zope.catalog.interfaces import ICatalog |
---|
[9387] | 23 | from zope.event import notify |
---|
| 24 | from waeup.kofa.university.faculty import Faculty |
---|
| 25 | from waeup.kofa.university.department import Department |
---|
[7894] | 26 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 27 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 28 | from waeup.kofa.configuration import SessionConfiguration |
---|
[9347] | 29 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
[10675] | 30 | from waeup.kwarapoly.students.payments import CustomStudentOnlinePayment |
---|
[7894] | 31 | |
---|
[7970] | 32 | # Also run tests that send requests to external servers? |
---|
| 33 | # If you enable this, please make sure the external services |
---|
| 34 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[9811] | 35 | EXTERNAL_TESTS = False |
---|
[7970] | 36 | |
---|
| 37 | def external_test(func): |
---|
| 38 | if not EXTERNAL_TESTS: |
---|
| 39 | myself = __file__ |
---|
| 40 | if myself.endswith('.pyc'): |
---|
| 41 | myself = myself[:-2] |
---|
| 42 | print "WARNING: external tests are skipped!" |
---|
| 43 | print "WARNING: edit %s to enable them." % myself |
---|
| 44 | return |
---|
| 45 | return func |
---|
| 46 | |
---|
| 47 | |
---|
[8266] | 48 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 49 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 50 | """ |
---|
| 51 | |
---|
| 52 | layer = FunctionalLayer |
---|
| 53 | |
---|
[7970] | 54 | def setUp(self): |
---|
[8266] | 55 | super(InterswitchTestsStudents, self).setUp() |
---|
[9387] | 56 | |
---|
| 57 | # Create at least one Kwarapoly faculty |
---|
| 58 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 59 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 60 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 61 | self.certificate2.code = u'CERT2' |
---|
| 62 | self.certificate2.application_category = 'basic' |
---|
| 63 | self.certificate2.study_mode = 'nd_ft' |
---|
| 64 | self.certificate2.start_level = 100 |
---|
| 65 | self.certificate2.end_level = 300 |
---|
| 66 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 67 | self.certificate2) |
---|
| 68 | # Set study course attributes of test student |
---|
| 69 | self.student['studycourse'].certificate = self.certificate2 |
---|
| 70 | self.student['studycourse'].current_session = 2004 |
---|
| 71 | self.student['studycourse'].entry_session = 2004 |
---|
| 72 | self.student['studycourse'].current_verdict = 'A' |
---|
| 73 | self.student['studycourse'].current_level = 100 |
---|
[9392] | 74 | # Set local lga |
---|
| 75 | self.student.lga = u'kwara_asa' |
---|
[9387] | 76 | # Update the catalog |
---|
| 77 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
| 78 | |
---|
[10675] | 79 | |
---|
| 80 | def test_schoolfee_ticket_creation(self): |
---|
[7970] | 81 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 82 | self.browser.open(self.payments_path) |
---|
[7970] | 83 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 84 | self.browser.open(self.payments_path + '/addop') |
---|
[9737] | 85 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7970] | 86 | self.browser.getControl("Create ticket").click() |
---|
[10675] | 87 | self.assertMatches('...Book and pay for accommodation first...', |
---|
| 88 | self.browser.contents) |
---|
| 89 | # We add a fake maint. payment ticket to meet the condition |
---|
| 90 | maint_payment = CustomStudentOnlinePayment() |
---|
| 91 | self.student['payments']['any_key'] = maint_payment |
---|
| 92 | maint_payment.p_category = 'hostel_maintenance' |
---|
| 93 | maint_payment.p_state = 'unpaid' |
---|
| 94 | maint_payment.p_session = 2004 |
---|
| 95 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 96 | self.browser.getControl("Create ticket").click() |
---|
| 97 | self.assertMatches('...Book and pay for accommodation first...', |
---|
| 98 | self.browser.contents) |
---|
| 99 | # Ticket must be paid |
---|
| 100 | maint_payment.p_state = 'paid' |
---|
| 101 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 102 | self.browser.getControl("Create ticket").click() |
---|
[9436] | 103 | self.assertMatches('...ticket created...', |
---|
| 104 | self.browser.contents) |
---|
| 105 | ctrl = self.browser.getControl(name='val_id') |
---|
[10675] | 106 | self.value = ctrl.options[1] |
---|
[9789] | 107 | self.browser.getLink(self.value).click() |
---|
[9436] | 108 | self.assertMatches('...Amount Authorized...', |
---|
| 109 | self.browser.contents) |
---|
| 110 | self.assertMatches( |
---|
[10672] | 111 | '...<span>39400.0</span>...', |
---|
[9436] | 112 | self.browser.contents) |
---|
| 113 | self.payment_url = self.browser.url |
---|
[7970] | 114 | |
---|
| 115 | |
---|
[8263] | 116 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 117 | # return payment_url + ( |
---|
| 118 | # '/isw_callback?echo=' + |
---|
| 119 | # '&resp=%s' + |
---|
| 120 | # '&desc=Something went wrong' + |
---|
| 121 | # '&txnRef=p1331792385335' + |
---|
| 122 | # '&payRef=' + '&retRef=' + |
---|
| 123 | # '&cardNum=0' + |
---|
| 124 | # '&apprAmt=%s' + |
---|
| 125 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 126 | |
---|
[7970] | 127 | def test_interswitch_form(self): |
---|
[10675] | 128 | |
---|
| 129 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 130 | self.browser.open(self.payments_path) |
---|
| 131 | # In KwaraPoly only returning students can create school fee payment |
---|
| 132 | # without haveing paid accommodation fee |
---|
| 133 | IWorkflowState(self.student).setState('returning') |
---|
| 134 | configuration = createObject('waeup.SessionConfiguration') |
---|
| 135 | configuration.academic_session = 2005 |
---|
| 136 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
| 137 | self.browser.open(self.payments_path + '/addop') |
---|
| 138 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 139 | self.browser.getControl("Create ticket").click() |
---|
| 140 | self.assertMatches('...ticket created...', self.browser.contents) |
---|
| 141 | ctrl = self.browser.getControl(name='val_id') |
---|
| 142 | self.value = ctrl.options[0] |
---|
| 143 | self.browser.getLink(self.value).click() |
---|
| 144 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 145 | self.assertMatches( |
---|
| 146 | '...<span>29500.0</span>...', |
---|
| 147 | self.browser.contents) |
---|
| 148 | self.payment_url = self.browser.url |
---|
| 149 | |
---|
[7894] | 150 | # Manager can access InterswitchForm |
---|
[9789] | 151 | self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0) |
---|
| 152 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0) |
---|
| 153 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0) |
---|
[7894] | 154 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 155 | # Split amounts have been set. |
---|
| 156 | self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0) |
---|
| 157 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0) |
---|
| 158 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0) |
---|
[7894] | 159 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 160 | self.browser.contents) |
---|
[9811] | 161 | self.assertTrue( |
---|
[10675] | 162 | '<input type="hidden" name="amount" value="2950000.0" />' in |
---|
[7894] | 163 | self.browser.contents) |
---|
[9811] | 164 | self.assertTrue( |
---|
[10675] | 165 | 'item_name="School Fee" item_amt="2620000" bank_id="120" acct_num="1771180233"' in |
---|
[9129] | 166 | self.browser.contents) |
---|
[9811] | 167 | self.assertTrue( |
---|
| 168 | 'item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"' in |
---|
[9129] | 169 | self.browser.contents) |
---|
[9811] | 170 | self.assertTrue( |
---|
| 171 | 'item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"' in |
---|
[9129] | 172 | self.browser.contents) |
---|
[7894] | 173 | |
---|
[9616] | 174 | # Let's do the same for maintenance fee payment |
---|
| 175 | |
---|
| 176 | self.browser.open(self.payments_path) |
---|
| 177 | self.browser.open(self.payments_path + '/addop') |
---|
| 178 | self.browser.getControl( |
---|
| 179 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 180 | self.browser.getControl("Create ticket").click() |
---|
| 181 | self.assertMatches('...You have not yet booked accommodation...', |
---|
| 182 | self.browser.contents) |
---|
| 183 | # Students have to book bed first |
---|
| 184 | self.browser.open(self.acco_path) |
---|
| 185 | IWorkflowState(self.student).setState('admitted') |
---|
| 186 | self.browser.getLink("Book accommodation").click() |
---|
| 187 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
| 188 | self.browser.getControl("Create bed ticket").click() |
---|
| 189 | # Bed is randomly selected but, since there is only |
---|
| 190 | # one bed for this student, we know that ... |
---|
| 191 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
| 192 | self.browser.contents) |
---|
| 193 | self.assertMatches('...ticket created...', |
---|
| 194 | self.browser.contents) |
---|
| 195 | self.browser.open(self.payments_path + '/addop') |
---|
| 196 | self.browser.getControl( |
---|
| 197 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 198 | self.browser.getControl("Create ticket").click() |
---|
| 199 | self.assertMatches('...ticket created...', |
---|
| 200 | self.browser.contents) |
---|
| 201 | ctrl = self.browser.getControl(name='val_id') |
---|
| 202 | value = ctrl.options[1] |
---|
| 203 | self.browser.getLink(value).click() |
---|
| 204 | self.assertMatches('...Amount Authorized...', |
---|
| 205 | self.browser.contents) |
---|
[10682] | 206 | # Maint fee is taken from the hostel object |
---|
[9616] | 207 | self.assertMatches( |
---|
[10682] | 208 | '...<span>876.0</span>...', |
---|
[9616] | 209 | self.browser.contents) |
---|
| 210 | self.payment_url = self.browser.url |
---|
| 211 | # Manager can access InterswitchForm |
---|
| 212 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 213 | # Split amounts have been set. |
---|
| 214 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
| 215 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0) |
---|
| 216 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
[9616] | 217 | # The total amount to be processed by Interswitch |
---|
| 218 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 219 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 220 | self.browser.contents) |
---|
| 221 | self.assertMatches( |
---|
[9626] | 222 | '...<input type="hidden" name="pay_item_id" value="102" />...', |
---|
| 223 | self.browser.contents) |
---|
| 224 | self.assertMatches( |
---|
[10682] | 225 | '...<input type="hidden" name="amount" value="87600.0" />...', |
---|
[9616] | 226 | self.browser.contents) |
---|
| 227 | self.assertMatches( |
---|
[10682] | 228 | '...item_name="Hostel Maintenance Fee" item_amt="57600" bank_id="31" acct_num="0039050937"...', |
---|
[9616] | 229 | self.browser.contents) |
---|
| 230 | |
---|
[9737] | 231 | # Create carryover ticket |
---|
| 232 | self.browser.open(self.payments_path + '/addop') |
---|
| 233 | self.browser.getControl(name="form.p_category").value = ['carryover1'] |
---|
| 234 | self.browser.getControl("Create ticket").click() |
---|
| 235 | ctrl = self.browser.getControl(name='val_id') |
---|
| 236 | value = ctrl.options[2] |
---|
| 237 | self.browser.getLink(value).click() |
---|
| 238 | self.assertMatches( |
---|
| 239 | '...<span>6000.0</span>...', |
---|
| 240 | self.browser.contents) |
---|
| 241 | # Manager can access InterswitchForm |
---|
| 242 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 243 | # Split amounts have been set. |
---|
| 244 | self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0) |
---|
| 245 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0) |
---|
| 246 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0) |
---|
[9737] | 247 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="101" />...', |
---|
| 248 | self.browser.contents) |
---|
| 249 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 250 | self.browser.contents) |
---|
| 251 | self.assertMatches( |
---|
| 252 | '...<input type="hidden" name="amount" value="600000.0" />...', |
---|
| 253 | self.browser.contents) |
---|
| 254 | self.assertMatches( |
---|
| 255 | '...item_name="School Fee" item_amt="270000" bank_id="120" acct_num="1771180233"...', |
---|
| 256 | self.browser.contents) |
---|
| 257 | self.assertMatches( |
---|
| 258 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
| 259 | self.browser.contents) |
---|
| 260 | self.assertMatches( |
---|
| 261 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
| 262 | self.browser.contents) |
---|
| 263 | |
---|
[10736] | 264 | def test_interswitch_form_new_payment_cats(self): |
---|
| 265 | # only a few categories covered |
---|
| 266 | |
---|
| 267 | self.app['configuration']['2004'].certificate_fee = 6800.0 |
---|
| 268 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 269 | self.browser.open(self.payments_path + '/addop') |
---|
| 270 | self.browser.getControl(name="form.p_category").value = ['certificate'] |
---|
| 271 | self.browser.getControl("Create ticket").click() |
---|
| 272 | self.assertMatches('...ticket created...', self.browser.contents) |
---|
| 273 | ctrl = self.browser.getControl(name='val_id') |
---|
| 274 | value = ctrl.options[0] |
---|
| 275 | self.browser.getLink(value).click() |
---|
| 276 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 277 | self.assertMatches( |
---|
| 278 | '...<span>6800.0</span>...', self.browser.contents) |
---|
| 279 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 280 | self.assertEqual(self.student['payments'][value].amount_auth, 6800.0) |
---|
| 281 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 282 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 283 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 284 | |
---|
| 285 | self.app['configuration']['2004'].transcript_local_fee = 5000.0 |
---|
| 286 | self.browser.open(self.payments_path + '/addop') |
---|
| 287 | self.browser.getControl(name="form.p_category").value = ['transcript_local'] |
---|
| 288 | self.browser.getControl("Create ticket").click() |
---|
| 289 | ctrl = self.browser.getControl(name='val_id') |
---|
| 290 | value = ctrl.options[1] |
---|
| 291 | self.browser.getLink(value).click() |
---|
| 292 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 293 | self.assertMatches( |
---|
| 294 | '...<span>5000.0</span>...', self.browser.contents) |
---|
| 295 | self.payment_url = self.browser.url |
---|
| 296 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 297 | self.assertEqual(self.student['payments'][value].amount_auth, 5000.0) |
---|
| 298 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 299 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 300 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 301 | |
---|
| 302 | self.app['configuration']['2004'].loss_idcard_fee = 1000.0 |
---|
| 303 | self.browser.open(self.payments_path + '/addop') |
---|
| 304 | self.browser.getControl(name="form.p_category").value = ['loss_idcard'] |
---|
| 305 | self.browser.getControl("Create ticket").click() |
---|
| 306 | ctrl = self.browser.getControl(name='val_id') |
---|
| 307 | value = ctrl.options[2] |
---|
| 308 | self.browser.getLink(value).click() |
---|
| 309 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 310 | self.assertMatches( |
---|
| 311 | '...<span>1000.0</span>...', self.browser.contents) |
---|
| 312 | self.payment_url = self.browser.url |
---|
| 313 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 314 | self.assertEqual(self.student['payments'][value].amount_auth, 1000.0) |
---|
| 315 | self.assertEqual(self.student['payments'][value].provider_amt, 9.0) |
---|
| 316 | self.assertEqual(self.student['payments'][value].gateway_amt, 15.0) |
---|
| 317 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 6.0) |
---|
| 318 | |
---|
| 319 | self.app['configuration']['2004'].loss_examcard_fee = 500.0 |
---|
| 320 | self.browser.open(self.payments_path + '/addop') |
---|
| 321 | self.browser.getControl(name="form.p_category").value = ['loss_examcard'] |
---|
| 322 | self.browser.getControl("Create ticket").click() |
---|
| 323 | ctrl = self.browser.getControl(name='val_id') |
---|
| 324 | value = ctrl.options[3] |
---|
| 325 | self.browser.getLink(value).click() |
---|
| 326 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 327 | self.assertMatches( |
---|
| 328 | '...<span>500.0</span>...', self.browser.contents) |
---|
| 329 | self.payment_url = self.browser.url |
---|
| 330 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 331 | self.assertEqual(self.student['payments'][value].amount_auth, 500.0) |
---|
| 332 | self.assertEqual(self.student['payments'][value].provider_amt, 4.5) |
---|
| 333 | self.assertEqual(self.student['payments'][value].gateway_amt, 7.5) |
---|
| 334 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 3) |
---|
| 335 | |
---|
| 336 | self.app['configuration']['2004'].change_inst_fee = 6000.0 |
---|
| 337 | self.browser.open(self.payments_path + '/addop') |
---|
| 338 | self.browser.getControl(name="form.p_category").value = ['change_inst'] |
---|
| 339 | self.browser.getControl("Create ticket").click() |
---|
| 340 | ctrl = self.browser.getControl(name='val_id') |
---|
| 341 | value = ctrl.options[4] |
---|
| 342 | self.browser.getLink(value).click() |
---|
| 343 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 344 | self.assertMatches( |
---|
| 345 | '...<span>6000.0</span>...', self.browser.contents) |
---|
| 346 | self.payment_url = self.browser.url |
---|
| 347 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 348 | self.assertEqual(self.student['payments'][value].amount_auth, 6000.0) |
---|
| 349 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 350 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 351 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 352 | |
---|
| 353 | self.app['configuration']['2004'].loss_result_fee = 7000.0 |
---|
| 354 | self.browser.open(self.payments_path + '/addop') |
---|
| 355 | self.browser.getControl(name="form.p_category").value = ['loss_result'] |
---|
| 356 | self.browser.getControl("Create ticket").click() |
---|
| 357 | ctrl = self.browser.getControl(name='val_id') |
---|
| 358 | value = ctrl.options[5] |
---|
| 359 | self.browser.getLink(value).click() |
---|
| 360 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 361 | self.assertMatches( |
---|
| 362 | '...<span>7000.0</span>...', self.browser.contents) |
---|
| 363 | self.payment_url = self.browser.url |
---|
| 364 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 365 | self.assertEqual(self.student['payments'][value].amount_auth, 7000.0) |
---|
| 366 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 367 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 368 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 369 | |
---|
[7970] | 370 | @external_test |
---|
[7930] | 371 | def test_webservice(self): |
---|
[9789] | 372 | # First we have open InterswitchPageStudent to set provider_amt |
---|
| 373 | # and gateway_amt |
---|
| 374 | self.browser.open(self.payment_url + '/goto_interswitch') |
---|
| 375 | # Now we can call the webservice |
---|
[7970] | 376 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 377 | self.assertMatches('...Unsuccessful callback...', |
---|
| 378 | self.browser.contents) |
---|
[9710] | 379 | # The payment is now in state failed ... |
---|
[8266] | 380 | self.assertMatches('...<span>Failed</span>...', |
---|
| 381 | self.browser.contents) |
---|
[9710] | 382 | # ... and the catalog has been updated |
---|
| 383 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 384 | results = list( |
---|
| 385 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 386 | self.assertEqual(len(results), 1) |
---|
| 387 | self.assertEqual(results[0].p_state, 'failed') |
---|
[8266] | 388 | |
---|
[9789] | 389 | # Let's replace the p_id with a valid p_id of the Kwarapoly |
---|
| 390 | # live system. This is definitely not an appropriate |
---|
| 391 | # solution for testing, but we have no choice since |
---|
| 392 | # Interswitch doesn't provide any interface |
---|
| 393 | # for testing. |
---|
| 394 | payment = self.student['payments'][self.value] |
---|
| 395 | payment.p_id = 'p3543612043224' |
---|
[8266] | 396 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[9789] | 397 | self.assertMatches('...Callback amount does not match...', |
---|
[8266] | 398 | self.browser.contents) |
---|
[9789] | 399 | # The payment is now in state failed ... |
---|
[8266] | 400 | self.assertMatches('...<span>Failed</span>...', |
---|
| 401 | self.browser.contents) |
---|
[9789] | 402 | # Let's replace the amount autorized with the amount of the |
---|
| 403 | # live system payment |
---|
| 404 | payment.amount_auth = payment.r_amount_approved |
---|
| 405 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 406 | self.assertMatches('...Successful payment...', |
---|
| 407 | self.browser.contents) |
---|
| 408 | # The payment is now in state paid ... |
---|
| 409 | self.assertMatches('...<span>Paid</span>...', |
---|
| 410 | self.browser.contents) |
---|
| 411 | # ... and the catalog has been updated |
---|
| 412 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 413 | results = list( |
---|
| 414 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
| 415 | self.assertEqual(len(results), 1) |
---|
| 416 | self.assertEqual(results[0].p_state, 'paid') |
---|
| 417 | # Approval is logged in students.log ... |
---|
| 418 | logfile = os.path.join( |
---|
| 419 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 420 | logcontent = open(logfile).read() |
---|
| 421 | self.assertTrue( |
---|
| 422 | 'zope.mgr - ' |
---|
| 423 | 'waeup.kwarapoly.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - ' |
---|
| 424 | 'W1000000 - successful schoolfee payment: p3543612043224\n' |
---|
| 425 | in logcontent) |
---|
| 426 | # ... and in payments.log |
---|
| 427 | logfile = os.path.join( |
---|
| 428 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
| 429 | logcontent = open(logfile).read() |
---|
| 430 | self.assertTrue( |
---|
| 431 | '"zope.mgr",W1000000,p3543612043224,schoolfee,' |
---|
| 432 | '52100.0,00,1200.0,300.0,1800.0,,,\n' |
---|
[10131] | 433 | in logcontent) |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 437 | """Tests for the Interswitch payment gateway. |
---|
| 438 | """ |
---|
| 439 | |
---|
| 440 | layer = FunctionalLayer |
---|
| 441 | |
---|
| 442 | def setUp(self): |
---|
| 443 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 444 | # Create at least one Kwarapoly faculty |
---|
| 445 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 446 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 447 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 448 | self.certificate2.code = u'CERT2' |
---|
[10133] | 449 | self.certificate2.application_category = 'ndft' |
---|
[10131] | 450 | self.certificate2.study_mode = 'nd_ft' |
---|
| 451 | self.certificate2.start_level = 100 |
---|
| 452 | self.certificate2.end_level = 300 |
---|
| 453 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 454 | self.certificate2) |
---|
[10133] | 455 | self.applicantscontainer.application_category = 'ndft' |
---|
[10131] | 456 | self.applicant.applicant_id = u'nd_anything' |
---|
| 457 | |
---|
| 458 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 459 | self.browser.open(self.manage_path) |
---|
| 460 | #IWorkflowState(self.student).setState('started') |
---|
| 461 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
| 462 | self.browser.getControl(name="form.course1").value = ['CERT2'] |
---|
| 463 | self.applicantscontainer.application_fee = 3333.0 |
---|
| 464 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
| 465 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 466 | self.browser.getControl("Save").click() |
---|
| 467 | self.browser.getControl("Add online").click() |
---|
| 468 | self.assertMatches('...ticket created...', |
---|
| 469 | self.browser.contents) |
---|
| 470 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 471 | #value = ctrl.options[0] |
---|
| 472 | #self.browser.getLink(value).click() |
---|
| 473 | self.assertMatches('...Amount Authorized...', |
---|
| 474 | self.browser.contents) |
---|
| 475 | self.assertMatches( |
---|
| 476 | '...<span>3333.0</span>...', |
---|
| 477 | self.browser.contents) |
---|
| 478 | self.payment_url = self.browser.url |
---|
| 479 | |
---|
| 480 | |
---|
| 481 | def test_interswitch_form(self): |
---|
| 482 | |
---|
| 483 | # Manager can access InterswitchForm |
---|
| 484 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 485 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 486 | self.browser.contents) |
---|
| 487 | self.assertTrue( |
---|
| 488 | '<input type="hidden" name="amount" value="333300.0" />' |
---|
| 489 | in self.browser.contents) |
---|
| 490 | self.assertTrue( |
---|
| 491 | '<item_detail item_id="1" item_name="application" ' |
---|
| 492 | 'item_amt="253300" bank_id="8" acct_num="2014191363" />' |
---|
| 493 | in self.browser.contents) |
---|
| 494 | |
---|
[10133] | 495 | # hndft fee goes to another account |
---|
[10131] | 496 | self.applicant.applicant_id = u'hnd_anything' |
---|
| 497 | self.browser.open(self.manage_path) |
---|
| 498 | ctrl = self.browser.getControl(name='val_id') |
---|
| 499 | value = ctrl.options[0] |
---|
| 500 | self.browser.getLink(value).click() |
---|
| 501 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 502 | self.assertTrue( |
---|
| 503 | '<item_detail item_id="1" item_name="application" ' |
---|
[10254] | 504 | 'item_amt="253300" bank_id="9" acct_num="7000016724" />' |
---|
[10131] | 505 | in self.browser.contents) |
---|
[10176] | 506 | # Commission or bribe? |
---|
[10142] | 507 | self.assertTrue( |
---|
[10176] | 508 | '<item_detail item_id="2" item_name="Dalash" item_amt="20000" ' |
---|
| 509 | 'bank_id="117" acct_num="1013196791" />' |
---|
[10142] | 510 | in self.browser.contents) |
---|
[10176] | 511 | self.assertTrue( |
---|
| 512 | '<item_detail item_id="3" item_name="BT Education" ' |
---|
| 513 | 'item_amt="30000" bank_id="117" acct_num="1010764827" />' |
---|
| 514 | in self.browser.contents) |
---|
[10597] | 515 | |
---|
| 516 | # prehndft fee goes to another account |
---|
| 517 | self.applicant.applicant_id = u'prehnd_anything' |
---|
| 518 | self.browser.open(self.manage_path) |
---|
| 519 | ctrl = self.browser.getControl(name='val_id') |
---|
| 520 | value = ctrl.options[0] |
---|
| 521 | self.browser.getLink(value).click() |
---|
| 522 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 523 | self.assertTrue( |
---|
| 524 | '<item_detail item_id="1" item_name="application" ' |
---|
| 525 | 'item_amt="303300" bank_id="8" acct_num="2013910271" />' |
---|
| 526 | in self.browser.contents) |
---|
| 527 | # No 'commission', no provider fee |
---|
| 528 | self.assertFalse('Dalash' in self.browser.contents) |
---|
| 529 | self.assertFalse('BT Education' in self.browser.contents) |
---|
| 530 | |
---|
| 531 | # prejambites fee goes to another account |
---|
| 532 | self.applicant.applicant_id = u'prejambites_anything' |
---|
| 533 | self.browser.open(self.manage_path) |
---|
| 534 | ctrl = self.browser.getControl(name='val_id') |
---|
| 535 | value = ctrl.options[0] |
---|
| 536 | self.browser.getLink(value).click() |
---|
| 537 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 538 | self.assertTrue( |
---|
| 539 | '<item_detail item_id="1" item_name="application" ' |
---|
| 540 | 'item_amt="303300" bank_id="10" acct_num="0106259811" />' |
---|
| 541 | in self.browser.contents) |
---|
| 542 | # No 'commission', no provider fee |
---|
| 543 | self.assertFalse('Dalash' in self.browser.contents) |
---|
| 544 | self.assertFalse('BT Education' in self.browser.contents) |
---|