1 | ## $Id: tests.py 11624 2014-05-06 19:00:28Z 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' |
---|
87 | % self.p_id) |
---|
88 | self.assertEqual(self.browser.contents, |
---|
89 | # Version 1 |
---|
90 | #'FULL_NAME=Anna Tester&' |
---|
91 | #'FACULTY=fac1&' |
---|
92 | #'DEPARTMENT=dep1&' |
---|
93 | #'RETURN_TYPE=%s&' |
---|
94 | #'PROGRAMME_TYPE=CERT1&' |
---|
95 | #'PAYMENT_TYPE=School Fee&' |
---|
96 | #'ACADEMIC_SESSION=2004/2005&' |
---|
97 | #'MATRIC_NO=E1000000&' |
---|
98 | #'FEE_AMOUNT=1234.0&' |
---|
99 | #'TRANSACTION_STATUS=unpaid' |
---|
100 | |
---|
101 | # Version 2 |
---|
102 | 'PayeeName=Anna Tester~' |
---|
103 | 'Faculty=fac1~' |
---|
104 | 'Department=dep1~' |
---|
105 | 'Level=100~' |
---|
106 | 'ProgrammeType=CERT1~' |
---|
107 | 'StudyType=ug_ft~' |
---|
108 | 'Session=2004/2005~' |
---|
109 | 'PayeeID=%s~' |
---|
110 | 'Amount=1234.0~' |
---|
111 | 'FeeStatus=unpaid~' |
---|
112 | 'Semester=N/A~' |
---|
113 | 'PaymentType=School Fee~' |
---|
114 | 'MatricNumber=E1000000~' |
---|
115 | 'Email=aa@aa.ng~' |
---|
116 | 'PhoneNumber=1234' % self.p_id) |
---|
117 | |
---|
118 | self.browser.open('http://localhost/app/feerequest') |
---|
119 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
120 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
121 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
122 | self.browser.open( |
---|
123 | 'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE') |
---|
124 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2) |
---|
125 | self.browser.open( |
---|
126 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
---|
127 | % self.p_id) |
---|
128 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
129 | self.browser.open( |
---|
130 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
---|
131 | % self.p_id) |
---|
132 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
133 | self.browser.open( |
---|
134 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
---|
135 | % self.p_id) |
---|
136 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
137 | self.browser.open( |
---|
138 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
---|
139 | % self.p_id) |
---|
140 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
141 | self.student['payments'][self.p_id].p_state = 'paid' |
---|
142 | self.browser.open( |
---|
143 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE' |
---|
144 | % self.p_id) |
---|
145 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2) |
---|
146 | |
---|
147 | |
---|
148 | @external_test |
---|
149 | def test_etranzact_query_history(self): |
---|
150 | |
---|
151 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
152 | % self.CONFIRMATION_NO) |
---|
153 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
154 | self.browser.contents) |
---|
155 | #self.assertMatches('...Wrong amount...', |
---|
156 | # self.browser.contents) |
---|
157 | #self.student['payments'][value].amount_auth = self.student[ |
---|
158 | # 'payments'][value].r_amount_approved |
---|
159 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
160 | # % self.CONFIRMATION_NO) |
---|
161 | #self.assertMatches('...Wrong transaction id...', |
---|
162 | # self.browser.contents) |
---|
163 | |
---|
164 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
165 | """Tests for the Interswitch payment gateway. |
---|
166 | """ |
---|
167 | |
---|
168 | layer = FunctionalLayer |
---|
169 | |
---|
170 | CONFIRMATION_NO = '500856521315472785095' |
---|
171 | |
---|
172 | def setUp(self): |
---|
173 | super(EtranzactTestsApplicants, self).setUp() |
---|
174 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
175 | self.browser.open(self.manage_path) |
---|
176 | #IWorkflowState(self.student).setState('started') |
---|
177 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
178 | self.browser.getControl(name="transition").value = ['start'] |
---|
179 | self.browser.getControl("Save").click() |
---|
180 | self.browser.getControl("Add online").click() |
---|
181 | self.assertTrue( |
---|
182 | 'Session configuration object is not available' |
---|
183 | in self.browser.contents) |
---|
184 | configuration = SessionConfiguration() |
---|
185 | configuration.academic_session = 2009 |
---|
186 | configuration.application_fee = 1000.0 |
---|
187 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
188 | self.browser.open(self.manage_path) |
---|
189 | self.browser.getControl("Add online").click() |
---|
190 | self.assertMatches('...ticket created...', |
---|
191 | self.browser.contents) |
---|
192 | self.assertMatches('...Amount Authorized...', |
---|
193 | self.browser.contents) |
---|
194 | self.assertMatches( |
---|
195 | '...<span>1000.0</span>...', |
---|
196 | self.browser.contents) |
---|
197 | self.payment_url = self.browser.url |
---|
198 | |
---|
199 | @external_test |
---|
200 | def test_etranzact_query_history(self): |
---|
201 | |
---|
202 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
203 | % self.CONFIRMATION_NO) |
---|
204 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
205 | self.browser.contents) |
---|
206 | #self.assertMatches('...Wrong amount...', |
---|
207 | # self.browser.contents) |
---|
208 | #self.applicant[value].amount_auth = self.applicant[ |
---|
209 | # value].r_amount_approved |
---|
210 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
211 | # % self.CONFIRMATION_NO) |
---|
212 | #self.assertMatches('...Wrong transaction id...', |
---|
213 | # self.browser.contents) |
---|