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

Last change on this file since 11627 was 11624, checked in by Henrik Bettermann, 11 years ago

Configure new and returning school fee in session configuration objects.

  • Property svn:keywords set to Id
File size: 9.0 KB
RevLine 
[7929]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##
18from hurry.workflow.interfaces import IWorkflowState
19from waeup.kofa.students.tests.test_browser import StudentsFullSetup
[8267]20from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
21from waeup.kofa.configuration import SessionConfiguration
[8444]22from waeup.aaue.testing import FunctionalLayer
[10978]23from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2
[7929]24
[7970]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.
[8271]29EXTERNAL_TESTS = False
[7970]30
31def 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
[8267]41class EtranzactTestsStudent(StudentsFullSetup):
[7976]42    """Tests for the eTranzact payment gateway.
[7929]43    """
44
45    layer = FunctionalLayer
46
47    CONFIRMATION_NO = '500856521315472785095'
48
[7976]49    def setUp(self):
[8267]50        super(EtranzactTestsStudent, self).setUp()
[7929]51        # Managers can add online payment tickets
52        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[11624]53        self.app['configuration']['2004'].school_fee_1 = 1234.0
[7995]54        self.browser.open(self.payments_path)
[7929]55        IWorkflowState(self.student).setState('cleared')
[7995]56        self.browser.open(self.payments_path + '/addop')
[11622]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')
[9905]66        self.browser.getControl(name="form.p_category").value = ['schoolfee']
[7929]67        self.browser.getControl("Create ticket").click()
68        self.assertMatches('...ticket created...',
69                           self.browser.contents)
70        ctrl = self.browser.getControl(name='val_id')
[11622]71        value = ctrl.options[1]
[8731]72        self.p_id = value
[7929]73        self.browser.getLink(value).click()
74        self.assertMatches('...Amount Authorized...',
75                           self.browser.contents)
[7976]76        self.payment_url = self.browser.url
77
78    def test_enterpin(self):
79        self.browser.getLink("Query eTranzact History").click()
80        self.assertMatches(
[11291]81            '...Confirmation Number (PIN)...',
[7976]82            self.browser.contents)
83
[8731]84    def test_webservice(self):
[10937]85        self.browser.open(
86            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE'
87            % self.p_id)
[8731]88        self.assertEqual(self.browser.contents,
[10907]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~'
[10932]112            'Semester=N/A~'
[10907]113            'PaymentType=School Fee~'
114            'MatricNumber=E1000000~'
115            'Email=aa@aa.ng~'
116            'PhoneNumber=1234' % self.p_id)
117
[10937]118        self.browser.open('http://localhost/app/feerequest')
[10978]119        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
[9508]120        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
[10978]121        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
[10937]122        self.browser.open(
[10954]123            'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE')
[10978]124        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2)
[10954]125        self.browser.open(
[10937]126            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
127            % self.p_id)
[10978]128        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
[10937]129        self.browser.open(
130            'http://localhost/app/feerequest?PAYEE_ID=%s'
131            % self.p_id)
[10978]132        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
[10937]133        self.browser.open(
134            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE'
135            % self.p_id)
[10978]136        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
[10937]137        self.browser.open(
138            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
139            % self.p_id)
[10978]140        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
[11554]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)
[8731]146
[10937]147
[7976]148    @external_test
149    def test_etranzact_query_history(self):
150
151        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
[7929]152            % self.CONFIRMATION_NO)
[8267]153        self.assertMatches('...Invalid or unsuccessful callback:...',
[7929]154                          self.browser.contents)
[8267]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)
[7929]163
[8267]164class 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)
[8430]188        self.browser.open(self.manage_path)
[8267]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
[7976]202        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
[7929]203            % self.CONFIRMATION_NO)
[8267]204        self.assertMatches('...Invalid or unsuccessful callback:...',
[7929]205                          self.browser.contents)
[8267]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)
Note: See TracBrowser for help on using the repository browser.