1 | ## $Id: tests.py 9711 2012-11-23 07:57:57Z 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 zope.component import getUtility |
---|
19 | from zope.catalog.interfaces import ICatalog |
---|
20 | from hurry.workflow.interfaces import IWorkflowState |
---|
21 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
22 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
23 | from waeup.kofa.configuration import SessionConfiguration |
---|
24 | from waeup.fceokene.testing import FunctionalLayer |
---|
25 | |
---|
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. |
---|
29 | EXTERNAL_TESTS = False |
---|
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 | |
---|
42 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
43 | """Tests for the Interswitch payment gateway. |
---|
44 | """ |
---|
45 | |
---|
46 | layer = FunctionalLayer |
---|
47 | |
---|
48 | def setUp(self): |
---|
49 | super(InterswitchTestsStudents, self).setUp() |
---|
50 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
51 | self.browser.open(self.payments_path) |
---|
52 | IWorkflowState(self.student).setState('cleared') |
---|
53 | self.browser.open(self.payments_path + '/addop') |
---|
54 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
55 | self.browser.getControl("Create ticket").click() |
---|
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>12495.0</span>...', |
---|
65 | self.browser.contents) |
---|
66 | self.payment_url = self.browser.url |
---|
67 | |
---|
68 | |
---|
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) |
---|
79 | |
---|
80 | def test_interswitch_form(self): |
---|
81 | |
---|
82 | # Manager can access InterswitchForm for the created school fee ticket |
---|
83 | self.browser.getLink("CollegePAY", index=0).click() |
---|
84 | self.assertMatches('...Total Amount Authorized:...', |
---|
85 | self.browser.contents) |
---|
86 | self.assertMatches( |
---|
87 | '...<input type="hidden" name="amount" value="1249500.0" />...', |
---|
88 | self.browser.contents) |
---|
89 | self.assertMatches( |
---|
90 | '...item_name="School Fee" item_amt="934800" bank_id="117" acct_num="6216801033"...', |
---|
91 | self.browser.contents) |
---|
92 | self.assertMatches( |
---|
93 | '...item_name="FCEOkene Split" item_amt="140000" bank_id="117" acct_num="6216801058"...', |
---|
94 | self.browser.contents) |
---|
95 | self.assertMatches( |
---|
96 | '...item_name="BT Education" item_amt="160000" bank_id="31" acct_num="0026781725"...', |
---|
97 | self.browser.contents) |
---|
98 | |
---|
99 | # Let's do the same for maintenance fee payment |
---|
100 | |
---|
101 | self.browser.open(self.payments_path) |
---|
102 | self.browser.open(self.payments_path + '/addop') |
---|
103 | self.browser.getControl( |
---|
104 | name="form.p_category").value = ['hostel_maintenance'] |
---|
105 | self.browser.getControl("Create ticket").click() |
---|
106 | self.assertMatches('...You have not yet booked accommodation...', |
---|
107 | self.browser.contents) |
---|
108 | # Students have to book bed first |
---|
109 | self.browser.open(self.acco_path) |
---|
110 | IWorkflowState(self.student).setState('admitted') |
---|
111 | self.browser.getLink("Book accommodation").click() |
---|
112 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
113 | self.browser.getControl("Create bed ticket").click() |
---|
114 | # Bed is randomly selected but, since there is only |
---|
115 | # one bed for this student, we know that ... |
---|
116 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
117 | self.browser.contents) |
---|
118 | self.assertMatches('...ticket created...', |
---|
119 | self.browser.contents) |
---|
120 | self.browser.open(self.payments_path + '/addop') |
---|
121 | self.browser.getControl( |
---|
122 | name="form.p_category").value = ['hostel_maintenance'] |
---|
123 | self.browser.getControl("Create ticket").click() |
---|
124 | self.assertMatches('...ticket created...', |
---|
125 | self.browser.contents) |
---|
126 | ctrl = self.browser.getControl(name='val_id') |
---|
127 | value = ctrl.options[1] |
---|
128 | self.browser.getLink(value).click() |
---|
129 | self.assertMatches('...Amount Authorized...', |
---|
130 | self.browser.contents) |
---|
131 | self.assertMatches( |
---|
132 | '...<span>4150.0</span>...', |
---|
133 | self.browser.contents) |
---|
134 | self.payment_url = self.browser.url |
---|
135 | # Manager can access InterswitchForm |
---|
136 | self.browser.getLink("CollegePAY", index=0).click() |
---|
137 | # The total amount to be processed by Interswitch |
---|
138 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
139 | self.assertMatches('...Total Amount Authorized:...', |
---|
140 | self.browser.contents) |
---|
141 | self.assertMatches( |
---|
142 | '...<input type="hidden" name="amount" value="400000.0" />...', |
---|
143 | self.browser.contents) |
---|
144 | self.assertMatches( |
---|
145 | '...item_name="Hostel Maintenance Fee" item_amt="385000" bank_id="117" acct_num="1012044132"...', |
---|
146 | self.browser.contents) |
---|
147 | # BT does nor charge a fee for maintenance fee |
---|
148 | self.assertFalse("BT Education" in self.browser.contents) |
---|
149 | |
---|
150 | # @external_test |
---|
151 | # def test_callback(self): |
---|
152 | |
---|
153 | # Manager can call callback manually |
---|
154 | # self.browser.open(self.callback_url(self.payment_url, 'XX', '300')) |
---|
155 | # self.assertMatches('...Unsuccessful callback: Something went wrong...', |
---|
156 | # self.browser.contents) |
---|
157 | # self.assertMatches('...Failed...', |
---|
158 | # self.browser.contents) |
---|
159 | # self.browser.open(self.payment_url + '/isw_callback') |
---|
160 | # self.assertMatches('...Unsuccessful callback: Incomplete query string...', |
---|
161 | # self.browser.contents) |
---|
162 | # self.assertMatches('...Failed...', |
---|
163 | # self.browser.contents) |
---|
164 | # self.browser.open(self.callback_url(self.payment_url, '00', '300000')) |
---|
165 | # self.assertMatches('...Wrong amount...', |
---|
166 | # self.browser.contents) |
---|
167 | # self.browser.open(self.callback_url(self.payment_url, '00', '4000000')) |
---|
168 | # self.assertMatches('...Valid callback received...', |
---|
169 | # self.browser.contents) |
---|
170 | |
---|
171 | @external_test |
---|
172 | def test_webservice(self): |
---|
173 | self.browser.open(self.payment_url + '/request_webservice') |
---|
174 | #self.assertMatches('...Unsuccessful callback...', |
---|
175 | # self.browser.contents) |
---|
176 | self.assertMatches('...Response from Interswitch...', |
---|
177 | self.browser.contents) |
---|
178 | # The payment is now in state failed ... |
---|
179 | self.assertMatches('...<span>Failed</span>...', |
---|
180 | self.browser.contents) |
---|
181 | # ... and the catalog has been updated |
---|
182 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
183 | results = list( |
---|
184 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
185 | self.assertEqual(len(results), 1) |
---|
186 | self.assertEqual(results[0].p_state, 'failed') |
---|
187 | |
---|
188 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
189 | """Tests for the Interswitch payment gateway. |
---|
190 | """ |
---|
191 | |
---|
192 | layer = FunctionalLayer |
---|
193 | |
---|
194 | def setUp(self): |
---|
195 | super(InterswitchTestsApplicants, self).setUp() |
---|
196 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
197 | self.browser.open(self.manage_path) |
---|
198 | #IWorkflowState(self.student).setState('started') |
---|
199 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
200 | self.applicantscontainer.application_fee = 1000.0 |
---|
201 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
202 | self.browser.getControl(name="transition").value = ['start'] |
---|
203 | self.browser.getControl("Save").click() |
---|
204 | self.browser.getControl("Add online").click() |
---|
205 | self.assertMatches('...ticket created...', |
---|
206 | self.browser.contents) |
---|
207 | #ctrl = self.browser.getControl(name='val_id') |
---|
208 | #value = ctrl.options[0] |
---|
209 | #self.browser.getLink(value).click() |
---|
210 | self.assertMatches('...Amount Authorized...', |
---|
211 | self.browser.contents) |
---|
212 | self.assertMatches( |
---|
213 | '...<span>1000.0</span>...', |
---|
214 | self.browser.contents) |
---|
215 | self.payment_url = self.browser.url |
---|
216 | |
---|
217 | |
---|
218 | def test_interswitch_form(self): |
---|
219 | |
---|
220 | # Manager can access InterswitchForm |
---|
221 | self.browser.getLink("CollegePAY", index=0).click() |
---|
222 | self.assertMatches('...Total Amount Authorized:...', |
---|
223 | self.browser.contents) |
---|
224 | self.assertMatches( |
---|
225 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
226 | self.browser.contents) |
---|
227 | |
---|
228 | @external_test |
---|
229 | def test_webservice(self): |
---|
230 | |
---|
231 | self.browser.open(self.payment_url + '/request_webservice') |
---|
232 | self.assertMatches('...Unsuccessful callback...', |
---|
233 | self.browser.contents) |
---|
234 | # The payment is now in state failed |
---|
235 | self.assertMatches('...<span>Failed</span>...', |
---|
236 | self.browser.contents) |
---|