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

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

Fix tests.

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