[7894] | 1 | ## $Id: tests.py 9737 2012-11-28 17:00:43Z 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 | ## |
---|
[9387] | 18 | import grok |
---|
[7894] | 19 | from hurry.workflow.interfaces import IWorkflowState |
---|
[9710] | 20 | from zope.component import createObject, getUtility |
---|
| 21 | from zope.catalog.interfaces import ICatalog |
---|
[9387] | 22 | from zope.event import notify |
---|
| 23 | from waeup.kofa.university.faculty import Faculty |
---|
| 24 | from waeup.kofa.university.department import Department |
---|
[7894] | 25 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 26 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 27 | from waeup.kofa.configuration import SessionConfiguration |
---|
[9347] | 28 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
[7894] | 29 | |
---|
[7970] | 30 | # Also run tests that send requests to external servers? |
---|
| 31 | # If you enable this, please make sure the external services |
---|
| 32 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[8271] | 33 | EXTERNAL_TESTS = False |
---|
[7970] | 34 | |
---|
| 35 | def external_test(func): |
---|
| 36 | if not EXTERNAL_TESTS: |
---|
| 37 | myself = __file__ |
---|
| 38 | if myself.endswith('.pyc'): |
---|
| 39 | myself = myself[:-2] |
---|
| 40 | print "WARNING: external tests are skipped!" |
---|
| 41 | print "WARNING: edit %s to enable them." % myself |
---|
| 42 | return |
---|
| 43 | return func |
---|
| 44 | |
---|
| 45 | |
---|
[8266] | 46 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 47 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 48 | """ |
---|
| 49 | |
---|
| 50 | layer = FunctionalLayer |
---|
| 51 | |
---|
[7970] | 52 | def setUp(self): |
---|
[8266] | 53 | super(InterswitchTestsStudents, self).setUp() |
---|
[9387] | 54 | |
---|
| 55 | # Create at least one Kwarapoly faculty |
---|
| 56 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 57 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 58 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 59 | self.certificate2.code = u'CERT2' |
---|
| 60 | self.certificate2.application_category = 'basic' |
---|
| 61 | self.certificate2.study_mode = 'nd_ft' |
---|
| 62 | self.certificate2.start_level = 100 |
---|
| 63 | self.certificate2.end_level = 300 |
---|
| 64 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 65 | self.certificate2) |
---|
| 66 | # Set study course attributes of test student |
---|
| 67 | self.student['studycourse'].certificate = self.certificate2 |
---|
| 68 | self.student['studycourse'].current_session = 2004 |
---|
| 69 | self.student['studycourse'].entry_session = 2004 |
---|
| 70 | self.student['studycourse'].current_verdict = 'A' |
---|
| 71 | self.student['studycourse'].current_level = 100 |
---|
[9392] | 72 | # Set local lga |
---|
| 73 | self.student.lga = u'kwara_asa' |
---|
[9387] | 74 | # Update the catalog |
---|
| 75 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
| 76 | |
---|
[7970] | 77 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 78 | self.browser.open(self.payments_path) |
---|
[7970] | 79 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 80 | self.browser.open(self.payments_path + '/addop') |
---|
[9737] | 81 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7970] | 82 | self.browser.getControl("Create ticket").click() |
---|
[9436] | 83 | self.assertMatches('...ticket created...', |
---|
| 84 | self.browser.contents) |
---|
| 85 | ctrl = self.browser.getControl(name='val_id') |
---|
| 86 | value = ctrl.options[0] |
---|
| 87 | self.browser.getLink(value).click() |
---|
| 88 | self.assertMatches('...Amount Authorized...', |
---|
| 89 | self.browser.contents) |
---|
| 90 | self.assertMatches( |
---|
[9528] | 91 | '...<span>36600.0</span>...', |
---|
[9436] | 92 | self.browser.contents) |
---|
| 93 | self.payment_url = self.browser.url |
---|
[7970] | 94 | |
---|
| 95 | |
---|
[8263] | 96 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 97 | # return payment_url + ( |
---|
| 98 | # '/isw_callback?echo=' + |
---|
| 99 | # '&resp=%s' + |
---|
| 100 | # '&desc=Something went wrong' + |
---|
| 101 | # '&txnRef=p1331792385335' + |
---|
| 102 | # '&payRef=' + '&retRef=' + |
---|
| 103 | # '&cardNum=0' + |
---|
| 104 | # '&apprAmt=%s' + |
---|
| 105 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 106 | |
---|
[7970] | 107 | def test_interswitch_form(self): |
---|
[7894] | 108 | # Manager can access InterswitchForm |
---|
| 109 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 110 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 111 | self.browser.contents) |
---|
| 112 | self.assertMatches( |
---|
[9392] | 113 | '...<input type="hidden" name="amount" value="3710000.0" />...', |
---|
[7894] | 114 | self.browser.contents) |
---|
[9129] | 115 | self.assertMatches( |
---|
[9616] | 116 | '...item_name="School Fee" item_amt="3380000" bank_id="120" acct_num="1771180233"...', |
---|
[9129] | 117 | self.browser.contents) |
---|
| 118 | self.assertMatches( |
---|
[9387] | 119 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
[9129] | 120 | self.browser.contents) |
---|
| 121 | self.assertMatches( |
---|
[9387] | 122 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
[9129] | 123 | self.browser.contents) |
---|
[7894] | 124 | |
---|
[9616] | 125 | # Let's do the same for maintenance fee payment |
---|
| 126 | |
---|
| 127 | self.browser.open(self.payments_path) |
---|
| 128 | self.browser.open(self.payments_path + '/addop') |
---|
| 129 | self.browser.getControl( |
---|
| 130 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 131 | self.browser.getControl("Create ticket").click() |
---|
| 132 | self.assertMatches('...You have not yet booked accommodation...', |
---|
| 133 | self.browser.contents) |
---|
| 134 | # Students have to book bed first |
---|
| 135 | self.browser.open(self.acco_path) |
---|
| 136 | IWorkflowState(self.student).setState('admitted') |
---|
| 137 | self.browser.getLink("Book accommodation").click() |
---|
| 138 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
| 139 | self.browser.getControl("Create bed ticket").click() |
---|
| 140 | # Bed is randomly selected but, since there is only |
---|
| 141 | # one bed for this student, we know that ... |
---|
| 142 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
| 143 | self.browser.contents) |
---|
| 144 | self.assertMatches('...ticket created...', |
---|
| 145 | self.browser.contents) |
---|
| 146 | self.browser.open(self.payments_path + '/addop') |
---|
| 147 | self.browser.getControl( |
---|
| 148 | name="form.p_category").value = ['hostel_maintenance'] |
---|
| 149 | self.browser.getControl("Create ticket").click() |
---|
| 150 | self.assertMatches('...ticket created...', |
---|
| 151 | self.browser.contents) |
---|
| 152 | ctrl = self.browser.getControl(name='val_id') |
---|
| 153 | value = ctrl.options[1] |
---|
| 154 | self.browser.getLink(value).click() |
---|
| 155 | self.assertMatches('...Amount Authorized...', |
---|
| 156 | self.browser.contents) |
---|
| 157 | # Maint fee is taken from the session configuration object |
---|
| 158 | self.assertMatches( |
---|
| 159 | '...<span>987.0</span>...', |
---|
| 160 | self.browser.contents) |
---|
| 161 | self.payment_url = self.browser.url |
---|
| 162 | # Manager can access InterswitchForm |
---|
| 163 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 164 | # The total amount to be processed by Interswitch |
---|
| 165 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 166 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 167 | self.browser.contents) |
---|
| 168 | self.assertMatches( |
---|
[9626] | 169 | '...<input type="hidden" name="pay_item_id" value="102" />...', |
---|
| 170 | self.browser.contents) |
---|
| 171 | self.assertMatches( |
---|
[9616] | 172 | '...<input type="hidden" name="amount" value="98700.0" />...', |
---|
| 173 | self.browser.contents) |
---|
| 174 | self.assertMatches( |
---|
[9617] | 175 | '...item_name="Hostel Maintenance Fee" item_amt="68700" bank_id="31" acct_num="0039050937"...', |
---|
[9616] | 176 | self.browser.contents) |
---|
| 177 | |
---|
[9737] | 178 | # Create carryover ticket |
---|
| 179 | self.browser.open(self.payments_path + '/addop') |
---|
| 180 | self.browser.getControl(name="form.p_category").value = ['carryover1'] |
---|
| 181 | self.browser.getControl("Create ticket").click() |
---|
| 182 | ctrl = self.browser.getControl(name='val_id') |
---|
| 183 | value = ctrl.options[2] |
---|
| 184 | self.browser.getLink(value).click() |
---|
| 185 | self.assertMatches( |
---|
| 186 | '...<span>6000.0</span>...', |
---|
| 187 | self.browser.contents) |
---|
| 188 | # Manager can access InterswitchForm |
---|
| 189 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 190 | self.assertMatches('...<input type="hidden" name="pay_item_id" value="101" />...', |
---|
| 191 | self.browser.contents) |
---|
| 192 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 193 | self.browser.contents) |
---|
| 194 | self.assertMatches( |
---|
| 195 | '...<input type="hidden" name="amount" value="600000.0" />...', |
---|
| 196 | self.browser.contents) |
---|
| 197 | self.assertMatches( |
---|
| 198 | '...item_name="School Fee" item_amt="270000" bank_id="120" acct_num="1771180233"...', |
---|
| 199 | self.browser.contents) |
---|
| 200 | self.assertMatches( |
---|
| 201 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
| 202 | self.browser.contents) |
---|
| 203 | self.assertMatches( |
---|
| 204 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
| 205 | self.browser.contents) |
---|
| 206 | |
---|
[8263] | 207 | # @external_test |
---|
| 208 | # def test_callback(self): |
---|
[7970] | 209 | |
---|
[7894] | 210 | # Manager can call callback manually |
---|
[8263] | 211 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
| 212 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
| 213 | # self.browser.contents) |
---|
| 214 | # self.assertMatches('...Failed...', |
---|
| 215 | # self.browser.contents) |
---|
| 216 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
| 217 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
| 218 | # self.browser.contents) |
---|
| 219 | # self.assertMatches('...Failed...', |
---|
| 220 | # self.browser.contents) |
---|
| 221 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
| 222 | # self.assertMatches('...Wrong amount...', |
---|
| 223 | # self.browser.contents) |
---|
| 224 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
| 225 | # self.assertMatches('...Valid callback received...', |
---|
| 226 | # self.browser.contents) |
---|
[7930] | 227 | |
---|
[7970] | 228 | @external_test |
---|
[7930] | 229 | def test_webservice(self): |
---|
| 230 | |
---|
[7970] | 231 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 232 | self.assertMatches('...Unsuccessful callback...', |
---|
| 233 | self.browser.contents) |
---|
[9710] | 234 | # The payment is now in state failed ... |
---|
[8266] | 235 | self.assertMatches('...<span>Failed</span>...', |
---|
| 236 | self.browser.contents) |
---|
[9710] | 237 | # ... and the catalog has been updated |
---|
| 238 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 239 | results = list( |
---|
| 240 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 241 | self.assertEqual(len(results), 1) |
---|
| 242 | self.assertEqual(results[0].p_state, 'failed') |
---|
[8266] | 243 | |
---|
| 244 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 245 | """Tests for the Interswitch payment gateway. |
---|
| 246 | """ |
---|
| 247 | |
---|
| 248 | layer = FunctionalLayer |
---|
| 249 | |
---|
| 250 | def setUp(self): |
---|
| 251 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 252 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 253 | self.browser.open(self.manage_path) |
---|
| 254 | #IWorkflowState(self.student).setState('started') |
---|
| 255 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
[8528] | 256 | self.applicantscontainer.application_fee = 1000.0 |
---|
[9454] | 257 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
[8266] | 258 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 259 | self.browser.getControl("Save").click() |
---|
| 260 | self.browser.getControl("Add online").click() |
---|
| 261 | self.assertMatches('...ticket created...', |
---|
| 262 | self.browser.contents) |
---|
[8281] | 263 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 264 | #value = ctrl.options[0] |
---|
| 265 | #self.browser.getLink(value).click() |
---|
[8266] | 266 | self.assertMatches('...Amount Authorized...', |
---|
| 267 | self.browser.contents) |
---|
| 268 | self.assertMatches( |
---|
| 269 | '...<span>1000.0</span>...', |
---|
| 270 | self.browser.contents) |
---|
| 271 | self.payment_url = self.browser.url |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | def test_interswitch_form(self): |
---|
| 275 | |
---|
| 276 | # Manager can access InterswitchForm |
---|
| 277 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 278 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 279 | self.browser.contents) |
---|
| 280 | self.assertMatches( |
---|
[8276] | 281 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
[8266] | 282 | self.browser.contents) |
---|
| 283 | |
---|
| 284 | @external_test |
---|
| 285 | def test_webservice(self): |
---|
| 286 | |
---|
| 287 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 288 | self.assertMatches('...Unsuccessful callback...', |
---|
| 289 | self.browser.contents) |
---|
| 290 | # The payment is now in state failed |
---|
| 291 | self.assertMatches('...<span>Failed</span>...', |
---|
| 292 | self.browser.contents) |
---|