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

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

Add webservice regression test.

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