[7894] | 1 | ## $Id: tests.py 9731 2012-11-27 15:02:34Z 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 | ## |
---|
[9713] | 18 | from zope.component import createObject, getUtility |
---|
| 19 | from zope.catalog.interfaces import ICatalog |
---|
[7894] | 20 | from hurry.workflow.interfaces import IWorkflowState |
---|
| 21 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 22 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 23 | from waeup.kofa.configuration import SessionConfiguration |
---|
[8020] | 24 | from waeup.uniben.testing import FunctionalLayer |
---|
[7894] | 25 | |
---|
[7970] | 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 | |
---|
| 41 | |
---|
[8266] | 42 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 43 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 44 | """ |
---|
| 45 | |
---|
| 46 | layer = FunctionalLayer |
---|
| 47 | |
---|
[7970] | 48 | def setUp(self): |
---|
[8266] | 49 | super(InterswitchTestsStudents, self).setUp() |
---|
[7970] | 50 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 51 | self.browser.open(self.payments_path) |
---|
[7970] | 52 | IWorkflowState(self.student).setState('cleared') |
---|
[9006] | 53 | self.student.nationality = u'NG' |
---|
[7995] | 54 | self.browser.open(self.payments_path + '/addop') |
---|
[9384] | 55 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7970] | 56 | self.browser.getControl("Create ticket").click() |
---|
[9435] | 57 | self.assertMatches('...ticket created...', |
---|
| 58 | self.browser.contents) |
---|
| 59 | ctrl = self.browser.getControl(name='val_id') |
---|
| 60 | value = ctrl.options[0] |
---|
| 61 | self.browser.getLink(value).click() |
---|
| 62 | self.assertMatches('...Amount Authorized...', |
---|
| 63 | self.browser.contents) |
---|
| 64 | self.assertMatches( |
---|
| 65 | '...<span>40000.0</span>...', |
---|
| 66 | self.browser.contents) |
---|
| 67 | self.payment_url = self.browser.url |
---|
[7970] | 68 | |
---|
[8263] | 69 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 70 | # return payment_url + ( |
---|
| 71 | # '/isw_callback?echo=' + |
---|
| 72 | # '&resp=%s' + |
---|
| 73 | # '&desc=Something went wrong' + |
---|
| 74 | # '&txnRef=p1331792385335' + |
---|
| 75 | # '&payRef=' + '&retRef=' + |
---|
| 76 | # '&cardNum=0' + |
---|
| 77 | # '&apprAmt=%s' + |
---|
| 78 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 79 | |
---|
[7970] | 80 | def test_interswitch_form(self): |
---|
[7894] | 81 | # Manager can access InterswitchForm |
---|
| 82 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[8266] | 83 | # The total amount to be processed by Interswitch |
---|
| 84 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
[9389] | 85 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5700" />...', |
---|
| 86 | self.browser.contents) |
---|
[9384] | 87 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 88 | self.browser.contents) |
---|
[9460] | 89 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
[7894] | 90 | self.assertMatches( |
---|
[8276] | 91 | '...<input type="hidden" name="amount" value="4000000.0" />...', |
---|
[7894] | 92 | self.browser.contents) |
---|
[9384] | 93 | self.assertMatches( |
---|
[9460] | 94 | '...item_name="School Fee" item_amt="3835000" bank_id="8" acct_num="2017506430"...', |
---|
[9384] | 95 | self.browser.contents) |
---|
| 96 | self.assertMatches( |
---|
| 97 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
| 98 | self.browser.contents) |
---|
[7894] | 99 | |
---|
[9520] | 100 | # Create school fee ticket for returning students. Payment is made |
---|
| 101 | # for next session. |
---|
| 102 | current_payment_key = self.student['payments'].keys()[0] |
---|
[9389] | 103 | self.certificate.study_mode = u'ug_pt' |
---|
| 104 | IWorkflowState(self.student).setState('returning') |
---|
| 105 | configuration = createObject('waeup.SessionConfiguration') |
---|
| 106 | configuration.academic_session = 2005 |
---|
| 107 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[9384] | 108 | self.browser.open(self.payments_path + '/addop') |
---|
[9389] | 109 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[9384] | 110 | self.browser.getControl("Create ticket").click() |
---|
[9570] | 111 | |
---|
| 112 | ## Next session payment can't be made ... |
---|
| 113 | #self.assertMatches( |
---|
| 114 | # '...You have not yet paid your current/active session...', |
---|
| 115 | # self.browser.contents) |
---|
| 116 | ## current session payment must be approved first. |
---|
| 117 | #self.student['payments'][current_payment_key].approve() |
---|
| 118 | #self.browser.open(self.payments_path + '/addop') |
---|
| 119 | #self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 120 | #self.browser.getControl("Create ticket").click() |
---|
| 121 | |
---|
[9384] | 122 | ctrl = self.browser.getControl(name='val_id') |
---|
| 123 | value = ctrl.options[1] |
---|
| 124 | self.browser.getLink(value).click() |
---|
[9389] | 125 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 126 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...', |
---|
[9384] | 127 | self.browser.contents) |
---|
| 128 | self.assertMatches( |
---|
[9389] | 129 | '...<input type="hidden" name="amount" value="2000000.0" />...', |
---|
| 130 | self.browser.contents) |
---|
| 131 | self.assertMatches( |
---|
[9460] | 132 | '...item_name="School Fee" item_amt="1835000" bank_id="16" acct_num="0122009929"...', |
---|
[9389] | 133 | self.browser.contents) |
---|
| 134 | self.assertMatches( |
---|
| 135 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
| 136 | self.browser.contents) |
---|
| 137 | |
---|
| 138 | # Create clearance fee ticket |
---|
| 139 | self.browser.open(self.payments_path + '/addop') |
---|
| 140 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
| 141 | self.browser.getControl("Create ticket").click() |
---|
| 142 | ctrl = self.browser.getControl(name='val_id') |
---|
| 143 | value = ctrl.options[2] |
---|
| 144 | self.browser.getLink(value).click() |
---|
| 145 | self.assertMatches( |
---|
[9384] | 146 | '...<span>45000.0</span>...', |
---|
| 147 | self.browser.contents) |
---|
| 148 | # Manager can access InterswitchForm |
---|
| 149 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9389] | 150 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...', |
---|
[9384] | 151 | self.browser.contents) |
---|
| 152 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 153 | self.browser.contents) |
---|
| 154 | self.assertMatches( |
---|
| 155 | '...<input type="hidden" name="amount" value="4500000.0" />...', |
---|
| 156 | self.browser.contents) |
---|
| 157 | self.assertMatches( |
---|
| 158 | '...item_name="Acceptance Fee" item_amt="4335000" bank_id="7" acct_num="1003475516"...', |
---|
| 159 | self.browser.contents) |
---|
| 160 | self.assertMatches( |
---|
| 161 | '...item_name="BT Education" item_amt="150000" bank_id="117" acct_num="1010764827"...', |
---|
| 162 | self.browser.contents) |
---|
| 163 | |
---|
[9515] | 164 | # Create gown fee ticket |
---|
| 165 | configuration.maint_fee = 987.0 |
---|
| 166 | self.app['configuration']['2004'].gown_fee = 234.0 |
---|
| 167 | self.browser.open(self.payments_path + '/addop') |
---|
| 168 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
| 169 | self.browser.getControl("Create ticket").click() |
---|
| 170 | ctrl = self.browser.getControl(name='val_id') |
---|
| 171 | value = ctrl.options[3] |
---|
| 172 | self.browser.getLink(value).click() |
---|
| 173 | self.assertMatches( |
---|
| 174 | '...<span>234.0</span>...', |
---|
| 175 | self.browser.contents) |
---|
| 176 | # Manager can access InterswitchForm |
---|
| 177 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 178 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5704" />...', |
---|
| 179 | self.browser.contents) |
---|
| 180 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 181 | self.browser.contents) |
---|
| 182 | self.assertMatches( |
---|
| 183 | '...<input type="hidden" name="amount" value="23400.0" />...', |
---|
| 184 | self.browser.contents) |
---|
| 185 | self.assertMatches( |
---|
| 186 | '...<item_detail item_id="1" item_name="Gown Hire Fee" item_amt="8400" bank_id="7" acct_num="1016232382" />...', |
---|
| 187 | self.browser.contents) |
---|
| 188 | self.assertFalse( |
---|
| 189 | 'item_name="BT Education"' in self.browser.contents) |
---|
[9384] | 190 | |
---|
[9727] | 191 | # Create temp maint fee ticket |
---|
| 192 | self.browser.open(self.payments_path + '/addop') |
---|
| 193 | self.browser.getControl(name="form.p_category").value = ['tempmaint_1'] |
---|
| 194 | self.browser.getControl("Create ticket").click() |
---|
| 195 | ctrl = self.browser.getControl(name='val_id') |
---|
| 196 | value = ctrl.options[4] |
---|
| 197 | self.browser.getLink(value).click() |
---|
| 198 | self.assertMatches( |
---|
[9728] | 199 | '...<span>8150.0</span>...', |
---|
[9727] | 200 | self.browser.contents) |
---|
| 201 | # Manager can access InterswitchForm |
---|
| 202 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 203 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="5705" />...', |
---|
| 204 | self.browser.contents) |
---|
| 205 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 206 | self.browser.contents) |
---|
| 207 | self.assertMatches( |
---|
[9728] | 208 | '...<input type="hidden" name="amount" value="815000.0" />...', |
---|
[9727] | 209 | self.browser.contents) |
---|
| 210 | self.assertMatches( |
---|
[9731] | 211 | '...<item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="800000" bank_id="129" acct_num="0014414547" />...', |
---|
[9727] | 212 | self.browser.contents) |
---|
[9728] | 213 | self.assertFalse( |
---|
| 214 | 'item_name="BT Education"' in self.browser.contents) |
---|
[9727] | 215 | |
---|
[8263] | 216 | # @external_test |
---|
| 217 | # def test_callback(self): |
---|
[7970] | 218 | |
---|
[7894] | 219 | # Manager can call callback manually |
---|
[8263] | 220 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
| 221 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
| 222 | # self.browser.contents) |
---|
| 223 | # self.assertMatches('...Failed...', |
---|
| 224 | # self.browser.contents) |
---|
| 225 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
| 226 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
| 227 | # self.browser.contents) |
---|
| 228 | # self.assertMatches('...Failed...', |
---|
| 229 | # self.browser.contents) |
---|
| 230 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
| 231 | # self.assertMatches('...Wrong amount...', |
---|
| 232 | # self.browser.contents) |
---|
| 233 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
| 234 | # self.assertMatches('...Valid callback received...', |
---|
| 235 | # self.browser.contents) |
---|
[7930] | 236 | |
---|
[7970] | 237 | @external_test |
---|
[7930] | 238 | def test_webservice(self): |
---|
| 239 | |
---|
[7970] | 240 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 241 | self.assertMatches('...Unsuccessful callback...', |
---|
| 242 | self.browser.contents) |
---|
[9713] | 243 | # The payment is now in state failed ... |
---|
[8266] | 244 | self.assertMatches('...<span>Failed</span>...', |
---|
| 245 | self.browser.contents) |
---|
[9713] | 246 | # ... and the catalog has been updated |
---|
| 247 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 248 | results = list( |
---|
| 249 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 250 | self.assertEqual(len(results), 1) |
---|
| 251 | self.assertEqual(results[0].p_state, 'failed') |
---|
[8266] | 252 | |
---|
| 253 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 254 | """Tests for the Interswitch payment gateway. |
---|
| 255 | """ |
---|
| 256 | |
---|
| 257 | layer = FunctionalLayer |
---|
| 258 | |
---|
| 259 | def setUp(self): |
---|
| 260 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 261 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 262 | self.browser.open(self.manage_path) |
---|
| 263 | #IWorkflowState(self.student).setState('started') |
---|
| 264 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
[8526] | 265 | self.applicantscontainer.application_fee = 1000.0 |
---|
[9453] | 266 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
[8266] | 267 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 268 | self.browser.getControl("Save").click() |
---|
| 269 | self.browser.getControl("Add online").click() |
---|
| 270 | self.assertMatches('...ticket created...', |
---|
| 271 | self.browser.contents) |
---|
[8281] | 272 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 273 | #value = ctrl.options[0] |
---|
| 274 | #self.browser.getLink(value).click() |
---|
[8266] | 275 | self.assertMatches('...Amount Authorized...', |
---|
| 276 | self.browser.contents) |
---|
| 277 | self.assertMatches( |
---|
| 278 | '...<span>1000.0</span>...', |
---|
| 279 | self.browser.contents) |
---|
| 280 | self.payment_url = self.browser.url |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | def test_interswitch_form(self): |
---|
| 284 | |
---|
| 285 | # Manager can access InterswitchForm |
---|
| 286 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 287 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 288 | self.browser.contents) |
---|
| 289 | self.assertMatches( |
---|
[8276] | 290 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
[8266] | 291 | self.browser.contents) |
---|
| 292 | |
---|
| 293 | @external_test |
---|
| 294 | def test_webservice(self): |
---|
| 295 | |
---|
| 296 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 297 | self.assertMatches('...Unsuccessful callback...', |
---|
| 298 | self.browser.contents) |
---|
| 299 | # The payment is now in state failed |
---|
| 300 | self.assertMatches('...<span>Failed</span>...', |
---|
| 301 | self.browser.contents) |
---|