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