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

Last change on this file since 13793 was 13784, checked in by Henrik Bettermann, 9 years ago

Improve and reorganize webservice.

  • Property svn:keywords set to Id
File size: 12.3 KB
Line 
1## $Id: tests.py 13784 2016-03-19 12:51:01Z 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        self.assertEqual(self.browser.contents,
100            'PayeeName=Anna Tester~'
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~'
110            'Semester=N/A~'
111            'PaymentType=School Fee Plus~'
112            'MatricNumber=E1000000~'
113            'Email=aa@aa.ng~'
114            'PhoneNumber=1234' % self.p_id)
115
116        self.browser.open('http://localhost/app/feerequest')
117        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
118
119        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
120        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
121
122        self.browser.open(
123            'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE-NEW')
124        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2)
125
126        self.browser.open(
127            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
128            % self.p_id)
129        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2)
130
131        self.browser.open(
132            'http://localhost/app/feerequest?PAYEE_ID=%s'
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&PAYMENT_TYPE=ACCEPTANCE-FEE'
138            % self.p_id)
139        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
140
141        self.browser.open(
142            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
143            % self.p_id)
144        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
145
146        self.student['payments'][self.p_id].p_state = 'paid'
147        self.browser.open(
148            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-NEW'
149            % self.p_id)
150        self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2)
151
152        IWorkflowState(self.student).setState('returning')
153        self.student['payments'][self.p_id].p_state = 'unpaid'
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 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
158
159        self.browser.open(
160            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-BALANCE'
161            % self.p_id)
162        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Not a balance payment' + ERROR_PART2)
163        self.payment.p_item = u'Balance'
164        self.browser.open(
165            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-PLUS-RETURNING'
166            % self.p_id)
167        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Balance payment' + ERROR_PART2)
168        self.payment.p_item = u'CERT1'
169
170        self.payment.p_category = 'schoolfee'
171        self.certificate.study_mode = 'special_pg_ft'
172        self.browser.open(
173            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING'
174            % self.p_id)
175        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Postgrad student' + ERROR_PART2)
176
177        self.certificate.study_mode = 'ug_ft'
178        self.browser.open(
179            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE-RETURNING'
180            % self.p_id)
181        self.assertEqual(self.browser.contents,
182            'PayeeName=Anna Tester~'
183            'Faculty=fac1~'
184            'Department=dep1~'
185            'Level=100~'
186            'ProgrammeType=CERT1~'
187            'StudyType=ug_ft~'
188            'Session=2004/2005~'
189            'PayeeID=%s~'
190            'Amount=1234.0~'
191            'FeeStatus=unpaid~'
192            'Semester=N/A~'
193            'PaymentType=School Fee~'
194            'MatricNumber=E1000000~'
195            'Email=aa@aa.ng~'
196            'PhoneNumber=1234' % self.p_id)
197
198    @external_test
199    def test_etranzact_query_history(self):
200
201        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
202            % self.CONFIRMATION_NO)
203        self.assertMatches('...Invalid or unsuccessful callback:...',
204                          self.browser.contents)
205        #self.assertMatches('...Wrong amount...',
206        #                  self.browser.contents)
207        #self.student['payments'][value].amount_auth = self.student[
208        #    'payments'][value].r_amount_approved
209        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
210        #    % self.CONFIRMATION_NO)
211        #self.assertMatches('...Wrong transaction id...',
212        #                  self.browser.contents)
213
214class EtranzactTestsApplicants(ApplicantsFullSetup):
215    """Tests for the Interswitch payment gateway.
216    """
217
218    layer = FunctionalLayer
219
220    CONFIRMATION_NO = '500856521315472785095'
221
222    def setUp(self):
223        super(EtranzactTestsApplicants, self).setUp()
224        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
225        self.browser.open(self.manage_path)
226        #IWorkflowState(self.student).setState('started')
227        super(EtranzactTestsApplicants, self).fill_correct_values()
228        self.browser.getControl(name="transition").value = ['start']
229        self.browser.getControl(name="form.nationality").value = ['NG']
230        self.browser.getControl(name="form.programme_type").value = ['direct']
231        self.browser.getControl("Save").click()
232        self.browser.getControl("Add online").click()
233        self.assertTrue(
234            'Session configuration object is not available'
235            in self.browser.contents)
236        configuration = SessionConfiguration()
237        configuration.academic_session = session_1
238        configuration.application_fee = 1000.0
239        self.app['configuration'].addSessionConfiguration(configuration)
240        self.browser.open(self.manage_path)
241        self.browser.getControl("Add online").click()
242        self.assertMatches('...ticket created...',
243                           self.browser.contents)
244        self.assertMatches('...Amount Authorized...',
245                           self.browser.contents)
246        self.assertMatches(
247            '...<span>1000.0</span>...',
248            self.browser.contents)
249        self.payment_url = self.browser.url
250        self.browser.open(self.manage_path)
251        ctrl = self.browser.getControl(name='val_id')
252        value = ctrl.options[0]
253        self.p_id = value
254
255    def test_webservice(self):
256        self.browser.open(
257            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
258            % self.p_id)
259        self.assertEqual(self.browser.contents,
260            'PayeeName=John Anthony Tester~'
261            'Faculty=N/A~'
262            'Department=N/A~'
263            'Level=N/A~'
264            'ProgrammeType=This is the app%s container~'
265            'StudyType=N/A~'
266            'Session=%s/%s~'
267            'PayeeID=%s~'
268            'Amount=1000.0~'
269            'FeeStatus=unpaid~'
270            'Semester=N/A~'
271            'PaymentType=Application Fee~'
272            'MatricNumber=%s~'
273            'Email=xx@yy.zz~'
274            'PhoneNumber=None' % (
275                session_1, session_1, session_1+1,
276                self.p_id,self.applicant.applicant_id))
277
278    @external_test
279    def test_etranzact_query_history(self):
280
281        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
282            % self.CONFIRMATION_NO)
283        self.assertMatches('...Invalid or unsuccessful callback:...',
284                          self.browser.contents)
285        #self.assertMatches('...Wrong amount...',
286        #                  self.browser.contents)
287        #self.applicant[value].amount_auth = self.applicant[
288        #    value].r_amount_approved
289        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
290        #    % self.CONFIRMATION_NO)
291        #self.assertMatches('...Wrong transaction id...',
292        #                  self.browser.contents)
Note: See TracBrowser for help on using the repository browser.