[7929] | 1 | ## $Id: tests.py 15455 2019-06-15 12:30:51Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | from hurry.workflow.interfaces import IWorkflowState |
---|
[15455] | 19 | from zope.component import createObject, getUtility |
---|
[7929] | 20 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[12429] | 21 | from waeup.kofa.applicants.tests.test_browser import ( |
---|
| 22 | ApplicantsFullSetup, session_1) |
---|
[8267] | 23 | from waeup.kofa.configuration import SessionConfiguration |
---|
[8444] | 24 | from waeup.aaue.testing import FunctionalLayer |
---|
[10978] | 25 | from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2 |
---|
[7929] | 26 | |
---|
[7970] | 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. |
---|
[8271] | 31 | EXTERNAL_TESTS = False |
---|
[7970] | 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 | |
---|
[8267] | 43 | class EtranzactTestsStudent(StudentsFullSetup): |
---|
[7976] | 44 | """Tests for the eTranzact payment gateway. |
---|
[7929] | 45 | """ |
---|
| 46 | |
---|
| 47 | layer = FunctionalLayer |
---|
| 48 | |
---|
| 49 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 50 | |
---|
[7976] | 51 | def setUp(self): |
---|
[8267] | 52 | super(EtranzactTestsStudent, self).setUp() |
---|
[7929] | 53 | # Managers can add online payment tickets |
---|
| 54 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[13374] | 55 | self.student['studycourse'].certificate.school_fee_1 = 1234.0 |
---|
[7995] | 56 | self.browser.open(self.payments_path) |
---|
[7929] | 57 | IWorkflowState(self.student).setState('cleared') |
---|
[13374] | 58 | self.student.nationality = u'NG' |
---|
[7995] | 59 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 60 | self.browser.getControl(name="form.p_category").value = ['clearance_incl'] |
---|
[11622] | 61 | self.browser.getControl("Create ticket").click() |
---|
| 62 | self.assertMatches('...ticket created...', |
---|
| 63 | self.browser.contents) |
---|
| 64 | ctrl = self.browser.getControl(name='val_id') |
---|
[12975] | 65 | value1 = ctrl.options[0] |
---|
[11622] | 66 | |
---|
| 67 | self.browser.open(self.payments_path + '/addop') |
---|
[13421] | 68 | self.browser.getControl(name="form.p_category").value = ['schoolfee_incl'] |
---|
[7929] | 69 | self.browser.getControl("Create ticket").click() |
---|
| 70 | self.assertMatches('...ticket created...', |
---|
| 71 | self.browser.contents) |
---|
| 72 | ctrl = self.browser.getControl(name='val_id') |
---|
[12975] | 73 | value2 = ctrl.options[1] |
---|
| 74 | self.p_id = value2 |
---|
[13784] | 75 | self.payment = self.student['payments'][value2] |
---|
[12975] | 76 | self.browser.getLink(value2).click() |
---|
[7929] | 77 | self.assertMatches('...Amount Authorized...', |
---|
| 78 | self.browser.contents) |
---|
[7976] | 79 | self.payment_url = self.browser.url |
---|
| 80 | |
---|
| 81 | def test_enterpin(self): |
---|
[12975] | 82 | self.student['studycourse'].entry_session = 2013 |
---|
| 83 | self.browser.open(self.payment_url) |
---|
[7976] | 84 | self.browser.getLink("Query eTranzact History").click() |
---|
[12975] | 85 | self.assertTrue( |
---|
| 86 | 'Please pay acceptance fee firs' in self.browser.contents) |
---|
| 87 | self.assertFalse( |
---|
| 88 | 'Confirmation Number (PIN)' in self.browser.contents) |
---|
| 89 | self.student['payments'].values()[0].approve() |
---|
| 90 | self.browser.getLink("Query eTranzact History").click() |
---|
| 91 | self.assertFalse( |
---|
| 92 | 'Please pay acceptance fee firs' in self.browser.contents) |
---|
| 93 | self.assertTrue( |
---|
| 94 | 'Confirmation Number (PIN)' in self.browser.contents) |
---|
[7976] | 95 | |
---|
[8731] | 96 | def test_webservice(self): |
---|
[10937] | 97 | self.browser.open( |
---|
[13784] | 98 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-NEW' |
---|
[10937] | 99 | % self.p_id) |
---|
[15346] | 100 | |
---|
| 101 | # webservice disabled on 6/3/19 |
---|
| 102 | self.assertEqual(self.browser.contents, '') |
---|
| 103 | return |
---|
| 104 | |
---|
[8731] | 105 | self.assertEqual(self.browser.contents, |
---|
[13963] | 106 | 'PayeeName=TESTER, Anna~' |
---|
[10907] | 107 | 'Faculty=fac1~' |
---|
| 108 | 'Department=dep1~' |
---|
| 109 | 'Level=100~' |
---|
| 110 | 'ProgrammeType=CERT1~' |
---|
| 111 | 'StudyType=ug_ft~' |
---|
| 112 | 'Session=2004/2005~' |
---|
| 113 | 'PayeeID=%s~' |
---|
| 114 | 'Amount=1234.0~' |
---|
| 115 | 'FeeStatus=unpaid~' |
---|
[10932] | 116 | 'Semester=N/A~' |
---|
[13421] | 117 | 'PaymentType=School Fee Plus~' |
---|
[10907] | 118 | 'MatricNumber=E1000000~' |
---|
| 119 | 'Email=aa@aa.ng~' |
---|
| 120 | 'PhoneNumber=1234' % self.p_id) |
---|
| 121 | |
---|
[10937] | 122 | self.browser.open('http://localhost/app/feerequest') |
---|
[10978] | 123 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
[13784] | 124 | |
---|
[9508] | 125 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
[10978] | 126 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
[13784] | 127 | |
---|
[10937] | 128 | self.browser.open( |
---|
[11652] | 129 | 'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW') |
---|
[10978] | 130 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2) |
---|
[13784] | 131 | |
---|
[10954] | 132 | self.browser.open( |
---|
[10937] | 133 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
---|
| 134 | % self.p_id) |
---|
[10978] | 135 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
[13784] | 136 | |
---|
[10937] | 137 | self.browser.open( |
---|
| 138 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
---|
| 139 | % self.p_id) |
---|
[10978] | 140 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
[13784] | 141 | |
---|
[10937] | 142 | self.browser.open( |
---|
[11651] | 143 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
---|
[10937] | 144 | % self.p_id) |
---|
[10978] | 145 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
[13784] | 146 | |
---|
[11651] | 147 | self.browser.open( |
---|
[15086] | 148 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE-UTME' |
---|
[11651] | 149 | % self.p_id) |
---|
| 150 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
[13784] | 151 | |
---|
[13799] | 152 | # Change payment state |
---|
[11554] | 153 | self.student['payments'][self.p_id].p_state = 'paid' |
---|
[13799] | 154 | |
---|
[11554] | 155 | self.browser.open( |
---|
[11652] | 156 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
[11554] | 157 | % self.p_id) |
---|
| 158 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2) |
---|
[8731] | 159 | |
---|
[13799] | 160 | # Change workflow state and payment state |
---|
[11652] | 161 | IWorkflowState(self.student).setState('returning') |
---|
| 162 | self.student['payments'][self.p_id].p_state = 'unpaid' |
---|
[13799] | 163 | |
---|
[11652] | 164 | self.browser.open( |
---|
| 165 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
| 166 | % self.p_id) |
---|
| 167 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
[13784] | 168 | |
---|
[11652] | 169 | self.browser.open( |
---|
[13784] | 170 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-BALANCE' |
---|
| 171 | % self.p_id) |
---|
| 172 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Not a balance payment' + ERROR_PART2) |
---|
[13799] | 173 | |
---|
| 174 | # Change payment item |
---|
[13784] | 175 | self.payment.p_item = u'Balance' |
---|
| 176 | self.browser.open( |
---|
| 177 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-RETURNING' |
---|
| 178 | % self.p_id) |
---|
| 179 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Balance payment' + ERROR_PART2) |
---|
| 180 | |
---|
[13799] | 181 | # Change study mode |
---|
[14083] | 182 | self.certificate.study_mode = 'special_pg_pt' |
---|
[13784] | 183 | self.browser.open( |
---|
[13799] | 184 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-BALANCE' |
---|
[11652] | 185 | % self.p_id) |
---|
[14083] | 186 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Part-time student' + ERROR_PART2) |
---|
| 187 | self.browser.open( |
---|
| 188 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PT-BALANCE' |
---|
| 189 | % self.p_id) |
---|
[13799] | 190 | self.assertEqual(self.browser.contents, |
---|
[13963] | 191 | 'PayeeName=TESTER, Anna~' |
---|
[13799] | 192 | 'Faculty=fac1~' |
---|
| 193 | 'Department=dep1~' |
---|
| 194 | 'Level=100~' |
---|
| 195 | 'ProgrammeType=Balance~' |
---|
[14083] | 196 | 'StudyType=special_pg_pt~' |
---|
[13799] | 197 | 'Session=2004/2005~' |
---|
| 198 | 'PayeeID=%s~' |
---|
| 199 | 'Amount=1234.0~' |
---|
| 200 | 'FeeStatus=unpaid~' |
---|
| 201 | 'Semester=N/A~' |
---|
| 202 | 'PaymentType=School Fee Plus~' |
---|
| 203 | 'MatricNumber=E1000000~' |
---|
| 204 | 'Email=aa@aa.ng~' |
---|
| 205 | 'PhoneNumber=1234' % self.p_id) |
---|
| 206 | |
---|
| 207 | # Change payment item |
---|
| 208 | self.payment.p_item = u'CERT1' |
---|
| 209 | |
---|
| 210 | self.browser.open( |
---|
| 211 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-RETURNING' |
---|
| 212 | % self.p_id) |
---|
[13784] | 213 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Postgrad student' + ERROR_PART2) |
---|
[10937] | 214 | |
---|
[13799] | 215 | # Cange payment category and study mode |
---|
| 216 | self.payment.p_category = 'schoolfee' |
---|
[13784] | 217 | self.certificate.study_mode = 'ug_ft' |
---|
[13799] | 218 | |
---|
[13784] | 219 | self.browser.open( |
---|
| 220 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING' |
---|
| 221 | % self.p_id) |
---|
[11652] | 222 | self.assertEqual(self.browser.contents, |
---|
[13963] | 223 | 'PayeeName=TESTER, Anna~' |
---|
[11652] | 224 | 'Faculty=fac1~' |
---|
| 225 | 'Department=dep1~' |
---|
| 226 | 'Level=100~' |
---|
| 227 | 'ProgrammeType=CERT1~' |
---|
| 228 | 'StudyType=ug_ft~' |
---|
| 229 | 'Session=2004/2005~' |
---|
| 230 | 'PayeeID=%s~' |
---|
| 231 | 'Amount=1234.0~' |
---|
| 232 | 'FeeStatus=unpaid~' |
---|
| 233 | 'Semester=N/A~' |
---|
[13784] | 234 | 'PaymentType=School Fee~' |
---|
[11652] | 235 | 'MatricNumber=E1000000~' |
---|
| 236 | 'Email=aa@aa.ng~' |
---|
| 237 | 'PhoneNumber=1234' % self.p_id) |
---|
| 238 | |
---|
[14087] | 239 | IWorkflowState(self.student).setState('cleared') |
---|
| 240 | self.browser.open( |
---|
| 241 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-FP-NEW' |
---|
| 242 | % self.p_id) |
---|
| 243 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Not a foundation programme student' + ERROR_PART2) |
---|
| 244 | self.certificate.study_mode = 'found' |
---|
| 245 | self.browser.open( |
---|
| 246 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
| 247 | % self.p_id) |
---|
| 248 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Foundation programme student' + ERROR_PART2) |
---|
| 249 | |
---|
[7976] | 250 | @external_test |
---|
| 251 | def test_etranzact_query_history(self): |
---|
| 252 | |
---|
| 253 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 254 | % self.CONFIRMATION_NO) |
---|
[8267] | 255 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 256 | self.browser.contents) |
---|
[8267] | 257 | #self.assertMatches('...Wrong amount...', |
---|
| 258 | # self.browser.contents) |
---|
| 259 | #self.student['payments'][value].amount_auth = self.student[ |
---|
| 260 | # 'payments'][value].r_amount_approved |
---|
| 261 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 262 | # % self.CONFIRMATION_NO) |
---|
| 263 | #self.assertMatches('...Wrong transaction id...', |
---|
| 264 | # self.browser.contents) |
---|
[7929] | 265 | |
---|
[8267] | 266 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
| 267 | """Tests for the Interswitch payment gateway. |
---|
| 268 | """ |
---|
| 269 | |
---|
| 270 | layer = FunctionalLayer |
---|
| 271 | |
---|
| 272 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 273 | |
---|
| 274 | def setUp(self): |
---|
| 275 | super(EtranzactTestsApplicants, self).setUp() |
---|
[15455] | 276 | certificate = createObject('waeup.Certificate') |
---|
| 277 | certificate.code = 'CERT2' |
---|
| 278 | certificate.title = 'New Certificate' |
---|
| 279 | certificate.application_category = 'basic' |
---|
| 280 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
| 281 | certificate) |
---|
[13977] | 282 | self.applicantscontainer.application_fee = 200.0 |
---|
[8267] | 283 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 284 | self.browser.open(self.manage_path) |
---|
| 285 | #IWorkflowState(self.student).setState('started') |
---|
| 286 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
| 287 | self.browser.getControl(name="transition").value = ['start'] |
---|
[11655] | 288 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
[15455] | 289 | self.browser.getControl(name="form.course2").value = ['CERT2'] |
---|
[13977] | 290 | #self.browser.getControl(name="form.programme_type").value = ['direct'] |
---|
[8267] | 291 | self.browser.getControl("Save").click() |
---|
| 292 | self.browser.getControl("Add online").click() |
---|
| 293 | self.assertTrue( |
---|
| 294 | 'Session configuration object is not available' |
---|
| 295 | in self.browser.contents) |
---|
| 296 | configuration = SessionConfiguration() |
---|
[12429] | 297 | configuration.academic_session = session_1 |
---|
[13888] | 298 | self.applicantscontainer.application_fee = 1000.0 |
---|
[8267] | 299 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[8430] | 300 | self.browser.open(self.manage_path) |
---|
[8267] | 301 | self.browser.getControl("Add online").click() |
---|
| 302 | self.assertMatches('...ticket created...', |
---|
| 303 | self.browser.contents) |
---|
| 304 | self.assertMatches('...Amount Authorized...', |
---|
| 305 | self.browser.contents) |
---|
| 306 | self.assertMatches( |
---|
| 307 | '...<span>1000.0</span>...', |
---|
| 308 | self.browser.contents) |
---|
| 309 | self.payment_url = self.browser.url |
---|
[11655] | 310 | self.browser.open(self.manage_path) |
---|
| 311 | ctrl = self.browser.getControl(name='val_id') |
---|
| 312 | value = ctrl.options[0] |
---|
| 313 | self.p_id = value |
---|
[8267] | 314 | |
---|
[11655] | 315 | def test_webservice(self): |
---|
| 316 | self.browser.open( |
---|
[15086] | 317 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE-UTME' |
---|
[11655] | 318 | % self.p_id) |
---|
[15346] | 319 | |
---|
| 320 | # webservice disabled on 6/3/19 |
---|
| 321 | self.assertEqual(self.browser.contents, '') |
---|
| 322 | return |
---|
| 323 | |
---|
[11655] | 324 | self.assertEqual(self.browser.contents, |
---|
[13963] | 325 | 'PayeeName=TESTER, John Anthony~' |
---|
[11655] | 326 | 'Faculty=N/A~' |
---|
| 327 | 'Department=N/A~' |
---|
| 328 | 'Level=N/A~' |
---|
[12429] | 329 | 'ProgrammeType=This is the app%s container~' |
---|
[11655] | 330 | 'StudyType=N/A~' |
---|
[12429] | 331 | 'Session=%s/%s~' |
---|
[11655] | 332 | 'PayeeID=%s~' |
---|
| 333 | 'Amount=1000.0~' |
---|
| 334 | 'FeeStatus=unpaid~' |
---|
| 335 | 'Semester=N/A~' |
---|
| 336 | 'PaymentType=Application Fee~' |
---|
| 337 | 'MatricNumber=%s~' |
---|
| 338 | 'Email=xx@yy.zz~' |
---|
[12429] | 339 | 'PhoneNumber=None' % ( |
---|
| 340 | session_1, session_1, session_1+1, |
---|
| 341 | self.p_id,self.applicant.applicant_id)) |
---|
[11655] | 342 | |
---|
[8267] | 343 | @external_test |
---|
| 344 | def test_etranzact_query_history(self): |
---|
| 345 | |
---|
[7976] | 346 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 347 | % self.CONFIRMATION_NO) |
---|
[8267] | 348 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 349 | self.browser.contents) |
---|
[8267] | 350 | #self.assertMatches('...Wrong amount...', |
---|
| 351 | # self.browser.contents) |
---|
| 352 | #self.applicant[value].amount_auth = self.applicant[ |
---|
| 353 | # value].r_amount_approved |
---|
| 354 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 355 | # % self.CONFIRMATION_NO) |
---|
| 356 | #self.assertMatches('...Wrong transaction id...', |
---|
| 357 | # self.browser.contents) |
---|