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

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

Output like

http://imopoly.mycampustest.ihems.net/EIMSPayeeIdDetails.aspx?PAYEE_ID=12NDCSTWK33Y256&PAYMENT_TYPE=TRANSCRIPT%20FEE

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1## $Id: tests.py 10978 2014-01-24 11:35:27Z 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 = 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 = ['schoolfee']
58        self.browser.getControl("Create ticket").click()
59        self.assertMatches('...ticket created...',
60                           self.browser.contents)
61
62        ctrl = self.browser.getControl(name='val_id')
63        value = ctrl.options[0]
64        self.p_id = value
65        self.browser.getLink(value).click()
66        self.assertMatches('...Amount Authorized...',
67                           self.browser.contents)
68        self.payment_url = self.browser.url
69
70    def test_enterpin(self):
71        self.browser.getLink("Query eTranzact History").click()
72        self.assertMatches(
73            '...Confirmation Number (PIN):...',
74            self.browser.contents)
75
76    def test_webservice(self):
77        self.browser.open(
78            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE'
79            % self.p_id)
80        self.assertEqual(self.browser.contents,
81            # Version 1
82            #'FULL_NAME=Anna Tester&'
83            #'FACULTY=fac1&'
84            #'DEPARTMENT=dep1&'
85            #'RETURN_TYPE=%s&'
86            #'PROGRAMME_TYPE=CERT1&'
87            #'PAYMENT_TYPE=School Fee&'
88            #'ACADEMIC_SESSION=2004/2005&'
89            #'MATRIC_NO=E1000000&'
90            #'FEE_AMOUNT=1234.0&'
91            #'TRANSACTION_STATUS=unpaid'
92
93            # Version 2
94            'PayeeName=Anna Tester~'
95            'Faculty=fac1~'
96            'Department=dep1~'
97            'Level=100~'
98            'ProgrammeType=CERT1~'
99            'StudyType=ug_ft~'
100            'Session=2004/2005~'
101            'PayeeID=%s~'
102            'Amount=1234.0~'
103            'FeeStatus=unpaid~'
104            'Semester=N/A~'
105            'PaymentType=School Fee~'
106            'MatricNumber=E1000000~'
107            'Email=aa@aa.ng~'
108            'PhoneNumber=1234' % self.p_id)
109
110        self.browser.open('http://localhost/app/feerequest')
111        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
112        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
113        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2)
114        self.browser.open(
115            'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE')
116        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2)
117        self.browser.open(
118            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE'
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'
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&PAYMENT_TYPE=ACCEPTANCE-FEE'
127            % self.p_id)
128        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
129        self.browser.open(
130            'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE'
131            % self.p_id)
132        self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2)
133
134
135    @external_test
136    def test_etranzact_query_history(self):
137
138        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
139            % self.CONFIRMATION_NO)
140        self.assertMatches('...Invalid or unsuccessful callback:...',
141                          self.browser.contents)
142        #self.assertMatches('...Wrong amount...',
143        #                  self.browser.contents)
144        #self.student['payments'][value].amount_auth = self.student[
145        #    'payments'][value].r_amount_approved
146        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
147        #    % self.CONFIRMATION_NO)
148        #self.assertMatches('...Wrong transaction id...',
149        #                  self.browser.contents)
150
151class EtranzactTestsApplicants(ApplicantsFullSetup):
152    """Tests for the Interswitch payment gateway.
153    """
154
155    layer = FunctionalLayer
156
157    CONFIRMATION_NO = '500856521315472785095'
158
159    def setUp(self):
160        super(EtranzactTestsApplicants, self).setUp()
161        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
162        self.browser.open(self.manage_path)
163        #IWorkflowState(self.student).setState('started')
164        super(EtranzactTestsApplicants, self).fill_correct_values()
165        self.browser.getControl(name="transition").value = ['start']
166        self.browser.getControl("Save").click()
167        self.browser.getControl("Add online").click()
168        self.assertTrue(
169            'Session configuration object is not available'
170            in self.browser.contents)
171        configuration = SessionConfiguration()
172        configuration.academic_session = 2009
173        configuration.application_fee = 1000.0
174        self.app['configuration'].addSessionConfiguration(configuration)
175        self.browser.open(self.manage_path)
176        self.browser.getControl("Add online").click()
177        self.assertMatches('...ticket created...',
178                           self.browser.contents)
179        self.assertMatches('...Amount Authorized...',
180                           self.browser.contents)
181        self.assertMatches(
182            '...<span>1000.0</span>...',
183            self.browser.contents)
184        self.payment_url = self.browser.url
185
186    @external_test
187    def test_etranzact_query_history(self):
188
189        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
190            % self.CONFIRMATION_NO)
191        self.assertMatches('...Invalid or unsuccessful callback:...',
192                          self.browser.contents)
193        #self.assertMatches('...Wrong amount...',
194        #                  self.browser.contents)
195        #self.applicant[value].amount_auth = self.applicant[
196        #    value].r_amount_approved
197        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
198        #    % self.CONFIRMATION_NO)
199        #self.assertMatches('...Wrong transaction id...',
200        #                  self.browser.contents)
Note: See TracBrowser for help on using the repository browser.