[7894] | 1 | ## $Id: tests.py 9143 2012-09-01 15:16:10Z 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 |
---|
[8266] | 20 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 21 | from waeup.kofa.configuration import SessionConfiguration |
---|
[8460] | 22 | from waeup.fceokene.testing import FunctionalLayer |
---|
[7894] | 23 | |
---|
[7970] | 24 | # Also run tests that send requests to external servers? |
---|
| 25 | # If you enable this, please make sure the external services |
---|
| 26 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[8271] | 27 | EXTERNAL_TESTS = False |
---|
[7970] | 28 | |
---|
| 29 | def external_test(func): |
---|
| 30 | if not EXTERNAL_TESTS: |
---|
| 31 | myself = __file__ |
---|
| 32 | if myself.endswith('.pyc'): |
---|
| 33 | myself = myself[:-2] |
---|
| 34 | print "WARNING: external tests are skipped!" |
---|
| 35 | print "WARNING: edit %s to enable them." % myself |
---|
| 36 | return |
---|
| 37 | return func |
---|
| 38 | |
---|
| 39 | |
---|
[8266] | 40 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 41 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 42 | """ |
---|
| 43 | |
---|
| 44 | layer = FunctionalLayer |
---|
| 45 | |
---|
[7970] | 46 | def setUp(self): |
---|
[8266] | 47 | super(InterswitchTestsStudents, self).setUp() |
---|
[7970] | 48 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 49 | self.browser.open(self.payments_path) |
---|
[7970] | 50 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 51 | self.browser.open(self.payments_path + '/addop') |
---|
[7970] | 52 | self.browser.getControl("Create ticket").click() |
---|
| 53 | self.assertMatches('...ticket created...', |
---|
| 54 | self.browser.contents) |
---|
| 55 | ctrl = self.browser.getControl(name='val_id') |
---|
| 56 | value = ctrl.options[0] |
---|
| 57 | self.browser.getLink(value).click() |
---|
| 58 | self.assertMatches('...Amount Authorized...', |
---|
| 59 | self.browser.contents) |
---|
[8266] | 60 | self.assertMatches( |
---|
[9143] | 61 | '...<span>12495.0</span>...', |
---|
[8266] | 62 | self.browser.contents) |
---|
[7970] | 63 | self.payment_url = self.browser.url |
---|
| 64 | |
---|
| 65 | |
---|
[8263] | 66 | # def callback_url(self, payment_url, resp, apprAmt): |
---|
| 67 | # return payment_url + ( |
---|
| 68 | # '/isw_callback?echo=' + |
---|
| 69 | # '&resp=%s' + |
---|
| 70 | # '&desc=Something went wrong' + |
---|
| 71 | # '&txnRef=p1331792385335' + |
---|
| 72 | # '&payRef=' + '&retRef=' + |
---|
| 73 | # '&cardNum=0' + |
---|
| 74 | # '&apprAmt=%s' + |
---|
| 75 | # '&url=http://xyz') % (resp, apprAmt) |
---|
[7894] | 76 | |
---|
[7970] | 77 | def test_interswitch_form(self): |
---|
[7894] | 78 | |
---|
| 79 | # Manager can access InterswitchForm |
---|
| 80 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 81 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 82 | self.browser.contents) |
---|
| 83 | self.assertMatches( |
---|
[9143] | 84 | '...<input type="hidden" name="amount" value="1249500.0" />...', |
---|
[7894] | 85 | self.browser.contents) |
---|
[9129] | 86 | self.assertMatches( |
---|
[9143] | 87 | '...item_name="schoolfee" item_amt="1044500" bank_id="117" acct_num="6216801033"...', |
---|
[9129] | 88 | self.browser.contents) |
---|
| 89 | self.assertMatches( |
---|
| 90 | '...item_name="FCEOkene Split" item_amt="140000" bank_id="117" acct_num="6216801058"...', |
---|
| 91 | self.browser.contents) |
---|
| 92 | self.assertMatches( |
---|
| 93 | '...item_name="BT Education" item_amt="50000" bank_id="31" acct_num="0026781725"...', |
---|
| 94 | self.browser.contents) |
---|
[7894] | 95 | |
---|
[8263] | 96 | # @external_test |
---|
| 97 | # def test_callback(self): |
---|
[7970] | 98 | |
---|
[7894] | 99 | # Manager can call callback manually |
---|
[8263] | 100 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
| 101 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
| 102 | # self.browser.contents) |
---|
| 103 | # self.assertMatches('...Failed...', |
---|
| 104 | # self.browser.contents) |
---|
| 105 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
| 106 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
| 107 | # self.browser.contents) |
---|
| 108 | # self.assertMatches('...Failed...', |
---|
| 109 | # self.browser.contents) |
---|
| 110 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
| 111 | # self.assertMatches('...Wrong amount...', |
---|
| 112 | # self.browser.contents) |
---|
| 113 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
| 114 | # self.assertMatches('...Valid callback received...', |
---|
| 115 | # self.browser.contents) |
---|
[7930] | 116 | |
---|
[7970] | 117 | @external_test |
---|
[7930] | 118 | def test_webservice(self): |
---|
| 119 | |
---|
[7970] | 120 | self.browser.open(self.payment_url + '/request_webservice') |
---|
[7930] | 121 | self.assertMatches('...Unsuccessful callback...', |
---|
| 122 | self.browser.contents) |
---|
[8266] | 123 | # The payment is now in state failed |
---|
| 124 | self.assertMatches('...<span>Failed</span>...', |
---|
| 125 | self.browser.contents) |
---|
| 126 | |
---|
| 127 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 128 | """Tests for the Interswitch payment gateway. |
---|
| 129 | """ |
---|
| 130 | |
---|
| 131 | layer = FunctionalLayer |
---|
| 132 | |
---|
| 133 | def setUp(self): |
---|
| 134 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 135 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 136 | self.browser.open(self.manage_path) |
---|
| 137 | #IWorkflowState(self.student).setState('started') |
---|
| 138 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
[8528] | 139 | self.applicantscontainer.application_fee = 1000.0 |
---|
[8266] | 140 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 141 | self.browser.getControl("Save").click() |
---|
| 142 | self.browser.getControl("Add online").click() |
---|
| 143 | self.assertMatches('...ticket created...', |
---|
| 144 | self.browser.contents) |
---|
[8281] | 145 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 146 | #value = ctrl.options[0] |
---|
| 147 | #self.browser.getLink(value).click() |
---|
[8266] | 148 | self.assertMatches('...Amount Authorized...', |
---|
| 149 | self.browser.contents) |
---|
| 150 | self.assertMatches( |
---|
| 151 | '...<span>1000.0</span>...', |
---|
| 152 | self.browser.contents) |
---|
| 153 | self.payment_url = self.browser.url |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | def test_interswitch_form(self): |
---|
| 157 | |
---|
| 158 | # Manager can access InterswitchForm |
---|
| 159 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 160 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 161 | self.browser.contents) |
---|
| 162 | self.assertMatches( |
---|
[8276] | 163 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
[8266] | 164 | self.browser.contents) |
---|
| 165 | |
---|
| 166 | @external_test |
---|
| 167 | def test_webservice(self): |
---|
| 168 | |
---|
| 169 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 170 | self.assertMatches('...Unsuccessful callback...', |
---|
| 171 | self.browser.contents) |
---|
| 172 | # The payment is now in state failed |
---|
| 173 | self.assertMatches('...<span>Failed</span>...', |
---|
| 174 | self.browser.contents) |
---|