[7894] | 1 | ## $Id: tests.py 9454 2012-10-29 08:30:59Z 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 |
---|
[9387] | 20 | from zope.component import createObject |
---|
| 21 | from zope.event import notify |
---|
| 22 | from waeup.kofa.university.faculty import Faculty |
---|
| 23 | from waeup.kofa.university.department import Department |
---|
[7894] | 24 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 25 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 26 | from waeup.kofa.configuration import SessionConfiguration |
---|
[9347] | 27 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
[7894] | 28 | |
---|
[7970] | 29 | # Also run tests that send requests to external servers? |
---|
| 30 | # If you enable this, please make sure the external services |
---|
| 31 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[8271] | 32 | EXTERNAL_TESTS = False |
---|
[7970] | 33 | |
---|
| 34 | def external_test(func): |
---|
| 35 | if not EXTERNAL_TESTS: |
---|
| 36 | myself = __file__ |
---|
| 37 | if myself.endswith('.pyc'): |
---|
| 38 | myself = myself[:-2] |
---|
| 39 | print "WARNING: external tests are skipped!" |
---|
| 40 | print "WARNING: edit %s to enable them." % myself |
---|
| 41 | return |
---|
| 42 | return func |
---|
| 43 | |
---|
| 44 | |
---|
[8266] | 45 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 46 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 47 | """ |
---|
| 48 | |
---|
| 49 | layer = FunctionalLayer |
---|
| 50 | |
---|
[7970] | 51 | def setUp(self): |
---|
[8266] | 52 | super(InterswitchTestsStudents, self).setUp() |
---|
[9387] | 53 | |
---|
| 54 | # Create at least one Kwarapoly faculty |
---|
| 55 | self.app['faculties']['CPGS'] = Faculty(code='CPGS') |
---|
| 56 | self.app['faculties']['CPGS']['dep1'] = Department(code='dep1') |
---|
| 57 | self.certificate2 = createObject('waeup.Certificate') |
---|
| 58 | self.certificate2.code = u'CERT2' |
---|
| 59 | self.certificate2.application_category = 'basic' |
---|
| 60 | self.certificate2.study_mode = 'nd_ft' |
---|
| 61 | self.certificate2.start_level = 100 |
---|
| 62 | self.certificate2.end_level = 300 |
---|
| 63 | self.app['faculties']['CPGS']['dep1'].certificates.addCertificate( |
---|
| 64 | self.certificate2) |
---|
| 65 | # Set study course attributes of test student |
---|
| 66 | self.student['studycourse'].certificate = self.certificate2 |
---|
| 67 | self.student['studycourse'].current_session = 2004 |
---|
| 68 | self.student['studycourse'].entry_session = 2004 |
---|
| 69 | self.student['studycourse'].current_verdict = 'A' |
---|
| 70 | self.student['studycourse'].current_level = 100 |
---|
[9392] | 71 | # Set local lga |
---|
| 72 | self.student.lga = u'kwara_asa' |
---|
[9387] | 73 | # Update the catalog |
---|
| 74 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
| 75 | |
---|
[7970] | 76 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 77 | self.browser.open(self.payments_path) |
---|
[7970] | 78 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 79 | self.browser.open(self.payments_path + '/addop') |
---|
[7970] | 80 | self.browser.getControl("Create ticket").click() |
---|
[9436] | 81 | self.assertMatches('...ticket created...', |
---|
| 82 | self.browser.contents) |
---|
| 83 | ctrl = self.browser.getControl(name='val_id') |
---|
| 84 | value = ctrl.options[0] |
---|
| 85 | self.browser.getLink(value).click() |
---|
| 86 | self.assertMatches('...Amount Authorized...', |
---|
| 87 | self.browser.contents) |
---|
| 88 | self.assertMatches( |
---|
| 89 | '...<span>37100.0</span>...', |
---|
| 90 | self.browser.contents) |
---|
| 91 | self.payment_url = self.browser.url |
---|
[7970] | 92 | |
---|
| 93 | |
---|
[8263] | 94 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 95 | # return payment_url + ( |
---|
| 96 | # '/isw_callback?echo=' + |
---|
| 97 | # '&resp=%s' + |
---|
| 98 | # '&desc=Something went wrong' + |
---|
| 99 | # '&txnRef=p1331792385335' + |
---|
| 100 | # '&payRef=' + '&retRef=' + |
---|
| 101 | # '&cardNum=0' + |
---|
| 102 | # '&apprAmt=%s' + |
---|
| 103 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 104 | |
---|
[7970] | 105 | def test_interswitch_form(self): |
---|
[7894] | 106 | # Manager can access InterswitchForm |
---|
| 107 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 108 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 109 | self.browser.contents) |
---|
| 110 | self.assertMatches( |
---|
[9392] | 111 | '...<input type="hidden" name="amount" value="3710000.0" />...', |
---|
[7894] | 112 | self.browser.contents) |
---|
[9129] | 113 | self.assertMatches( |
---|
[9392] | 114 | '...item_name="schoolfee" item_amt="3380000" bank_id="120" acct_num="1771180233"...', |
---|
[9129] | 115 | self.browser.contents) |
---|
| 116 | self.assertMatches( |
---|
[9387] | 117 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
[9129] | 118 | self.browser.contents) |
---|
| 119 | self.assertMatches( |
---|
[9387] | 120 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
[9129] | 121 | self.browser.contents) |
---|
[7894] | 122 | |
---|
[8263] | 123 | # @external_test |
---|
| 124 | # def test_callback(self): |
---|
[7970] | 125 | |
---|
[7894] | 126 | # Manager can call callback manually |
---|
[8263] | 127 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
| 128 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
| 129 | # self.browser.contents) |
---|
| 130 | # self.assertMatches('...Failed...', |
---|
| 131 | # self.browser.contents) |
---|
| 132 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
| 133 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
| 134 | # self.browser.contents) |
---|
| 135 | # self.assertMatches('...Failed...', |
---|
| 136 | # self.browser.contents) |
---|
| 137 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
| 138 | # self.assertMatches('...Wrong amount...', |
---|
| 139 | # self.browser.contents) |
---|
| 140 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
| 141 | # self.assertMatches('...Valid callback received...', |
---|
| 142 | # self.browser.contents) |
---|
[7930] | 143 | |
---|
[7970] | 144 | @external_test |
---|
[7930] | 145 | def test_webservice(self): |
---|
| 146 | |
---|
[7970] | 147 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 148 | self.assertMatches('...Unsuccessful callback...', |
---|
| 149 | self.browser.contents) |
---|
[8266] | 150 | # The payment is now in state failed |
---|
| 151 | self.assertMatches('...<span>Failed</span>...', |
---|
| 152 | self.browser.contents) |
---|
| 153 | |
---|
| 154 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 155 | """Tests for the Interswitch payment gateway. |
---|
| 156 | """ |
---|
| 157 | |
---|
| 158 | layer = FunctionalLayer |
---|
| 159 | |
---|
| 160 | def setUp(self): |
---|
| 161 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 162 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 163 | self.browser.open(self.manage_path) |
---|
| 164 | #IWorkflowState(self.student).setState('started') |
---|
| 165 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
[8528] | 166 | self.applicantscontainer.application_fee = 1000.0 |
---|
[9454] | 167 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
[8266] | 168 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 169 | self.browser.getControl("Save").click() |
---|
| 170 | self.browser.getControl("Add online").click() |
---|
| 171 | self.assertMatches('...ticket created...', |
---|
| 172 | self.browser.contents) |
---|
[8281] | 173 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 174 | #value = ctrl.options[0] |
---|
| 175 | #self.browser.getLink(value).click() |
---|
[8266] | 176 | self.assertMatches('...Amount Authorized...', |
---|
| 177 | self.browser.contents) |
---|
| 178 | self.assertMatches( |
---|
| 179 | '...<span>1000.0</span>...', |
---|
| 180 | self.browser.contents) |
---|
| 181 | self.payment_url = self.browser.url |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | def test_interswitch_form(self): |
---|
| 185 | |
---|
| 186 | # Manager can access InterswitchForm |
---|
| 187 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 188 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 189 | self.browser.contents) |
---|
| 190 | self.assertMatches( |
---|
[8276] | 191 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
[8266] | 192 | self.browser.contents) |
---|
| 193 | |
---|
| 194 | @external_test |
---|
| 195 | def test_webservice(self): |
---|
| 196 | |
---|
| 197 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 198 | self.assertMatches('...Unsuccessful callback...', |
---|
| 199 | self.browser.contents) |
---|
| 200 | # The payment is now in state failed |
---|
| 201 | self.assertMatches('...<span>Failed</span>...', |
---|
| 202 | self.browser.contents) |
---|