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