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

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

Disable webservice.

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