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

Last change on this file since 13018 was 12975, checked in by Henrik Bettermann, 10 years ago

To guarantee that cleared students pay both acceptance fees and
school fees, a school fee payment POST request to the Interswitch
CollegePAY payment gateway can only be sent if
acceptance/clearance fee has been successfully queried/paid
beforehand. This requirement applies to students in state 'cleared'
and entry_session greater than 2013 only, see ticket #119.

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1## $Id: tests.py 12975 2015-05-21 17:05:42Z 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.app['configuration']['2004'].school_fee_1 = 1234.0
55        self.browser.open(self.payments_path)
56        IWorkflowState(self.student).setState('cleared')
57        self.browser.open(self.payments_path + '/addop')
58        self.browser.getControl(name="form.p_category").value = ['clearance']
59        self.browser.getControl("Create ticket").click()
60        self.assertMatches('...ticket created...',
61                           self.browser.contents)
62        ctrl = self.browser.getControl(name='val_id')
63        value1 = ctrl.options[0]
64
65        self.browser.open(self.payments_path + '/addop')
66        self.browser.getControl(name="form.p_category").value = ['schoolfee']
67        self.browser.getControl("Create ticket").click()
68        self.assertMatches('...ticket created...',
69                           self.browser.contents)
70        ctrl = self.browser.getControl(name='val_id')
71        value2 = ctrl.options[1]
72        self.p_id = value2
73        self.browser.getLink(value2).click()
74        self.assertMatches('...Amount Authorized...',
75                           self.browser.contents)
76        self.payment_url = self.browser.url
77
78    def test_enterpin(self):
79        self.student['studycourse'].entry_session = 2013
80        self.browser.open(self.payment_url)
81        self.browser.getLink("Query eTranzact History").click()
82        self.assertTrue(
83            'Please pay acceptance fee firs' in self.browser.contents)
84        self.assertFalse(
85            'Confirmation Number (PIN)' in self.browser.contents)
86        self.student['payments'].values()[0].approve()
87        self.browser.getLink("Query eTranzact History").click()
88        self.assertFalse(
89            'Please pay acceptance fee firs' in self.browser.contents)
90        self.assertTrue(
91            'Confirmation Number (PIN)' in self.browser.contents)
92
93    def test_webservice(self):
94        self.browser.open(
95            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
96            % self.p_id)
97        self.assertEqual(self.browser.contents,
98            'PayeeName=Anna Tester~'
99            'Faculty=fac1~'
100            'Department=dep1~'
101            'Level=100~'
102            'ProgrammeType=CERT1~'
103            'StudyType=ug_ft~'
104            'Session=2004/2005~'
105            'PayeeID=%s~'
106            'Amount=1234.0~'
107            'FeeStatus=unpaid~'
108            'Semester=N/A~'
109            'PaymentType=School Fee~'
110            'MatricNumber=E1000000~'
111            'Email=aa@aa.ng~'
112            'PhoneNumber=1234' % self.p_id)
113
114        self.browser.open('http://localhost/app/feerequest')
115        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
116        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
117        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
118        self.browser.open(
119            'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW')
120        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2)
121        self.browser.open(
122            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
123            % self.p_id)
124        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
125        self.browser.open(
126            'http://localhost/app/feerequest?PAYEE_ID=%s'
127            % self.p_id)
128        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
129        self.browser.open(
130            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE'
131            % self.p_id)
132        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
133        self.browser.open(
134            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
135            % self.p_id)
136        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
137        self.student['payments'][self.p_id].p_state = 'paid'
138        self.browser.open(
139            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
140            % self.p_id)
141        self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2)
142
143        IWorkflowState(self.student).setState('returning')
144        self.student['payments'][self.p_id].p_state = 'unpaid'
145        self.browser.open(
146            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
147            % self.p_id)
148        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
149        self.browser.open(
150            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING'
151            % self.p_id)
152
153        self.assertEqual(self.browser.contents,
154            'PayeeName=Anna Tester~'
155            'Faculty=fac1~'
156            'Department=dep1~'
157            'Level=100~'
158            'ProgrammeType=CERT1~'
159            'StudyType=ug_ft~'
160            'Session=2004/2005~'
161            'PayeeID=%s~'
162            'Amount=1234.0~'
163            'FeeStatus=unpaid~'
164            'Semester=N/A~'
165            'PaymentType=School Fee~'
166            'MatricNumber=E1000000~'
167            'Email=aa@aa.ng~'
168            'PhoneNumber=1234' % self.p_id)
169
170    @external_test
171    def test_etranzact_query_history(self):
172
173        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
174            % self.CONFIRMATION_NO)
175        self.assertMatches('...Invalid or unsuccessful callback:...',
176                          self.browser.contents)
177        #self.assertMatches('...Wrong amount...',
178        #                  self.browser.contents)
179        #self.student['payments'][value].amount_auth = self.student[
180        #    'payments'][value].r_amount_approved
181        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
182        #    % self.CONFIRMATION_NO)
183        #self.assertMatches('...Wrong transaction id...',
184        #                  self.browser.contents)
185
186class EtranzactTestsApplicants(ApplicantsFullSetup):
187    """Tests for the Interswitch payment gateway.
188    """
189
190    layer = FunctionalLayer
191
192    CONFIRMATION_NO = '500856521315472785095'
193
194    def setUp(self):
195        super(EtranzactTestsApplicants, self).setUp()
196        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
197        self.browser.open(self.manage_path)
198        #IWorkflowState(self.student).setState('started')
199        super(EtranzactTestsApplicants, self).fill_correct_values()
200        self.browser.getControl(name="transition").value = ['start']
201        self.browser.getControl(name="form.nationality").value = ['NG']
202        self.browser.getControl(name="form.programme_type").value = ['direct']
203        self.browser.getControl("Save").click()
204        self.browser.getControl("Add online").click()
205        self.assertTrue(
206            'Session configuration object is not available'
207            in self.browser.contents)
208        configuration = SessionConfiguration()
209        configuration.academic_session = session_1
210        configuration.application_fee = 1000.0
211        self.app['configuration'].addSessionConfiguration(configuration)
212        self.browser.open(self.manage_path)
213        self.browser.getControl("Add online").click()
214        self.assertMatches('...ticket created...',
215                           self.browser.contents)
216        self.assertMatches('...Amount Authorized...',
217                           self.browser.contents)
218        self.assertMatches(
219            '...<span>1000.0</span>...',
220            self.browser.contents)
221        self.payment_url = self.browser.url
222        self.browser.open(self.manage_path)
223        ctrl = self.browser.getControl(name='val_id')
224        value = ctrl.options[0]
225        self.p_id = value
226
227    def test_webservice(self):
228        self.browser.open(
229            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
230            % self.p_id)
231        self.assertEqual(self.browser.contents,
232            'PayeeName=John Anthony Tester~'
233            'Faculty=N/A~'
234            'Department=N/A~'
235            'Level=N/A~'
236            'ProgrammeType=This is the app%s container~'
237            'StudyType=N/A~'
238            'Session=%s/%s~'
239            'PayeeID=%s~'
240            'Amount=1000.0~'
241            'FeeStatus=unpaid~'
242            'Semester=N/A~'
243            'PaymentType=Application Fee~'
244            'MatricNumber=%s~'
245            'Email=xx@yy.zz~'
246            'PhoneNumber=None' % (
247                session_1, session_1, session_1+1,
248                self.p_id,self.applicant.applicant_id))
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.applicant[value].amount_auth = self.applicant[
260        #    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)
Note: See TracBrowser for help on using the repository browser.