| 1 | ## $Id: tests.py 13374 2015-11-01 14:11:52Z 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 |
|---|
| 19 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
|---|
| 20 | from waeup.kofa.applicants.tests.test_browser import ( |
|---|
| 21 | ApplicantsFullSetup, session_1) |
|---|
| 22 | from waeup.kofa.configuration import SessionConfiguration |
|---|
| 23 | from waeup.aaue.testing import FunctionalLayer |
|---|
| 24 | from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2 |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | # Also run tests that send requests to external servers? |
|---|
| 28 | # If you enable this, please make sure the external services |
|---|
| 29 | # do exist really and are not bothered by being spammed by a test programme. |
|---|
| 30 | EXTERNAL_TESTS = False |
|---|
| 31 | |
|---|
| 32 | def external_test(func): |
|---|
| 33 | if not EXTERNAL_TESTS: |
|---|
| 34 | myself = __file__ |
|---|
| 35 | if myself.endswith('.pyc'): |
|---|
| 36 | myself = myself[:-2] |
|---|
| 37 | print "WARNING: external tests are skipped!" |
|---|
| 38 | print "WARNING: edit %s to enable them." % myself |
|---|
| 39 | return |
|---|
| 40 | return func |
|---|
| 41 | |
|---|
| 42 | class EtranzactTestsStudent(StudentsFullSetup): |
|---|
| 43 | """Tests for the eTranzact payment gateway. |
|---|
| 44 | """ |
|---|
| 45 | |
|---|
| 46 | layer = FunctionalLayer |
|---|
| 47 | |
|---|
| 48 | CONFIRMATION_NO = '500856521315472785095' |
|---|
| 49 | |
|---|
| 50 | def setUp(self): |
|---|
| 51 | super(EtranzactTestsStudent, self).setUp() |
|---|
| 52 | # Managers can add online payment tickets |
|---|
| 53 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
|---|
| 54 | self.student['studycourse'].certificate.school_fee_1 = 1234.0 |
|---|
| 55 | self.browser.open(self.payments_path) |
|---|
| 56 | IWorkflowState(self.student).setState('cleared') |
|---|
| 57 | self.student.nationality = u'NG' |
|---|
| 58 | self.browser.open(self.payments_path + '/addop') |
|---|
| 59 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
|---|
| 60 | self.browser.getControl("Create ticket").click() |
|---|
| 61 | self.assertMatches('...ticket created...', |
|---|
| 62 | self.browser.contents) |
|---|
| 63 | ctrl = self.browser.getControl(name='val_id') |
|---|
| 64 | value1 = ctrl.options[0] |
|---|
| 65 | |
|---|
| 66 | self.browser.open(self.payments_path + '/addop') |
|---|
| 67 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 68 | self.browser.getControl("Create ticket").click() |
|---|
| 69 | self.assertMatches('...ticket created...', |
|---|
| 70 | self.browser.contents) |
|---|
| 71 | ctrl = self.browser.getControl(name='val_id') |
|---|
| 72 | value2 = ctrl.options[1] |
|---|
| 73 | self.p_id = value2 |
|---|
| 74 | self.browser.getLink(value2).click() |
|---|
| 75 | self.assertMatches('...Amount Authorized...', |
|---|
| 76 | self.browser.contents) |
|---|
| 77 | self.payment_url = self.browser.url |
|---|
| 78 | |
|---|
| 79 | def test_enterpin(self): |
|---|
| 80 | self.student['studycourse'].entry_session = 2013 |
|---|
| 81 | self.browser.open(self.payment_url) |
|---|
| 82 | self.browser.getLink("Query eTranzact History").click() |
|---|
| 83 | self.assertTrue( |
|---|
| 84 | 'Please pay acceptance fee firs' in self.browser.contents) |
|---|
| 85 | self.assertFalse( |
|---|
| 86 | 'Confirmation Number (PIN)' in self.browser.contents) |
|---|
| 87 | self.student['payments'].values()[0].approve() |
|---|
| 88 | self.browser.getLink("Query eTranzact History").click() |
|---|
| 89 | self.assertFalse( |
|---|
| 90 | 'Please pay acceptance fee firs' in self.browser.contents) |
|---|
| 91 | self.assertTrue( |
|---|
| 92 | 'Confirmation Number (PIN)' in self.browser.contents) |
|---|
| 93 | |
|---|
| 94 | def test_webservice(self): |
|---|
| 95 | self.browser.open( |
|---|
| 96 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
|---|
| 97 | % self.p_id) |
|---|
| 98 | self.assertEqual(self.browser.contents, |
|---|
| 99 | 'PayeeName=Anna Tester~' |
|---|
| 100 | 'Faculty=fac1~' |
|---|
| 101 | 'Department=dep1~' |
|---|
| 102 | 'Level=100~' |
|---|
| 103 | 'ProgrammeType=CERT1~' |
|---|
| 104 | 'StudyType=ug_ft~' |
|---|
| 105 | 'Session=2004/2005~' |
|---|
| 106 | 'PayeeID=%s~' |
|---|
| 107 | 'Amount=1234.0~' |
|---|
| 108 | 'FeeStatus=unpaid~' |
|---|
| 109 | 'Semester=N/A~' |
|---|
| 110 | 'PaymentType=School Fee~' |
|---|
| 111 | 'MatricNumber=E1000000~' |
|---|
| 112 | 'Email=aa@aa.ng~' |
|---|
| 113 | 'PhoneNumber=1234' % self.p_id) |
|---|
| 114 | |
|---|
| 115 | self.browser.open('http://localhost/app/feerequest') |
|---|
| 116 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
|---|
| 117 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
|---|
| 118 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
|---|
| 119 | self.browser.open( |
|---|
| 120 | 'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW') |
|---|
| 121 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2) |
|---|
| 122 | self.browser.open( |
|---|
| 123 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
|---|
| 124 | % self.p_id) |
|---|
| 125 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
|---|
| 126 | self.browser.open( |
|---|
| 127 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
|---|
| 128 | % self.p_id) |
|---|
| 129 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
|---|
| 130 | self.browser.open( |
|---|
| 131 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
|---|
| 132 | % self.p_id) |
|---|
| 133 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
|---|
| 134 | self.browser.open( |
|---|
| 135 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
|---|
| 136 | % self.p_id) |
|---|
| 137 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
|---|
| 138 | self.student['payments'][self.p_id].p_state = 'paid' |
|---|
| 139 | self.browser.open( |
|---|
| 140 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
|---|
| 141 | % self.p_id) |
|---|
| 142 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2) |
|---|
| 143 | |
|---|
| 144 | IWorkflowState(self.student).setState('returning') |
|---|
| 145 | self.student['payments'][self.p_id].p_state = 'unpaid' |
|---|
| 146 | self.browser.open( |
|---|
| 147 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
|---|
| 148 | % self.p_id) |
|---|
| 149 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
|---|
| 150 | self.browser.open( |
|---|
| 151 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING' |
|---|
| 152 | % self.p_id) |
|---|
| 153 | |
|---|
| 154 | self.assertEqual(self.browser.contents, |
|---|
| 155 | 'PayeeName=Anna Tester~' |
|---|
| 156 | 'Faculty=fac1~' |
|---|
| 157 | 'Department=dep1~' |
|---|
| 158 | 'Level=100~' |
|---|
| 159 | 'ProgrammeType=CERT1~' |
|---|
| 160 | 'StudyType=ug_ft~' |
|---|
| 161 | 'Session=2004/2005~' |
|---|
| 162 | 'PayeeID=%s~' |
|---|
| 163 | 'Amount=1234.0~' |
|---|
| 164 | 'FeeStatus=unpaid~' |
|---|
| 165 | 'Semester=N/A~' |
|---|
| 166 | 'PaymentType=School Fee~' |
|---|
| 167 | 'MatricNumber=E1000000~' |
|---|
| 168 | 'Email=aa@aa.ng~' |
|---|
| 169 | 'PhoneNumber=1234' % self.p_id) |
|---|
| 170 | |
|---|
| 171 | @external_test |
|---|
| 172 | def test_etranzact_query_history(self): |
|---|
| 173 | |
|---|
| 174 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
|---|
| 175 | % self.CONFIRMATION_NO) |
|---|
| 176 | self.assertMatches('...Invalid or unsuccessful callback:...', |
|---|
| 177 | self.browser.contents) |
|---|
| 178 | #self.assertMatches('...Wrong amount...', |
|---|
| 179 | # self.browser.contents) |
|---|
| 180 | #self.student['payments'][value].amount_auth = self.student[ |
|---|
| 181 | # 'payments'][value].r_amount_approved |
|---|
| 182 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
|---|
| 183 | # % self.CONFIRMATION_NO) |
|---|
| 184 | #self.assertMatches('...Wrong transaction id...', |
|---|
| 185 | # self.browser.contents) |
|---|
| 186 | |
|---|
| 187 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
|---|
| 188 | """Tests for the Interswitch payment gateway. |
|---|
| 189 | """ |
|---|
| 190 | |
|---|
| 191 | layer = FunctionalLayer |
|---|
| 192 | |
|---|
| 193 | CONFIRMATION_NO = '500856521315472785095' |
|---|
| 194 | |
|---|
| 195 | def setUp(self): |
|---|
| 196 | super(EtranzactTestsApplicants, self).setUp() |
|---|
| 197 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
|---|
| 198 | self.browser.open(self.manage_path) |
|---|
| 199 | #IWorkflowState(self.student).setState('started') |
|---|
| 200 | super(EtranzactTestsApplicants, self).fill_correct_values() |
|---|
| 201 | self.browser.getControl(name="transition").value = ['start'] |
|---|
| 202 | self.browser.getControl(name="form.nationality").value = ['NG'] |
|---|
| 203 | self.browser.getControl(name="form.programme_type").value = ['direct'] |
|---|
| 204 | self.browser.getControl("Save").click() |
|---|
| 205 | self.browser.getControl("Add online").click() |
|---|
| 206 | self.assertTrue( |
|---|
| 207 | 'Session configuration object is not available' |
|---|
| 208 | in self.browser.contents) |
|---|
| 209 | configuration = SessionConfiguration() |
|---|
| 210 | configuration.academic_session = session_1 |
|---|
| 211 | configuration.application_fee = 1000.0 |
|---|
| 212 | self.app['configuration'].addSessionConfiguration(configuration) |
|---|
| 213 | self.browser.open(self.manage_path) |
|---|
| 214 | self.browser.getControl("Add online").click() |
|---|
| 215 | self.assertMatches('...ticket created...', |
|---|
| 216 | self.browser.contents) |
|---|
| 217 | self.assertMatches('...Amount Authorized...', |
|---|
| 218 | self.browser.contents) |
|---|
| 219 | self.assertMatches( |
|---|
| 220 | '...<span>1000.0</span>...', |
|---|
| 221 | self.browser.contents) |
|---|
| 222 | self.payment_url = self.browser.url |
|---|
| 223 | self.browser.open(self.manage_path) |
|---|
| 224 | ctrl = self.browser.getControl(name='val_id') |
|---|
| 225 | value = ctrl.options[0] |
|---|
| 226 | self.p_id = value |
|---|
| 227 | |
|---|
| 228 | def test_webservice(self): |
|---|
| 229 | self.browser.open( |
|---|
| 230 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
|---|
| 231 | % self.p_id) |
|---|
| 232 | self.assertEqual(self.browser.contents, |
|---|
| 233 | 'PayeeName=John Anthony Tester~' |
|---|
| 234 | 'Faculty=N/A~' |
|---|
| 235 | 'Department=N/A~' |
|---|
| 236 | 'Level=N/A~' |
|---|
| 237 | 'ProgrammeType=This is the app%s container~' |
|---|
| 238 | 'StudyType=N/A~' |
|---|
| 239 | 'Session=%s/%s~' |
|---|
| 240 | 'PayeeID=%s~' |
|---|
| 241 | 'Amount=1000.0~' |
|---|
| 242 | 'FeeStatus=unpaid~' |
|---|
| 243 | 'Semester=N/A~' |
|---|
| 244 | 'PaymentType=Application Fee~' |
|---|
| 245 | 'MatricNumber=%s~' |
|---|
| 246 | 'Email=xx@yy.zz~' |
|---|
| 247 | 'PhoneNumber=None' % ( |
|---|
| 248 | session_1, session_1, session_1+1, |
|---|
| 249 | self.p_id,self.applicant.applicant_id)) |
|---|
| 250 | |
|---|
| 251 | @external_test |
|---|
| 252 | def test_etranzact_query_history(self): |
|---|
| 253 | |
|---|
| 254 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
|---|
| 255 | % self.CONFIRMATION_NO) |
|---|
| 256 | self.assertMatches('...Invalid or unsuccessful callback:...', |
|---|
| 257 | self.browser.contents) |
|---|
| 258 | #self.assertMatches('...Wrong amount...', |
|---|
| 259 | # self.browser.contents) |
|---|
| 260 | #self.applicant[value].amount_auth = self.applicant[ |
|---|
| 261 | # value].r_amount_approved |
|---|
| 262 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
|---|
| 263 | # % self.CONFIRMATION_NO) |
|---|
| 264 | #self.assertMatches('...Wrong transaction id...', |
|---|
| 265 | # self.browser.contents) |
|---|