1 | ## $Id: tests.py 11652 2014-05-14 16:04:54Z 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 |
---|
20 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
21 | from waeup.kofa.configuration import SessionConfiguration |
---|
22 | from waeup.aaue.testing import FunctionalLayer |
---|
23 | from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2 |
---|
24 | |
---|
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 | class EtranzactTestsStudent(StudentsFullSetup): |
---|
42 | """Tests for the eTranzact payment gateway. |
---|
43 | """ |
---|
44 | |
---|
45 | layer = FunctionalLayer |
---|
46 | |
---|
47 | CONFIRMATION_NO = '500856521315472785095' |
---|
48 | |
---|
49 | def setUp(self): |
---|
50 | super(EtranzactTestsStudent, self).setUp() |
---|
51 | # Managers can add online payment tickets |
---|
52 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
53 | self.app['configuration']['2004'].school_fee_1 = 1234.0 |
---|
54 | self.browser.open(self.payments_path) |
---|
55 | IWorkflowState(self.student).setState('cleared') |
---|
56 | self.browser.open(self.payments_path + '/addop') |
---|
57 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
58 | self.browser.getControl("Create ticket").click() |
---|
59 | self.assertMatches('...ticket created...', |
---|
60 | self.browser.contents) |
---|
61 | ctrl = self.browser.getControl(name='val_id') |
---|
62 | value = ctrl.options[0] |
---|
63 | self.student['payments'][value].approve() |
---|
64 | |
---|
65 | self.browser.open(self.payments_path + '/addop') |
---|
66 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
67 | self.browser.getControl("Create ticket").click() |
---|
68 | self.assertMatches('...ticket created...', |
---|
69 | self.browser.contents) |
---|
70 | ctrl = self.browser.getControl(name='val_id') |
---|
71 | value = ctrl.options[1] |
---|
72 | self.p_id = value |
---|
73 | self.browser.getLink(value).click() |
---|
74 | self.assertMatches('...Amount Authorized...', |
---|
75 | self.browser.contents) |
---|
76 | self.payment_url = self.browser.url |
---|
77 | |
---|
78 | def test_enterpin(self): |
---|
79 | self.browser.getLink("Query eTranzact History").click() |
---|
80 | self.assertMatches( |
---|
81 | '...Confirmation Number (PIN)...', |
---|
82 | self.browser.contents) |
---|
83 | |
---|
84 | def test_webservice(self): |
---|
85 | self.browser.open( |
---|
86 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
87 | % self.p_id) |
---|
88 | self.assertEqual(self.browser.contents, |
---|
89 | 'PayeeName=Anna Tester~' |
---|
90 | 'Faculty=fac1~' |
---|
91 | 'Department=dep1~' |
---|
92 | 'Level=100~' |
---|
93 | 'ProgrammeType=CERT1~' |
---|
94 | 'StudyType=ug_ft~' |
---|
95 | 'Session=2004/2005~' |
---|
96 | 'PayeeID=%s~' |
---|
97 | 'Amount=1234.0~' |
---|
98 | 'FeeStatus=unpaid~' |
---|
99 | 'Semester=N/A~' |
---|
100 | 'PaymentType=School Fee~' |
---|
101 | 'MatricNumber=E1000000~' |
---|
102 | 'Email=aa@aa.ng~' |
---|
103 | 'PhoneNumber=1234' % self.p_id) |
---|
104 | |
---|
105 | self.browser.open('http://localhost/app/feerequest') |
---|
106 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
107 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
108 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
109 | self.browser.open( |
---|
110 | 'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW') |
---|
111 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2) |
---|
112 | self.browser.open( |
---|
113 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
---|
114 | % self.p_id) |
---|
115 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
116 | self.browser.open( |
---|
117 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
---|
118 | % self.p_id) |
---|
119 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
120 | self.browser.open( |
---|
121 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
---|
122 | % self.p_id) |
---|
123 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
124 | self.browser.open( |
---|
125 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
---|
126 | % self.p_id) |
---|
127 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
128 | self.student['payments'][self.p_id].p_state = 'paid' |
---|
129 | self.browser.open( |
---|
130 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
131 | % self.p_id) |
---|
132 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2) |
---|
133 | |
---|
134 | IWorkflowState(self.student).setState('returning') |
---|
135 | self.student['payments'][self.p_id].p_state = 'unpaid' |
---|
136 | self.browser.open( |
---|
137 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW' |
---|
138 | % self.p_id) |
---|
139 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
140 | self.browser.open( |
---|
141 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING' |
---|
142 | % self.p_id) |
---|
143 | |
---|
144 | self.assertEqual(self.browser.contents, |
---|
145 | 'PayeeName=Anna Tester~' |
---|
146 | 'Faculty=fac1~' |
---|
147 | 'Department=dep1~' |
---|
148 | 'Level=100~' |
---|
149 | 'ProgrammeType=CERT1~' |
---|
150 | 'StudyType=ug_ft~' |
---|
151 | 'Session=2004/2005~' |
---|
152 | 'PayeeID=%s~' |
---|
153 | 'Amount=1234.0~' |
---|
154 | 'FeeStatus=unpaid~' |
---|
155 | 'Semester=N/A~' |
---|
156 | 'PaymentType=School Fee~' |
---|
157 | 'MatricNumber=E1000000~' |
---|
158 | 'Email=aa@aa.ng~' |
---|
159 | 'PhoneNumber=1234' % self.p_id) |
---|
160 | |
---|
161 | @external_test |
---|
162 | def test_etranzact_query_history(self): |
---|
163 | |
---|
164 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
165 | % self.CONFIRMATION_NO) |
---|
166 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
167 | self.browser.contents) |
---|
168 | #self.assertMatches('...Wrong amount...', |
---|
169 | # self.browser.contents) |
---|
170 | #self.student['payments'][value].amount_auth = self.student[ |
---|
171 | # 'payments'][value].r_amount_approved |
---|
172 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
173 | # % self.CONFIRMATION_NO) |
---|
174 | #self.assertMatches('...Wrong transaction id...', |
---|
175 | # self.browser.contents) |
---|
176 | |
---|
177 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
178 | """Tests for the Interswitch payment gateway. |
---|
179 | """ |
---|
180 | |
---|
181 | layer = FunctionalLayer |
---|
182 | |
---|
183 | CONFIRMATION_NO = '500856521315472785095' |
---|
184 | |
---|
185 | def setUp(self): |
---|
186 | super(EtranzactTestsApplicants, self).setUp() |
---|
187 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
188 | self.browser.open(self.manage_path) |
---|
189 | #IWorkflowState(self.student).setState('started') |
---|
190 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
191 | self.browser.getControl(name="transition").value = ['start'] |
---|
192 | self.browser.getControl("Save").click() |
---|
193 | self.browser.getControl("Add online").click() |
---|
194 | self.assertTrue( |
---|
195 | 'Session configuration object is not available' |
---|
196 | in self.browser.contents) |
---|
197 | configuration = SessionConfiguration() |
---|
198 | configuration.academic_session = 2009 |
---|
199 | configuration.application_fee = 1000.0 |
---|
200 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
201 | self.browser.open(self.manage_path) |
---|
202 | self.browser.getControl("Add online").click() |
---|
203 | self.assertMatches('...ticket created...', |
---|
204 | self.browser.contents) |
---|
205 | self.assertMatches('...Amount Authorized...', |
---|
206 | self.browser.contents) |
---|
207 | self.assertMatches( |
---|
208 | '...<span>1000.0</span>...', |
---|
209 | self.browser.contents) |
---|
210 | self.payment_url = self.browser.url |
---|
211 | |
---|
212 | @external_test |
---|
213 | def test_etranzact_query_history(self): |
---|
214 | |
---|
215 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
216 | % self.CONFIRMATION_NO) |
---|
217 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
218 | self.browser.contents) |
---|
219 | #self.assertMatches('...Wrong amount...', |
---|
220 | # self.browser.contents) |
---|
221 | #self.applicant[value].amount_auth = self.applicant[ |
---|
222 | # value].r_amount_approved |
---|
223 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
224 | # % self.CONFIRMATION_NO) |
---|
225 | #self.assertMatches('...Wrong transaction id...', |
---|
226 | # self.browser.contents) |
---|