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

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

Conform with the new eTranzact format.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: tests.py 10907 2014-01-14 06:54:26Z 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
23
24
25# Also run tests that send requests to external servers?
26#   If you enable this, please make sure the external services
27#   do exist really and are not bothered by being spammed by a test programme.
28EXTERNAL_TESTS = False
29
30def external_test(func):
31    if not EXTERNAL_TESTS:
32        myself = __file__
33        if myself.endswith('.pyc'):
34            myself = myself[:-2]
35        print "WARNING: external tests are skipped!"
36        print "WARNING: edit %s to enable them." % myself
37        return
38    return func
39
40class EtranzactTestsStudent(StudentsFullSetup):
41    """Tests for the eTranzact payment gateway.
42    """
43
44    layer = FunctionalLayer
45
46    CONFIRMATION_NO = '500856521315472785095'
47
48    def setUp(self):
49        super(EtranzactTestsStudent, self).setUp()
50        # Managers can add online payment tickets
51        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
52        self.app['configuration']['2004'].school_fee = 1234.0
53        self.browser.open(self.payments_path)
54        IWorkflowState(self.student).setState('cleared')
55        self.browser.open(self.payments_path + '/addop')
56        self.browser.getControl(name="form.p_category").value = ['schoolfee']
57        self.browser.getControl("Create ticket").click()
58        self.assertMatches('...ticket created...',
59                           self.browser.contents)
60
61        ctrl = self.browser.getControl(name='val_id')
62        value = ctrl.options[0]
63        self.p_id = value
64        self.browser.getLink(value).click()
65        self.assertMatches('...Amount Authorized...',
66                           self.browser.contents)
67        self.payment_url = self.browser.url
68
69    def test_enterpin(self):
70        self.browser.getLink("Query eTranzact History").click()
71        self.assertMatches(
72            '...Confirmation Number (PIN):...',
73            self.browser.contents)
74
75    def test_webservice(self):
76        self.browser.open('http://localhost/app/feerequest?PAYEE_ID=%s' % self.p_id)
77        self.assertEqual(self.browser.contents,
78            # Version 1
79            #'FULL_NAME=Anna Tester&'
80            #'FACULTY=fac1&'
81            #'DEPARTMENT=dep1&'
82            #'RETURN_TYPE=%s&'
83            #'PROGRAMME_TYPE=CERT1&'
84            #'PAYMENT_TYPE=School Fee&'
85            #'ACADEMIC_SESSION=2004/2005&'
86            #'MATRIC_NO=E1000000&'
87            #'FEE_AMOUNT=1234.0&'
88            #'TRANSACTION_STATUS=unpaid'
89
90            # Version 2
91            'PayeeName=Anna Tester~'
92            'Faculty=fac1~'
93            'Department=dep1~'
94            'Level=100~'
95            'ProgrammeType=CERT1~'
96            'StudyType=ug_ft~'
97            'Session=2004/2005~'
98            'PayeeID=%s~'
99            'Amount=1234.0~'
100            'FeeStatus=unpaid~'
101            #Semester=SECOND~
102            'PaymentType=School Fee~'
103            'MatricNumber=E1000000~'
104            'Email=aa@aa.ng~'
105            'PhoneNumber=1234' % self.p_id)
106
107        self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense')
108        self.assertEqual(self.browser.contents, '-1')
109
110    @external_test
111    def test_etranzact_query_history(self):
112
113        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
114            % self.CONFIRMATION_NO)
115        self.assertMatches('...Invalid or unsuccessful callback:...',
116                          self.browser.contents)
117        #self.assertMatches('...Wrong amount...',
118        #                  self.browser.contents)
119        #self.student['payments'][value].amount_auth = self.student[
120        #    'payments'][value].r_amount_approved
121        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
122        #    % self.CONFIRMATION_NO)
123        #self.assertMatches('...Wrong transaction id...',
124        #                  self.browser.contents)
125
126class EtranzactTestsApplicants(ApplicantsFullSetup):
127    """Tests for the Interswitch payment gateway.
128    """
129
130    layer = FunctionalLayer
131
132    CONFIRMATION_NO = '500856521315472785095'
133
134    def setUp(self):
135        super(EtranzactTestsApplicants, self).setUp()
136        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
137        self.browser.open(self.manage_path)
138        #IWorkflowState(self.student).setState('started')
139        super(EtranzactTestsApplicants, self).fill_correct_values()
140        self.browser.getControl(name="transition").value = ['start']
141        self.browser.getControl("Save").click()
142        self.browser.getControl("Add online").click()
143        self.assertTrue(
144            'Session configuration object is not available'
145            in self.browser.contents)
146        configuration = SessionConfiguration()
147        configuration.academic_session = 2009
148        configuration.application_fee = 1000.0
149        self.app['configuration'].addSessionConfiguration(configuration)
150        self.browser.open(self.manage_path)
151        self.browser.getControl("Add online").click()
152        self.assertMatches('...ticket created...',
153                           self.browser.contents)
154        self.assertMatches('...Amount Authorized...',
155                           self.browser.contents)
156        self.assertMatches(
157            '...<span>1000.0</span>...',
158            self.browser.contents)
159        self.payment_url = self.browser.url
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.applicant[value].amount_auth = self.applicant[
171        #    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)
Note: See TracBrowser for help on using the repository browser.