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

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

Implement validation of PAYMENT_TYPE parameter.

  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
1## $Id: tests.py 10937 2014-01-16 15:46:17Z 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 ApplicantsFullSetup
21from waeup.kofa.configuration import SessionConfiguration
22from waeup.aaue.testing import FunctionalLayer
23
24
25# Also run tests that send requests to external servers?
26#   If you enable this, please make sure the external services
27#   do exist really and are not bothered by being spammed by a test programme.
28EXTERNAL_TESTS = False
29
30def external_test(func):
31    if not EXTERNAL_TESTS:
32        myself = __file__
33        if myself.endswith('.pyc'):
34            myself = myself[:-2]
35        print "WARNING: external tests are skipped!"
36        print "WARNING: edit %s to enable them." % myself
37        return
38    return func
39
40class EtranzactTestsStudent(StudentsFullSetup):
41    """Tests for the eTranzact payment gateway.
42    """
43
44    layer = FunctionalLayer
45
46    CONFIRMATION_NO = '500856521315472785095'
47
48    def setUp(self):
49        super(EtranzactTestsStudent, self).setUp()
50        # Managers can add online payment tickets
51        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
52        self.app['configuration']['2004'].school_fee = 1234.0
53        self.browser.open(self.payments_path)
54        IWorkflowState(self.student).setState('cleared')
55        self.browser.open(self.payments_path + '/addop')
56        self.browser.getControl(name="form.p_category").value = ['schoolfee']
57        self.browser.getControl("Create ticket").click()
58        self.assertMatches('...ticket created...',
59                           self.browser.contents)
60
61        ctrl = self.browser.getControl(name='val_id')
62        value = ctrl.options[0]
63        self.p_id = value
64        self.browser.getLink(value).click()
65        self.assertMatches('...Amount Authorized...',
66                           self.browser.contents)
67        self.payment_url = self.browser.url
68
69    def test_enterpin(self):
70        self.browser.getLink("Query eTranzact History").click()
71        self.assertMatches(
72            '...Confirmation Number (PIN):...',
73            self.browser.contents)
74
75    def test_webservice(self):
76        self.browser.open(
77            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE'
78            % self.p_id)
79        self.assertEqual(self.browser.contents,
80            # Version 1
81            #'FULL_NAME=Anna Tester&'
82            #'FACULTY=fac1&'
83            #'DEPARTMENT=dep1&'
84            #'RETURN_TYPE=%s&'
85            #'PROGRAMME_TYPE=CERT1&'
86            #'PAYMENT_TYPE=School Fee&'
87            #'ACADEMIC_SESSION=2004/2005&'
88            #'MATRIC_NO=E1000000&'
89            #'FEE_AMOUNT=1234.0&'
90            #'TRANSACTION_STATUS=unpaid'
91
92            # Version 2
93            'PayeeName=Anna Tester~'
94            'Faculty=fac1~'
95            'Department=dep1~'
96            'Level=100~'
97            'ProgrammeType=CERT1~'
98            'StudyType=ug_ft~'
99            'Session=2004/2005~'
100            'PayeeID=%s~'
101            'Amount=1234.0~'
102            'FeeStatus=unpaid~'
103            'Semester=N/A~'
104            'PaymentType=School Fee~'
105            'MatricNumber=E1000000~'
106            'Email=aa@aa.ng~'
107            'PhoneNumber=1234' % self.p_id)
108
109        self.browser.open('http://localhost/app/feerequest')
110        self.assertEqual(self.browser.contents, '-1')
111        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
112        self.assertEqual(self.browser.contents, '-1')
113        self.browser.open(
114            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
115            % self.p_id)
116        self.assertEqual(self.browser.contents, '-3')
117        self.browser.open(
118            'http://localhost/app/feerequest?PAYEE_ID=%s'
119            % self.p_id)
120        self.assertEqual(self.browser.contents, '-3')
121        self.browser.open(
122            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE'
123            % self.p_id)
124        self.assertEqual(self.browser.contents, '-6')
125        self.browser.open(
126            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
127            % self.p_id)
128        self.assertEqual(self.browser.contents, '-7')
129
130
131    @external_test
132    def test_etranzact_query_history(self):
133
134        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
135            % self.CONFIRMATION_NO)
136        self.assertMatches('...Invalid or unsuccessful callback:...',
137                          self.browser.contents)
138        #self.assertMatches('...Wrong amount...',
139        #                  self.browser.contents)
140        #self.student['payments'][value].amount_auth = self.student[
141        #    'payments'][value].r_amount_approved
142        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
143        #    % self.CONFIRMATION_NO)
144        #self.assertMatches('...Wrong transaction id...',
145        #                  self.browser.contents)
146
147class EtranzactTestsApplicants(ApplicantsFullSetup):
148    """Tests for the Interswitch payment gateway.
149    """
150
151    layer = FunctionalLayer
152
153    CONFIRMATION_NO = '500856521315472785095'
154
155    def setUp(self):
156        super(EtranzactTestsApplicants, self).setUp()
157        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
158        self.browser.open(self.manage_path)
159        #IWorkflowState(self.student).setState('started')
160        super(EtranzactTestsApplicants, self).fill_correct_values()
161        self.browser.getControl(name="transition").value = ['start']
162        self.browser.getControl("Save").click()
163        self.browser.getControl("Add online").click()
164        self.assertTrue(
165            'Session configuration object is not available'
166            in self.browser.contents)
167        configuration = SessionConfiguration()
168        configuration.academic_session = 2009
169        configuration.application_fee = 1000.0
170        self.app['configuration'].addSessionConfiguration(configuration)
171        self.browser.open(self.manage_path)
172        self.browser.getControl("Add online").click()
173        self.assertMatches('...ticket created...',
174                           self.browser.contents)
175        self.assertMatches('...Amount Authorized...',
176                           self.browser.contents)
177        self.assertMatches(
178            '...<span>1000.0</span>...',
179            self.browser.contents)
180        self.payment_url = self.browser.url
181
182    @external_test
183    def test_etranzact_query_history(self):
184
185        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
186            % self.CONFIRMATION_NO)
187        self.assertMatches('...Invalid or unsuccessful callback:...',
188                          self.browser.contents)
189        #self.assertMatches('...Wrong amount...',
190        #                  self.browser.contents)
191        #self.applicant[value].amount_auth = self.applicant[
192        #    value].r_amount_approved
193        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
194        #    % self.CONFIRMATION_NO)
195        #self.assertMatches('...Wrong transaction id...',
196        #                  self.browser.contents)
Note: See TracBrowser for help on using the repository browser.