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