1 | ## $Id: tests.py 9436 2012-10-26 21:49:15Z 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 | import grok |
---|
19 | from hurry.workflow.interfaces import IWorkflowState |
---|
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 |
---|
24 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
25 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
26 | from waeup.kofa.configuration import SessionConfiguration |
---|
27 | from waeup.kwarapoly.testing import FunctionalLayer |
---|
28 | |
---|
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. |
---|
32 | EXTERNAL_TESTS = False |
---|
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 | |
---|
45 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
46 | """Tests for the Interswitch payment gateway. |
---|
47 | """ |
---|
48 | |
---|
49 | layer = FunctionalLayer |
---|
50 | |
---|
51 | def setUp(self): |
---|
52 | super(InterswitchTestsStudents, self).setUp() |
---|
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 |
---|
71 | # Set local lga |
---|
72 | self.student.lga = u'kwara_asa' |
---|
73 | # Update the catalog |
---|
74 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
75 | |
---|
76 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
77 | self.browser.open(self.payments_path) |
---|
78 | IWorkflowState(self.student).setState('cleared') |
---|
79 | self.browser.open(self.payments_path + '/addop') |
---|
80 | self.browser.getControl("Create ticket").click() |
---|
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 |
---|
92 | |
---|
93 | |
---|
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) |
---|
104 | |
---|
105 | def test_interswitch_form(self): |
---|
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( |
---|
111 | '...<input type="hidden" name="amount" value="3710000.0" />...', |
---|
112 | self.browser.contents) |
---|
113 | self.assertMatches( |
---|
114 | '...item_name="schoolfee" item_amt="3380000" bank_id="120" acct_num="1771180233"...', |
---|
115 | self.browser.contents) |
---|
116 | self.assertMatches( |
---|
117 | '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...', |
---|
118 | self.browser.contents) |
---|
119 | self.assertMatches( |
---|
120 | '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...', |
---|
121 | self.browser.contents) |
---|
122 | |
---|
123 | # @external_test |
---|
124 | # def test_callback(self): |
---|
125 | |
---|
126 | # Manager can call callback manually |
---|
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) |
---|
143 | |
---|
144 | @external_test |
---|
145 | def test_webservice(self): |
---|
146 | |
---|
147 | self.browser.open(self.payment_url + '/request_webservice') |
---|
148 | self.assertMatches('...Unsuccessful callback...', |
---|
149 | self.browser.contents) |
---|
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() |
---|
166 | self.applicantscontainer.application_fee = 1000.0 |
---|
167 | self.browser.getControl(name="transition").value = ['start'] |
---|
168 | self.browser.getControl("Save").click() |
---|
169 | self.browser.getControl("Add online").click() |
---|
170 | self.assertMatches('...ticket created...', |
---|
171 | self.browser.contents) |
---|
172 | #ctrl = self.browser.getControl(name='val_id') |
---|
173 | #value = ctrl.options[0] |
---|
174 | #self.browser.getLink(value).click() |
---|
175 | self.assertMatches('...Amount Authorized...', |
---|
176 | self.browser.contents) |
---|
177 | self.assertMatches( |
---|
178 | '...<span>1000.0</span>...', |
---|
179 | self.browser.contents) |
---|
180 | self.payment_url = self.browser.url |
---|
181 | |
---|
182 | |
---|
183 | def test_interswitch_form(self): |
---|
184 | |
---|
185 | # Manager can access InterswitchForm |
---|
186 | self.browser.getLink("CollegePAY", index=0).click() |
---|
187 | self.assertMatches('...Total Amount Authorized:...', |
---|
188 | self.browser.contents) |
---|
189 | self.assertMatches( |
---|
190 | '...<input type="hidden" name="amount" value="100000.0" />...', |
---|
191 | self.browser.contents) |
---|
192 | |
---|
193 | @external_test |
---|
194 | def test_webservice(self): |
---|
195 | |
---|
196 | self.browser.open(self.payment_url + '/request_webservice') |
---|
197 | self.assertMatches('...Unsuccessful callback...', |
---|
198 | self.browser.contents) |
---|
199 | # The payment is now in state failed |
---|
200 | self.assertMatches('...<span>Failed</span>...', |
---|
201 | self.browser.contents) |
---|