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

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

Ticket #495: " I am thinking if you change the fee type (PAYMENT_TYPE=APPLICATION-FEE) to "PAYMENT_TYPE=APPLICATION-FEE-UTME". The the new name, etranzact will not be able to call our service."

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