source: main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py @ 15735

Last change on this file since 15735 was 15455, checked in by Henrik Bettermann, 6 years ago

Add course3 field.

  • Property svn:keywords set to Id
File size: 14.7 KB
Line 
1## $Id: tests.py 15455 2019-06-15 12:30:51Z 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##
18from hurry.workflow.interfaces import IWorkflowState
19from zope.component import createObject, getUtility
20from waeup.kofa.students.tests.test_browser import StudentsFullSetup
21from waeup.kofa.applicants.tests.test_browser import (
22    ApplicantsFullSetup, session_1)
23from waeup.kofa.configuration import SessionConfiguration
24from waeup.aaue.testing import FunctionalLayer
25from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2
26
27
28# Also run tests that send requests to external servers?
29#   If you enable this, please make sure the external services
30#   do exist really and are not bothered by being spammed by a test programme.
31EXTERNAL_TESTS = False
32
33def external_test(func):
34    if not EXTERNAL_TESTS:
35        myself = __file__
36        if myself.endswith('.pyc'):
37            myself = myself[:-2]
38        print "WARNING: external tests are skipped!"
39        print "WARNING: edit %s to enable them." % myself
40        return
41    return func
42
43class EtranzactTestsStudent(StudentsFullSetup):
44    """Tests for the eTranzact payment gateway.
45    """
46
47    layer = FunctionalLayer
48
49    CONFIRMATION_NO = '500856521315472785095'
50
51    def setUp(self):
52        super(EtranzactTestsStudent, self).setUp()
53        # Managers can add online payment tickets
54        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
55        self.student['studycourse'].certificate.school_fee_1 = 1234.0
56        self.browser.open(self.payments_path)
57        IWorkflowState(self.student).setState('cleared')
58        self.student.nationality = u'NG'
59        self.browser.open(self.payments_path + '/addop')
60        self.browser.getControl(name="form.p_category").value = ['clearance_incl']
61        self.browser.getControl("Create ticket").click()
62        self.assertMatches('...ticket created...',
63                           self.browser.contents)
64        ctrl = self.browser.getControl(name='val_id')
65        value1 = ctrl.options[0]
66
67        self.browser.open(self.payments_path + '/addop')
68        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
69        self.browser.getControl("Create ticket").click()
70        self.assertMatches('...ticket created...',
71                           self.browser.contents)
72        ctrl = self.browser.getControl(name='val_id')
73        value2 = ctrl.options[1]
74        self.p_id = value2
75        self.payment = self.student['payments'][value2]
76        self.browser.getLink(value2).click()
77        self.assertMatches('...Amount Authorized...',
78                           self.browser.contents)
79        self.payment_url = self.browser.url
80
81    def test_enterpin(self):
82        self.student['studycourse'].entry_session = 2013
83        self.browser.open(self.payment_url)
84        self.browser.getLink("Query eTranzact History").click()
85        self.assertTrue(
86            'Please pay acceptance fee firs' in self.browser.contents)
87        self.assertFalse(
88            'Confirmation Number (PIN)' in self.browser.contents)
89        self.student['payments'].values()[0].approve()
90        self.browser.getLink("Query eTranzact History").click()
91        self.assertFalse(
92            'Please pay acceptance fee firs' in self.browser.contents)
93        self.assertTrue(
94            'Confirmation Number (PIN)' in self.browser.contents)
95
96    def test_webservice(self):
97        self.browser.open(
98            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-NEW'
99            % self.p_id)
100
101         # webservice disabled on 6/3/19
102        self.assertEqual(self.browser.contents, '')
103        return
104
105        self.assertEqual(self.browser.contents,
106            'PayeeName=TESTER, Anna~'
107            'Faculty=fac1~'
108            'Department=dep1~'
109            'Level=100~'
110            'ProgrammeType=CERT1~'
111            'StudyType=ug_ft~'
112            'Session=2004/2005~'
113            'PayeeID=%s~'
114            'Amount=1234.0~'
115            'FeeStatus=unpaid~'
116            'Semester=N/A~'
117            'PaymentType=School Fee Plus~'
118            'MatricNumber=E1000000~'
119            'Email=aa@aa.ng~'
120            'PhoneNumber=1234' % self.p_id)
121
122        self.browser.open('http://localhost/app/feerequest')
123        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
124
125        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
126        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
127
128        self.browser.open(
129            'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW')
130        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2)
131
132        self.browser.open(
133            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
134            % self.p_id)
135        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
136
137        self.browser.open(
138            'http://localhost/app/feerequest?PAYEE_ID=%s'
139            % self.p_id)
140        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
141
142        self.browser.open(
143            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE'
144            % self.p_id)
145        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
146
147        self.browser.open(
148            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE-UTME'
149            % self.p_id)
150        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
151
152        # Change payment state
153        self.student['payments'][self.p_id].p_state = 'paid'
154
155        self.browser.open(
156            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
157            % self.p_id)
158        self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2)
159
160        # Change workflow state and payment state
161        IWorkflowState(self.student).setState('returning')
162        self.student['payments'][self.p_id].p_state = 'unpaid'
163
164        self.browser.open(
165            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
166            % self.p_id)
167        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
168
169        self.browser.open(
170            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-BALANCE'
171            % self.p_id)
172        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Not a balance payment' + ERROR_PART2)
173
174        # Change payment item
175        self.payment.p_item = u'Balance'
176        self.browser.open(
177            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-RETURNING'
178            % self.p_id)
179        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Balance payment' + ERROR_PART2)
180
181        # Change study mode
182        self.certificate.study_mode = 'special_pg_pt'
183        self.browser.open(
184            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-BALANCE'
185            % self.p_id)
186        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Part-time student' + ERROR_PART2)
187        self.browser.open(
188            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PT-BALANCE'
189            % self.p_id)
190        self.assertEqual(self.browser.contents,
191            'PayeeName=TESTER, Anna~'
192            'Faculty=fac1~'
193            'Department=dep1~'
194            'Level=100~'
195            'ProgrammeType=Balance~'
196            'StudyType=special_pg_pt~'
197            'Session=2004/2005~'
198            'PayeeID=%s~'
199            'Amount=1234.0~'
200            'FeeStatus=unpaid~'
201            'Semester=N/A~'
202            'PaymentType=School Fee Plus~'
203            'MatricNumber=E1000000~'
204            'Email=aa@aa.ng~'
205            'PhoneNumber=1234' % self.p_id)
206
207        # Change payment item
208        self.payment.p_item = u'CERT1'
209
210        self.browser.open(
211            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-RETURNING'
212            % self.p_id)
213        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Postgrad student' + ERROR_PART2)
214
215        # Cange payment category and study mode
216        self.payment.p_category = 'schoolfee'
217        self.certificate.study_mode = 'ug_ft'
218       
219        self.browser.open(
220            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING'
221            % self.p_id)
222        self.assertEqual(self.browser.contents,
223            'PayeeName=TESTER, Anna~'
224            'Faculty=fac1~'
225            'Department=dep1~'
226            'Level=100~'
227            'ProgrammeType=CERT1~'
228            'StudyType=ug_ft~'
229            'Session=2004/2005~'
230            'PayeeID=%s~'
231            'Amount=1234.0~'
232            'FeeStatus=unpaid~'
233            'Semester=N/A~'
234            'PaymentType=School Fee~'
235            'MatricNumber=E1000000~'
236            'Email=aa@aa.ng~'
237            'PhoneNumber=1234' % self.p_id)
238
239        IWorkflowState(self.student).setState('cleared')
240        self.browser.open(
241            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-FP-NEW'
242            % self.p_id)
243        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Not a foundation programme student' + ERROR_PART2)
244        self.certificate.study_mode = 'found'
245        self.browser.open(
246            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
247            % self.p_id)
248        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Foundation programme student' + ERROR_PART2)
249
250    @external_test
251    def test_etranzact_query_history(self):
252
253        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
254            % self.CONFIRMATION_NO)
255        self.assertMatches('...Invalid or unsuccessful callback:...',
256                          self.browser.contents)
257        #self.assertMatches('...Wrong amount...',
258        #                  self.browser.contents)
259        #self.student['payments'][value].amount_auth = self.student[
260        #    'payments'][value].r_amount_approved
261        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
262        #    % self.CONFIRMATION_NO)
263        #self.assertMatches('...Wrong transaction id...',
264        #                  self.browser.contents)
265
266class EtranzactTestsApplicants(ApplicantsFullSetup):
267    """Tests for the Interswitch payment gateway.
268    """
269
270    layer = FunctionalLayer
271
272    CONFIRMATION_NO = '500856521315472785095'
273
274    def setUp(self):
275        super(EtranzactTestsApplicants, self).setUp()
276        certificate = createObject('waeup.Certificate')
277        certificate.code = 'CERT2'
278        certificate.title = 'New Certificate'
279        certificate.application_category = 'basic'
280        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
281            certificate)
282        self.applicantscontainer.application_fee = 200.0
283        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
284        self.browser.open(self.manage_path)
285        #IWorkflowState(self.student).setState('started')
286        super(EtranzactTestsApplicants, self).fill_correct_values()
287        self.browser.getControl(name="transition").value = ['start']
288        self.browser.getControl(name="form.nationality").value = ['NG']
289        self.browser.getControl(name="form.course2").value = ['CERT2']
290        #self.browser.getControl(name="form.programme_type").value = ['direct']
291        self.browser.getControl("Save").click()
292        self.browser.getControl("Add online").click()
293        self.assertTrue(
294            'Session configuration object is not available'
295            in self.browser.contents)
296        configuration = SessionConfiguration()
297        configuration.academic_session = session_1
298        self.applicantscontainer.application_fee = 1000.0
299        self.app['configuration'].addSessionConfiguration(configuration)
300        self.browser.open(self.manage_path)
301        self.browser.getControl("Add online").click()
302        self.assertMatches('...ticket created...',
303                           self.browser.contents)
304        self.assertMatches('...Amount Authorized...',
305                           self.browser.contents)
306        self.assertMatches(
307            '...<span>1000.0</span>...',
308            self.browser.contents)
309        self.payment_url = self.browser.url
310        self.browser.open(self.manage_path)
311        ctrl = self.browser.getControl(name='val_id')
312        value = ctrl.options[0]
313        self.p_id = value
314
315    def test_webservice(self):
316        self.browser.open(
317            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE-UTME'
318            % self.p_id)
319
320         # webservice disabled on 6/3/19
321        self.assertEqual(self.browser.contents, '')
322        return
323
324        self.assertEqual(self.browser.contents,
325            'PayeeName=TESTER, John Anthony~'
326            'Faculty=N/A~'
327            'Department=N/A~'
328            'Level=N/A~'
329            'ProgrammeType=This is the app%s container~'
330            'StudyType=N/A~'
331            'Session=%s/%s~'
332            'PayeeID=%s~'
333            'Amount=1000.0~'
334            'FeeStatus=unpaid~'
335            'Semester=N/A~'
336            'PaymentType=Application Fee~'
337            'MatricNumber=%s~'
338            'Email=xx@yy.zz~'
339            'PhoneNumber=None' % (
340                session_1, session_1, session_1+1,
341                self.p_id,self.applicant.applicant_id))
342
343    @external_test
344    def test_etranzact_query_history(self):
345
346        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
347            % self.CONFIRMATION_NO)
348        self.assertMatches('...Invalid or unsuccessful callback:...',
349                          self.browser.contents)
350        #self.assertMatches('...Wrong amount...',
351        #                  self.browser.contents)
352        #self.applicant[value].amount_auth = self.applicant[
353        #    value].r_amount_approved
354        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
355        #    % self.CONFIRMATION_NO)
356        #self.assertMatches('...Wrong transaction id...',
357        #                  self.browser.contents)
Note: See TracBrowser for help on using the repository browser.