[7894] | 1 | ## $Id: tests.py 11883 2014-10-28 13:21:10Z 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 |
---|
[10844] | 20 | import pytz |
---|
| 21 | from datetime import datetime, date, timedelta |
---|
[7894] | 22 | from hurry.workflow.interfaces import IWorkflowState |
---|
[9710] | 23 | from zope.component import createObject, getUtility |
---|
| 24 | from zope.catalog.interfaces import ICatalog |
---|
[9387] | 25 | from zope.event import notify |
---|
[10844] | 26 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
[9387] | 27 | from waeup.kofa.university.faculty import Faculty |
---|
| 28 | from waeup.kofa.university.department import Department |
---|
[7894] | 29 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 30 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 31 | from waeup.kofa.configuration import SessionConfiguration |
---|
[9347] | 32 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
[10675] | 33 | from waeup.kwarapoly.students.payments import CustomStudentOnlinePayment |
---|
[7894] | 34 | |
---|
[7970] | 35 | # Also run tests that send requests to external servers? |
---|
| 36 | # If you enable this, please make sure the external services |
---|
| 37 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[11577] | 38 | EXTERNAL_TESTS = False |
---|
[7970] | 39 | |
---|
| 40 | def external_test(func): |
---|
| 41 | if not EXTERNAL_TESTS: |
---|
| 42 | myself = __file__ |
---|
| 43 | if myself.endswith('.pyc'): |
---|
| 44 | myself = myself[:-2] |
---|
| 45 | print "WARNING: external tests are skipped!" |
---|
| 46 | print "WARNING: edit %s to enable them." % myself |
---|
| 47 | return |
---|
| 48 | return func |
---|
| 49 | |
---|
| 50 | |
---|
[8266] | 51 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 52 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 53 | """ |
---|
| 54 | |
---|
| 55 | layer = FunctionalLayer |
---|
| 56 | |
---|
[7970] | 57 | def setUp(self): |
---|
[8266] | 58 | super(InterswitchTestsStudents, self).setUp() |
---|
[9387] | 59 | |
---|
| 60 | # Create at least one Kwarapoly faculty |
---|
| 61 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 62 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 63 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 64 | self.certificate2.code = u'CERT2' |
---|
| 65 | self.certificate2.application_category = 'basic' |
---|
| 66 | self.certificate2.study_mode = 'nd_ft' |
---|
| 67 | self.certificate2.start_level = 100 |
---|
| 68 | self.certificate2.end_level = 300 |
---|
| 69 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 70 | self.certificate2) |
---|
| 71 | # Set study course attributes of test student |
---|
| 72 | self.student['studycourse'].certificate = self.certificate2 |
---|
| 73 | self.student['studycourse'].current_session = 2004 |
---|
| 74 | self.student['studycourse'].entry_session = 2004 |
---|
| 75 | self.student['studycourse'].current_verdict = 'A' |
---|
| 76 | self.student['studycourse'].current_level = 100 |
---|
[9392] | 77 | # Set local lga |
---|
| 78 | self.student.lga = u'kwara_asa' |
---|
[9387] | 79 | # Update the catalog |
---|
| 80 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
| 81 | |
---|
[10675] | 82 | |
---|
| 83 | def test_schoolfee_ticket_creation(self): |
---|
[7970] | 84 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 85 | self.browser.open(self.payments_path) |
---|
[7970] | 86 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 87 | self.browser.open(self.payments_path + '/addop') |
---|
[9737] | 88 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7970] | 89 | self.browser.getControl("Create ticket").click() |
---|
[10675] | 90 | self.assertMatches('...Book and pay for accommodation first...', |
---|
| 91 | self.browser.contents) |
---|
| 92 | # We add a fake maint. payment ticket to meet the condition |
---|
| 93 | maint_payment = CustomStudentOnlinePayment() |
---|
| 94 | self.student['payments']['any_key'] = maint_payment |
---|
| 95 | maint_payment.p_category = 'hostel_maintenance' |
---|
| 96 | maint_payment.p_state = 'unpaid' |
---|
| 97 | maint_payment.p_session = 2004 |
---|
| 98 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 99 | self.browser.getControl("Create ticket").click() |
---|
| 100 | self.assertMatches('...Book and pay for accommodation first...', |
---|
| 101 | self.browser.contents) |
---|
| 102 | # Ticket must be paid |
---|
| 103 | maint_payment.p_state = 'paid' |
---|
| 104 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 105 | self.browser.getControl("Create ticket").click() |
---|
[9436] | 106 | self.assertMatches('...ticket created...', |
---|
| 107 | self.browser.contents) |
---|
| 108 | ctrl = self.browser.getControl(name='val_id') |
---|
[10675] | 109 | self.value = ctrl.options[1] |
---|
[9789] | 110 | self.browser.getLink(self.value).click() |
---|
[9436] | 111 | self.assertMatches('...Amount Authorized...', |
---|
| 112 | self.browser.contents) |
---|
| 113 | self.assertMatches( |
---|
[10672] | 114 | '...<span>39400.0</span>...', |
---|
[9436] | 115 | self.browser.contents) |
---|
| 116 | self.payment_url = self.browser.url |
---|
[7970] | 117 | |
---|
| 118 | |
---|
[8263] | 119 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 120 | # return payment_url + ( |
---|
| 121 | # '/isw_callback?echo=' + |
---|
| 122 | # '&resp=%s' + |
---|
| 123 | # '&desc=Something went wrong' + |
---|
| 124 | # '&txnRef=p1331792385335' + |
---|
| 125 | # '&payRef=' + '&retRef=' + |
---|
| 126 | # '&cardNum=0' + |
---|
| 127 | # '&apprAmt=%s' + |
---|
| 128 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 129 | |
---|
[7970] | 130 | def test_interswitch_form(self): |
---|
[10675] | 131 | |
---|
| 132 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 133 | self.browser.open(self.payments_path) |
---|
| 134 | # In KwaraPoly only returning students can create school fee payment |
---|
| 135 | # without haveing paid accommodation fee |
---|
| 136 | IWorkflowState(self.student).setState('returning') |
---|
| 137 | configuration = createObject('waeup.SessionConfiguration') |
---|
| 138 | configuration.academic_session = 2005 |
---|
| 139 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
| 140 | self.browser.open(self.payments_path + '/addop') |
---|
| 141 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 142 | self.browser.getControl("Create ticket").click() |
---|
| 143 | self.assertMatches('...ticket created...', self.browser.contents) |
---|
| 144 | ctrl = self.browser.getControl(name='val_id') |
---|
| 145 | self.value = ctrl.options[0] |
---|
| 146 | self.browser.getLink(self.value).click() |
---|
| 147 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 148 | self.assertMatches( |
---|
[11865] | 149 | '...<span>30500.0</span>...', |
---|
[10675] | 150 | self.browser.contents) |
---|
| 151 | self.payment_url = self.browser.url |
---|
| 152 | |
---|
[7894] | 153 | # Manager can access InterswitchForm |
---|
[9789] | 154 | self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0) |
---|
| 155 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0) |
---|
| 156 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0) |
---|
[7894] | 157 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 158 | # Split amounts have been set. |
---|
| 159 | self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0) |
---|
| 160 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0) |
---|
| 161 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0) |
---|
[7894] | 162 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 163 | self.browser.contents) |
---|
[9811] | 164 | self.assertTrue( |
---|
[11865] | 165 | '<input type="hidden" name="amount" value="3050000" />' in |
---|
[7894] | 166 | self.browser.contents) |
---|
[9811] | 167 | self.assertTrue( |
---|
[11865] | 168 | 'item_name="School Fee" item_amt="2720000" bank_id="120" acct_num="1771586608"' in |
---|
[9129] | 169 | self.browser.contents) |
---|
[9811] | 170 | self.assertTrue( |
---|
| 171 | 'item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"' in |
---|
[9129] | 172 | self.browser.contents) |
---|
[9811] | 173 | self.assertTrue( |
---|
| 174 | 'item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"' in |
---|
[9129] | 175 | self.browser.contents) |
---|
[7894] | 176 | |
---|
[9616] | 177 | # Let's do the same for maintenance fee payment |
---|
| 178 | |
---|
| 179 | self.browser.open(self.payments_path) |
---|
| 180 | self.browser.open(self.payments_path + '/addop') |
---|
| 181 | self.browser.getControl( |
---|
| 182 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 183 | self.browser.getControl("Create ticket").click() |
---|
| 184 | self.assertMatches('...You have not yet booked accommodation...', |
---|
| 185 | self.browser.contents) |
---|
| 186 | # Students have to book bed first |
---|
| 187 | self.browser.open(self.acco_path) |
---|
| 188 | IWorkflowState(self.student).setState('admitted') |
---|
| 189 | self.browser.getLink("Book accommodation").click() |
---|
| 190 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
| 191 | self.browser.getControl("Create bed ticket").click() |
---|
| 192 | # Bed is randomly selected but, since there is only |
---|
| 193 | # one bed for this student, we know that ... |
---|
| 194 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
| 195 | self.browser.contents) |
---|
| 196 | self.assertMatches('...ticket created...', |
---|
| 197 | self.browser.contents) |
---|
| 198 | self.browser.open(self.payments_path + '/addop') |
---|
| 199 | self.browser.getControl( |
---|
| 200 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 201 | self.browser.getControl("Create ticket").click() |
---|
| 202 | self.assertMatches('...ticket created...', |
---|
| 203 | self.browser.contents) |
---|
| 204 | ctrl = self.browser.getControl(name='val_id') |
---|
| 205 | value = ctrl.options[1] |
---|
| 206 | self.browser.getLink(value).click() |
---|
| 207 | self.assertMatches('...Amount Authorized...', |
---|
| 208 | self.browser.contents) |
---|
[10682] | 209 | # Maint fee is taken from the hostel object |
---|
[9616] | 210 | self.assertMatches( |
---|
[10682] | 211 | '...<span>876.0</span>...', |
---|
[9616] | 212 | self.browser.contents) |
---|
| 213 | self.payment_url = self.browser.url |
---|
| 214 | # Manager can access InterswitchForm |
---|
| 215 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 216 | # Split amounts have been set. |
---|
| 217 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
| 218 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0) |
---|
| 219 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
[9616] | 220 | # The total amount to be processed by Interswitch |
---|
| 221 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 222 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 223 | self.browser.contents) |
---|
| 224 | self.assertMatches( |
---|
[9626] | 225 | '...<input type="hidden" name="pay_item_id" value="102" />...', |
---|
| 226 | self.browser.contents) |
---|
| 227 | self.assertMatches( |
---|
[11791] | 228 | '...<input type="hidden" name="amount" value="87600" />...', |
---|
[9616] | 229 | self.browser.contents) |
---|
| 230 | self.assertMatches( |
---|
[10682] | 231 | '...item_name="Hostel Maintenance Fee" item_amt="57600" bank_id="31" acct_num="0039050937"...', |
---|
[9616] | 232 | self.browser.contents) |
---|
| 233 | |
---|
[9737] | 234 | # Create carryover ticket |
---|
| 235 | self.browser.open(self.payments_path + '/addop') |
---|
| 236 | self.browser.getControl(name="form.p_category").value = ['carryover1'] |
---|
| 237 | self.browser.getControl("Create ticket").click() |
---|
| 238 | ctrl = self.browser.getControl(name='val_id') |
---|
| 239 | value = ctrl.options[2] |
---|
| 240 | self.browser.getLink(value).click() |
---|
| 241 | self.assertMatches( |
---|
| 242 | '...<span>6000.0</span>...', |
---|
| 243 | self.browser.contents) |
---|
| 244 | # Manager can access InterswitchForm |
---|
| 245 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9789] | 246 | # Split amounts have been set. |
---|
| 247 | self.assertEqual(self.student['payments'][self.value].provider_amt, 1200.0) |
---|
| 248 | self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0) |
---|
| 249 | self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1800.0) |
---|
[9737] | 250 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="101" />...', |
---|
| 251 | self.browser.contents) |
---|
| 252 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 253 | self.browser.contents) |
---|
| 254 | self.assertMatches( |
---|
[11791] | 255 | '...<input type="hidden" name="amount" value="600000" />...', |
---|
[9737] | 256 | self.browser.contents) |
---|
| 257 | self.assertMatches( |
---|
[11760] | 258 | '...item_name="School Fee" item_amt="270000" bank_id="120" acct_num="1771586608"...', |
---|
[9737] | 259 | self.browser.contents) |
---|
| 260 | self.assertMatches( |
---|
| 261 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
| 262 | self.browser.contents) |
---|
| 263 | self.assertMatches( |
---|
| 264 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
| 265 | self.browser.contents) |
---|
| 266 | |
---|
[10736] | 267 | def test_interswitch_form_new_payment_cats(self): |
---|
| 268 | # only a few categories covered |
---|
| 269 | |
---|
| 270 | self.app['configuration']['2004'].certificate_fee = 6800.0 |
---|
| 271 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 272 | self.browser.open(self.payments_path + '/addop') |
---|
| 273 | self.browser.getControl(name="form.p_category").value = ['certificate'] |
---|
| 274 | self.browser.getControl("Create ticket").click() |
---|
| 275 | self.assertMatches('...ticket created...', self.browser.contents) |
---|
| 276 | ctrl = self.browser.getControl(name='val_id') |
---|
| 277 | value = ctrl.options[0] |
---|
| 278 | self.browser.getLink(value).click() |
---|
| 279 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 280 | self.assertMatches( |
---|
| 281 | '...<span>6800.0</span>...', self.browser.contents) |
---|
| 282 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 283 | self.assertEqual(self.student['payments'][value].amount_auth, 6800.0) |
---|
| 284 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 285 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 286 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 287 | |
---|
| 288 | self.app['configuration']['2004'].transcript_local_fee = 5000.0 |
---|
| 289 | self.browser.open(self.payments_path + '/addop') |
---|
| 290 | self.browser.getControl(name="form.p_category").value = ['transcript_local'] |
---|
| 291 | self.browser.getControl("Create ticket").click() |
---|
| 292 | ctrl = self.browser.getControl(name='val_id') |
---|
| 293 | value = ctrl.options[1] |
---|
| 294 | self.browser.getLink(value).click() |
---|
| 295 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 296 | self.assertMatches( |
---|
| 297 | '...<span>5000.0</span>...', self.browser.contents) |
---|
| 298 | self.payment_url = self.browser.url |
---|
| 299 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 300 | self.assertEqual(self.student['payments'][value].amount_auth, 5000.0) |
---|
| 301 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 302 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 303 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 304 | |
---|
[11768] | 305 | self.app['configuration']['2004'].loss_idcard_fee = 1015.0 |
---|
[10736] | 306 | self.browser.open(self.payments_path + '/addop') |
---|
| 307 | self.browser.getControl(name="form.p_category").value = ['loss_idcard'] |
---|
| 308 | self.browser.getControl("Create ticket").click() |
---|
| 309 | ctrl = self.browser.getControl(name='val_id') |
---|
| 310 | value = ctrl.options[2] |
---|
| 311 | self.browser.getLink(value).click() |
---|
| 312 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 313 | self.assertMatches( |
---|
[11768] | 314 | '...<span>1015.0</span>...', self.browser.contents) |
---|
[10736] | 315 | self.payment_url = self.browser.url |
---|
| 316 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[11768] | 317 | self.assertEqual(self.student['payments'][value].amount_auth, 1015.0) |
---|
[10736] | 318 | self.assertEqual(self.student['payments'][value].provider_amt, 9.0) |
---|
[11768] | 319 | self.assertEqual(self.student['payments'][value].gateway_amt, 15.22) |
---|
[10736] | 320 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 6.0) |
---|
| 321 | |
---|
| 322 | self.app['configuration']['2004'].loss_examcard_fee = 500.0 |
---|
| 323 | self.browser.open(self.payments_path + '/addop') |
---|
| 324 | self.browser.getControl(name="form.p_category").value = ['loss_examcard'] |
---|
| 325 | self.browser.getControl("Create ticket").click() |
---|
| 326 | ctrl = self.browser.getControl(name='val_id') |
---|
| 327 | value = ctrl.options[3] |
---|
| 328 | self.browser.getLink(value).click() |
---|
| 329 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 330 | self.assertMatches( |
---|
| 331 | '...<span>500.0</span>...', self.browser.contents) |
---|
| 332 | self.payment_url = self.browser.url |
---|
| 333 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 334 | self.assertEqual(self.student['payments'][value].amount_auth, 500.0) |
---|
| 335 | self.assertEqual(self.student['payments'][value].provider_amt, 4.5) |
---|
| 336 | self.assertEqual(self.student['payments'][value].gateway_amt, 7.5) |
---|
| 337 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 3) |
---|
| 338 | |
---|
| 339 | self.app['configuration']['2004'].change_inst_fee = 6000.0 |
---|
| 340 | self.browser.open(self.payments_path + '/addop') |
---|
| 341 | self.browser.getControl(name="form.p_category").value = ['change_inst'] |
---|
| 342 | self.browser.getControl("Create ticket").click() |
---|
| 343 | ctrl = self.browser.getControl(name='val_id') |
---|
| 344 | value = ctrl.options[4] |
---|
| 345 | self.browser.getLink(value).click() |
---|
| 346 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 347 | self.assertMatches( |
---|
| 348 | '...<span>6000.0</span>...', self.browser.contents) |
---|
| 349 | self.payment_url = self.browser.url |
---|
| 350 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 351 | self.assertEqual(self.student['payments'][value].amount_auth, 6000.0) |
---|
| 352 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 353 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 354 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 355 | |
---|
| 356 | self.app['configuration']['2004'].loss_result_fee = 7000.0 |
---|
| 357 | self.browser.open(self.payments_path + '/addop') |
---|
| 358 | self.browser.getControl(name="form.p_category").value = ['loss_result'] |
---|
| 359 | self.browser.getControl("Create ticket").click() |
---|
| 360 | ctrl = self.browser.getControl(name='val_id') |
---|
| 361 | value = ctrl.options[5] |
---|
| 362 | self.browser.getLink(value).click() |
---|
| 363 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 364 | self.assertMatches( |
---|
| 365 | '...<span>7000.0</span>...', self.browser.contents) |
---|
| 366 | self.payment_url = self.browser.url |
---|
| 367 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 368 | self.assertEqual(self.student['payments'][value].amount_auth, 7000.0) |
---|
| 369 | self.assertEqual(self.student['payments'][value].provider_amt, 300.0) |
---|
| 370 | self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) |
---|
| 371 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 200.0) |
---|
| 372 | |
---|
[11768] | 373 | self.app['configuration']['2004'].loss_idcard_fee = 1900.0 |
---|
[11682] | 374 | self.browser.open(self.payments_path + '/addop') |
---|
| 375 | self.browser.getControl(name="form.p_category").value = ['loss_idcard'] |
---|
| 376 | self.browser.getControl("Create ticket").click() |
---|
| 377 | ctrl = self.browser.getControl(name='val_id') |
---|
| 378 | value = ctrl.options[6] |
---|
| 379 | self.browser.getLink(value).click() |
---|
| 380 | self.assertMatches('...Amount Authorized...', self.browser.contents) |
---|
| 381 | self.assertMatches( |
---|
[11768] | 382 | '...<span>1900.0</span>...', self.browser.contents) |
---|
[11682] | 383 | self.payment_url = self.browser.url |
---|
| 384 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[11768] | 385 | self.assertEqual(self.student['payments'][value].amount_auth, 1900.0) |
---|
[11682] | 386 | self.assertEqual(self.student['payments'][value].provider_amt, 9.0) |
---|
[11768] | 387 | self.assertEqual(self.student['payments'][value].gateway_amt, 28.5) |
---|
[11682] | 388 | self.assertEqual(self.student['payments'][value].thirdparty_amt, 6.0) |
---|
| 389 | |
---|
| 390 | |
---|
[7970] | 391 | @external_test |
---|
[7930] | 392 | def test_webservice(self): |
---|
[11574] | 393 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 394 | IWorkflowState(self.student).setState('cleared') |
---|
| 395 | # We add a fake maint. payment ticket to meet the condition |
---|
| 396 | maint_payment = CustomStudentOnlinePayment() |
---|
| 397 | self.student['payments']['any_key'] = maint_payment |
---|
| 398 | maint_payment.p_category = 'hostel_maintenance' |
---|
| 399 | maint_payment.p_state = 'paid' |
---|
| 400 | maint_payment.p_session = 2004 |
---|
| 401 | # We create the school fee payment ticket |
---|
| 402 | self.browser.open(self.payments_path + '/addop') |
---|
| 403 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 404 | self.browser.getControl("Create ticket").click() |
---|
| 405 | self.assertMatches('...ticket created...', |
---|
| 406 | self.browser.contents) |
---|
| 407 | ctrl = self.browser.getControl(name='val_id') |
---|
| 408 | self.value = ctrl.options[1] |
---|
| 409 | self.browser.getLink(self.value).click() |
---|
| 410 | self.payment_url = self.browser.url |
---|
[9789] | 411 | # First we have open InterswitchPageStudent to set provider_amt |
---|
| 412 | # and gateway_amt |
---|
| 413 | self.browser.open(self.payment_url + '/goto_interswitch') |
---|
| 414 | # Now we can call the webservice |
---|
[7970] | 415 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 416 | self.assertMatches('...Unsuccessful callback...', |
---|
| 417 | self.browser.contents) |
---|
[9710] | 418 | # The payment is now in state failed ... |
---|
[8266] | 419 | self.assertMatches('...<span>Failed</span>...', |
---|
| 420 | self.browser.contents) |
---|
[9710] | 421 | # ... and the catalog has been updated |
---|
| 422 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 423 | results = list( |
---|
| 424 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 425 | self.assertEqual(len(results), 1) |
---|
| 426 | self.assertEqual(results[0].p_state, 'failed') |
---|
[8266] | 427 | |
---|
[9789] | 428 | # Let's replace the p_id with a valid p_id of the Kwarapoly |
---|
| 429 | # live system. This is definitely not an appropriate |
---|
| 430 | # solution for testing, but we have no choice since |
---|
| 431 | # Interswitch doesn't provide any interface |
---|
| 432 | # for testing. |
---|
| 433 | payment = self.student['payments'][self.value] |
---|
| 434 | payment.p_id = 'p3543612043224' |
---|
[8266] | 435 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[9789] | 436 | self.assertMatches('...Callback amount does not match...', |
---|
[8266] | 437 | self.browser.contents) |
---|
[9789] | 438 | # The payment is now in state failed ... |
---|
[8266] | 439 | self.assertMatches('...<span>Failed</span>...', |
---|
| 440 | self.browser.contents) |
---|
[9789] | 441 | # Let's replace the amount autorized with the amount of the |
---|
| 442 | # live system payment |
---|
| 443 | payment.amount_auth = payment.r_amount_approved |
---|
| 444 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 445 | self.assertMatches('...Successful payment...', |
---|
| 446 | self.browser.contents) |
---|
| 447 | # The payment is now in state paid ... |
---|
| 448 | self.assertMatches('...<span>Paid</span>...', |
---|
| 449 | self.browser.contents) |
---|
| 450 | # ... and the catalog has been updated |
---|
| 451 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 452 | results = list( |
---|
| 453 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
| 454 | self.assertEqual(len(results), 1) |
---|
| 455 | self.assertEqual(results[0].p_state, 'paid') |
---|
| 456 | # Approval is logged in students.log ... |
---|
| 457 | logfile = os.path.join( |
---|
| 458 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 459 | logcontent = open(logfile).read() |
---|
| 460 | self.assertTrue( |
---|
| 461 | 'zope.mgr - ' |
---|
[11636] | 462 | 'waeup.kwarapoly.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - ' |
---|
[9789] | 463 | 'W1000000 - successful schoolfee payment: p3543612043224\n' |
---|
| 464 | in logcontent) |
---|
| 465 | # ... and in payments.log |
---|
| 466 | logfile = os.path.join( |
---|
| 467 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
| 468 | logcontent = open(logfile).read() |
---|
| 469 | self.assertTrue( |
---|
| 470 | '"zope.mgr",W1000000,p3543612043224,schoolfee,' |
---|
| 471 | '52100.0,00,1200.0,300.0,1800.0,,,\n' |
---|
[10131] | 472 | in logcontent) |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 476 | """Tests for the Interswitch payment gateway. |
---|
| 477 | """ |
---|
| 478 | |
---|
| 479 | layer = FunctionalLayer |
---|
| 480 | |
---|
| 481 | def setUp(self): |
---|
| 482 | super(InterswitchTestsApplicants, self).setUp() |
---|
[10837] | 483 | configuration = SessionConfiguration() |
---|
| 484 | configuration.academic_session = datetime.now().year - 2 |
---|
| 485 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[10844] | 486 | self.configuration = configuration |
---|
[10131] | 487 | # Create at least one Kwarapoly faculty |
---|
| 488 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 489 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 490 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 491 | self.certificate2.code = u'CERT2' |
---|
[10133] | 492 | self.certificate2.application_category = 'ndft' |
---|
[10131] | 493 | self.certificate2.study_mode = 'nd_ft' |
---|
| 494 | self.certificate2.start_level = 100 |
---|
| 495 | self.certificate2.end_level = 300 |
---|
| 496 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 497 | self.certificate2) |
---|
[10133] | 498 | self.applicantscontainer.application_category = 'ndft' |
---|
[10131] | 499 | self.applicant.applicant_id = u'nd_anything' |
---|
| 500 | |
---|
| 501 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 502 | self.browser.open(self.manage_path) |
---|
| 503 | #IWorkflowState(self.student).setState('started') |
---|
| 504 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
| 505 | self.browser.getControl(name="form.course1").value = ['CERT2'] |
---|
| 506 | self.applicantscontainer.application_fee = 3333.0 |
---|
| 507 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
| 508 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 509 | self.browser.getControl("Save").click() |
---|
| 510 | self.browser.getControl("Add online").click() |
---|
| 511 | self.assertMatches('...ticket created...', |
---|
| 512 | self.browser.contents) |
---|
| 513 | self.assertMatches('...Amount Authorized...', |
---|
| 514 | self.browser.contents) |
---|
| 515 | self.assertMatches( |
---|
| 516 | '...<span>3333.0</span>...', |
---|
| 517 | self.browser.contents) |
---|
| 518 | self.payment_url = self.browser.url |
---|
| 519 | |
---|
| 520 | |
---|
| 521 | def test_interswitch_form(self): |
---|
| 522 | |
---|
| 523 | # Manager can access InterswitchForm |
---|
| 524 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 525 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 526 | self.browser.contents) |
---|
| 527 | self.assertTrue( |
---|
[11791] | 528 | '<input type="hidden" name="amount" value="333300" />' |
---|
[10131] | 529 | in self.browser.contents) |
---|
| 530 | self.assertTrue( |
---|
[11682] | 531 | '<item_detail item_id="1" item_name="Application Fee" ' |
---|
[11677] | 532 | 'item_amt="253300" bank_id="120" acct_num="1771440667" />' |
---|
[10131] | 533 | in self.browser.contents) |
---|
| 534 | |
---|
[11677] | 535 | # Meanwhile hndft fee goes to same account |
---|
[10131] | 536 | self.applicant.applicant_id = u'hnd_anything' |
---|
| 537 | self.browser.open(self.manage_path) |
---|
| 538 | ctrl = self.browser.getControl(name='val_id') |
---|
| 539 | value = ctrl.options[0] |
---|
| 540 | self.browser.getLink(value).click() |
---|
| 541 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 542 | self.assertTrue( |
---|
[11682] | 543 | '<item_detail item_id="1" item_name="Application Fee" ' |
---|
[11677] | 544 | 'item_amt="253300" bank_id="120" acct_num="1771440667" />' |
---|
[10131] | 545 | in self.browser.contents) |
---|
[10176] | 546 | # Commission or bribe? |
---|
[10142] | 547 | self.assertTrue( |
---|
[10176] | 548 | '<item_detail item_id="2" item_name="Dalash" item_amt="20000" ' |
---|
| 549 | 'bank_id="117" acct_num="1013196791" />' |
---|
[10142] | 550 | in self.browser.contents) |
---|
[10176] | 551 | self.assertTrue( |
---|
| 552 | '<item_detail item_id="3" item_name="BT Education" ' |
---|
| 553 | 'item_amt="30000" bank_id="117" acct_num="1010764827" />' |
---|
| 554 | in self.browser.contents) |
---|
[10597] | 555 | |
---|
| 556 | # prehndft fee goes to another account |
---|
| 557 | self.applicant.applicant_id = u'prehnd_anything' |
---|
| 558 | self.browser.open(self.manage_path) |
---|
| 559 | ctrl = self.browser.getControl(name='val_id') |
---|
| 560 | value = ctrl.options[0] |
---|
| 561 | self.browser.getLink(value).click() |
---|
| 562 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 563 | self.assertTrue( |
---|
[11682] | 564 | '<item_detail item_id="1" item_name="Application Fee" ' |
---|
[11797] | 565 | 'item_amt="253300" bank_id="10" acct_num="0106259811" />' |
---|
[10597] | 566 | in self.browser.contents) |
---|
[11793] | 567 | # No 'commission', no provider fee in 2013 |
---|
| 568 | #self.assertFalse('Dalash' in self.browser.contents) |
---|
| 569 | #self.assertFalse('BT Education' in self.browser.contents) |
---|
| 570 | # Comission is charged from 14/09/2014 |
---|
| 571 | self.assertTrue( |
---|
[11797] | 572 | '<item_detail item_id="2" item_name="Dalash" item_amt="20000" ' |
---|
[11793] | 573 | 'bank_id="117" acct_num="1013196791" />' |
---|
| 574 | in self.browser.contents) |
---|
| 575 | self.assertTrue( |
---|
| 576 | '<item_detail item_id="3" item_name="BT Education" ' |
---|
[11797] | 577 | 'item_amt="30000" bank_id="117" acct_num="1010764827" />' |
---|
[11793] | 578 | in self.browser.contents) |
---|
[10597] | 579 | |
---|
| 580 | # prejambites fee goes to another account |
---|
| 581 | self.applicant.applicant_id = u'prejambites_anything' |
---|
| 582 | self.browser.open(self.manage_path) |
---|
| 583 | ctrl = self.browser.getControl(name='val_id') |
---|
| 584 | value = ctrl.options[0] |
---|
| 585 | self.browser.getLink(value).click() |
---|
| 586 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 587 | self.assertTrue( |
---|
[11682] | 588 | '<item_detail item_id="1" item_name="Application Fee" ' |
---|
[11797] | 589 | 'item_amt="253300" bank_id="8" acct_num="2013910271" />' |
---|
[10597] | 590 | in self.browser.contents) |
---|
[11793] | 591 | # No 'commission', no provider fee in 2013 |
---|
| 592 | #self.assertFalse('Dalash' in self.browser.contents) |
---|
| 593 | #self.assertFalse('BT Education' in self.browser.contents) |
---|
| 594 | # Comission is charged from 14/09/2014 |
---|
| 595 | self.assertTrue( |
---|
[11797] | 596 | '<item_detail item_id="2" item_name="Dalash" item_amt="20000" ' |
---|
[11793] | 597 | 'bank_id="117" acct_num="1013196791" />' |
---|
| 598 | in self.browser.contents) |
---|
| 599 | self.assertTrue( |
---|
| 600 | '<item_detail item_id="3" item_name="BT Education" ' |
---|
[11797] | 601 | 'item_amt="30000" bank_id="117" acct_num="1010764827" />' |
---|
[11793] | 602 | in self.browser.contents) |
---|
[11796] | 603 | self.assertTrue( |
---|
| 604 | '<input type="hidden" name="pay_item_id" value="104" />' |
---|
| 605 | in self.browser.contents) |
---|
[10844] | 606 | |
---|
[11883] | 607 | # putme goes into the prejambites account |
---|
| 608 | self.applicant.applicant_id = u'putme_anything' |
---|
| 609 | self.browser.open(self.manage_path) |
---|
| 610 | ctrl = self.browser.getControl(name='val_id') |
---|
| 611 | value = ctrl.options[0] |
---|
| 612 | self.browser.getLink(value).click() |
---|
| 613 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 614 | self.assertTrue( |
---|
| 615 | '<item_detail item_id="1" item_name="Application Fee" ' |
---|
| 616 | 'item_amt="253300" bank_id="8" acct_num="2013910271" />' |
---|
| 617 | in self.browser.contents) |
---|
| 618 | self.assertTrue( |
---|
| 619 | '<item_detail item_id="2" item_name="Dalash" item_amt="20000" ' |
---|
| 620 | 'bank_id="117" acct_num="1013196791" />' |
---|
| 621 | in self.browser.contents) |
---|
| 622 | self.assertTrue( |
---|
| 623 | '<item_detail item_id="3" item_name="BT Education" ' |
---|
| 624 | 'item_amt="30000" bank_id="117" acct_num="1010764827" />' |
---|
| 625 | in self.browser.contents) |
---|
| 626 | self.assertTrue( |
---|
| 627 | '<input type="hidden" name="pay_item_id" value="104" />' |
---|
| 628 | in self.browser.contents) |
---|
[10844] | 629 | |
---|
| 630 | def prepare_special_container(self): |
---|
| 631 | # Add special application container |
---|
| 632 | container_name = u'special%s' % (datetime.now().year - 2) |
---|
| 633 | applicantscontainer = ApplicantsContainer() |
---|
| 634 | applicantscontainer.code = container_name |
---|
| 635 | applicantscontainer.prefix = 'special' |
---|
| 636 | applicantscontainer.year = datetime.now().year - 2 |
---|
| 637 | applicantscontainer.title = u'This is a special app container' |
---|
| 638 | applicantscontainer.application_category = 'no' |
---|
| 639 | applicantscontainer.mode = 'create' |
---|
| 640 | delta = timedelta(days=10) |
---|
| 641 | applicantscontainer.startdate = datetime.now(pytz.utc) - delta |
---|
| 642 | applicantscontainer.enddate = datetime.now(pytz.utc) + delta |
---|
| 643 | applicantscontainer.strict_deadline = True |
---|
| 644 | self.app['applicants'][container_name] = applicantscontainer |
---|
| 645 | # Add an applicant |
---|
| 646 | applicant = createObject('waeup.Applicant') |
---|
| 647 | # reg_number is the only field which has to be preset here |
---|
| 648 | # because managers are allowed to edit this required field |
---|
| 649 | applicant.reg_number = u'12345' |
---|
| 650 | applicant.firstname = u'Vorname' |
---|
| 651 | applicant.lastname = u'Nachname' |
---|
[10847] | 652 | applicant.email = 'aa@aa.aa' |
---|
[10844] | 653 | applicant.special_application = u'transcript_local' |
---|
| 654 | applicant.applicant_id = u'special_anything' |
---|
| 655 | self.app['applicants'][container_name].addApplicant(applicant) |
---|
| 656 | self.special_applicant = applicant |
---|
| 657 | self.configuration.transcript_local_fee = 5300.0 |
---|
| 658 | self.special_manage_path = 'http://localhost/app/applicants/%s/%s/%s' % ( |
---|
| 659 | container_name, applicant.application_number, 'manage') |
---|
| 660 | |
---|
| 661 | def test_interswitch_form_special(self): |
---|
| 662 | self.prepare_special_container() |
---|
| 663 | self.browser.open(self.special_manage_path) |
---|
| 664 | self.browser.getControl("Add online").click() |
---|
| 665 | self.assertMatches('...ticket created...', |
---|
| 666 | self.browser.contents) |
---|
| 667 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 668 | self.assertTrue( |
---|
[11682] | 669 | '<item_detail item_id="1" item_name="ND Transcript (local)" ' |
---|
[11557] | 670 | 'item_amt="450000" bank_id="9" acct_num="7000016724" />' |
---|
[10844] | 671 | in self.browser.contents) |
---|
[11574] | 672 | |
---|
[11769] | 673 | self.special_applicant.special_application = u'log_book' |
---|
| 674 | self.configuration.log_book_fee = 570.5 |
---|
| 675 | self.browser.open(self.special_manage_path) |
---|
| 676 | self.browser.getControl("Add online").click() |
---|
| 677 | self.assertMatches('...ticket created...', |
---|
| 678 | self.browser.contents) |
---|
| 679 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 680 | # The university gets 570.5 - (1.5% x 570.5) - 3 - 4.5 |
---|
| 681 | self.assertTrue( |
---|
| 682 | '<item_detail item_id="1" item_name="Log Book Fees" ' |
---|
| 683 | 'item_amt="55444" bank_id="117" acct_num="1010508401" />' |
---|
| 684 | in self.browser.contents) |
---|
| 685 | |
---|
| 686 | |
---|
[11574] | 687 | @external_test |
---|
| 688 | def test_webservice(self): |
---|
[11577] | 689 | self.prepare_special_container() |
---|
[11636] | 690 | IWorkflowState(self.special_applicant).setState('started') |
---|
[11577] | 691 | self.browser.open(self.special_manage_path) |
---|
| 692 | self.browser.getControl("Add online").click() |
---|
| 693 | payment_url = self.browser.url |
---|
| 694 | self.browser.open(payment_url + '/request_webservice') |
---|
[11574] | 695 | self.assertMatches('...Unsuccessful callback...', |
---|
| 696 | self.browser.contents) |
---|
| 697 | # The payment is now in state failed |
---|
| 698 | self.assertMatches('...<span>Failed</span>...', |
---|
| 699 | self.browser.contents) |
---|
| 700 | # Let's replace the p_id with a valid p_id of the Kwarapoly |
---|
| 701 | # live system. This is definitely not an appropriate |
---|
| 702 | # solution for testing, but we have no choice since |
---|
| 703 | # Interswitch doesn't provide any interface |
---|
| 704 | # for testing. |
---|
[11577] | 705 | p_id = self.special_applicant.keys()[0] |
---|
| 706 | payment = self.special_applicant[p_id] |
---|
[11574] | 707 | payment.p_id = 'p3543612043224' |
---|
[11577] | 708 | self.browser.open(payment_url + '/request_webservice') |
---|
[11574] | 709 | self.assertMatches('...Callback amount does not match...', |
---|
| 710 | self.browser.contents) |
---|
| 711 | payment.amount_auth = payment.r_amount_approved |
---|
| 712 | |
---|
[11577] | 713 | self.browser.open(payment_url + '/request_webservice') |
---|
[11574] | 714 | self.assertMatches('...Successful payment...', |
---|
| 715 | self.browser.contents) |
---|
| 716 | # The payment is now in state paid ... |
---|
| 717 | self.assertMatches('...<span>Paid</span>...', |
---|
| 718 | self.browser.contents) |
---|
| 719 | # ... and the catalog has been updated |
---|
| 720 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 721 | results = list( |
---|
| 722 | cat.searchResults(p_state=('paid', 'paid'))) |
---|
| 723 | self.assertEqual(len(results), 1) |
---|
| 724 | self.assertEqual(results[0].p_state, 'paid') |
---|
| 725 | # Approval is logged in applicants.log ... |
---|
| 726 | logfile = os.path.join( |
---|
| 727 | self.app['datacenter'].storage, 'logs', 'applicants.log') |
---|
| 728 | logcontent = open(logfile).read() |
---|
| 729 | self.assertTrue( |
---|
[11636] | 730 | 'zope.mgr - waeup.kwarapoly.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageApplicant' |
---|
[11577] | 731 | ' - special_anything - successful payment: p3543612043224\n' |
---|
[11574] | 732 | in logcontent) |
---|
| 733 | # ... and in payments.log |
---|
| 734 | logfile = os.path.join( |
---|
| 735 | self.app['datacenter'].storage, 'logs', 'payments.log') |
---|
| 736 | logcontent = open(logfile).read() |
---|
| 737 | self.assertTrue( |
---|
[11577] | 738 | '"zope.mgr",special_anything,p3543612043224,transcript_local,52100.0,' |
---|
[11574] | 739 | '00,0.0,0.0,0.0,,,\n' |
---|
| 740 | in logcontent) |
---|
[11577] | 741 | self.assertEqual(self.applicant.state, 'started') |
---|
| 742 | # Special Payment applicant can add new payment |
---|
| 743 | self.browser.open(self.edit_path) |
---|
| 744 | self.assertTrue('Add online payment ticket' in self.browser.contents) |
---|