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

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

Little cause but big effect: these tests had to adjusted for the changes in the previous revision.

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