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

Last change on this file since 8731 was 8731, checked in by Henrik Bettermann, 12 years ago

Change response string again and add missing webservice test.

  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1## $Id: tests.py 8731 2012-06-15 08:24:33Z 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.browser.open(self.payments_path)
53        IWorkflowState(self.student).setState('cleared')
54        self.browser.open(self.payments_path + '/addop')
55        self.browser.getControl("Create ticket").click()
56        self.assertMatches('...ticket created...',
57                           self.browser.contents)
58        ctrl = self.browser.getControl(name='val_id')
59        value = ctrl.options[0]
60        self.p_id = value
61        self.browser.getLink(value).click()
62        self.assertMatches('...Amount Authorized...',
63                           self.browser.contents)
64        self.payment_url = self.browser.url
65
66    def test_enterpin(self):
67        self.browser.getLink("Query eTranzact History").click()
68        self.assertMatches(
69            '...Confirmation Number (PIN):...',
70            self.browser.contents)
71
72    def test_webservice(self):
73        self.browser.open('http://localhost/app/feerequest?PAYEE_ID=%s' % self.p_id)
74        self.assertEqual(self.browser.contents,
75            'FULL_NAME=Anna Tester&MATRIC_NO=E1000000'
76            '&ACADEMIC_SESSION=2004/2005&PAYMENT_TYPE=School Fee&FACULTY=fac1'
77            '&DEPARTMENT=dep1&PROGRAMME_TYPE=CERT1'
78            '&RETURN_TYPE=%s&FEE_AMOUNT=40000.0'
79            '&TRANSACTION_STATUS=unpaid' % self.p_id)
80
81    @external_test
82    def test_etranzact_query_history(self):
83
84        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
85            % self.CONFIRMATION_NO)
86        self.assertMatches('...Invalid or unsuccessful callback:...',
87                          self.browser.contents)
88        #self.assertMatches('...Wrong amount...',
89        #                  self.browser.contents)
90        #self.student['payments'][value].amount_auth = self.student[
91        #    'payments'][value].r_amount_approved
92        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
93        #    % self.CONFIRMATION_NO)
94        #self.assertMatches('...Wrong transaction id...',
95        #                  self.browser.contents)
96
97class EtranzactTestsApplicants(ApplicantsFullSetup):
98    """Tests for the Interswitch payment gateway.
99    """
100
101    layer = FunctionalLayer
102
103    CONFIRMATION_NO = '500856521315472785095'
104
105    def setUp(self):
106        super(EtranzactTestsApplicants, self).setUp()
107        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
108        self.browser.open(self.manage_path)
109        #IWorkflowState(self.student).setState('started')
110        super(EtranzactTestsApplicants, self).fill_correct_values()
111        self.browser.getControl(name="transition").value = ['start']
112        self.browser.getControl("Save").click()
113        self.browser.getControl("Add online").click()
114        self.assertTrue(
115            'Session configuration object is not available'
116            in self.browser.contents)
117        configuration = SessionConfiguration()
118        configuration.academic_session = 2009
119        configuration.application_fee = 1000.0
120        self.app['configuration'].addSessionConfiguration(configuration)
121        self.browser.open(self.manage_path)
122        self.browser.getControl("Add online").click()
123        self.assertMatches('...ticket created...',
124                           self.browser.contents)
125        self.assertMatches('...Amount Authorized...',
126                           self.browser.contents)
127        self.assertMatches(
128            '...<span>1000.0</span>...',
129            self.browser.contents)
130        self.payment_url = self.browser.url
131
132    @external_test
133    def test_etranzact_query_history(self):
134
135        self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
136            % self.CONFIRMATION_NO)
137        self.assertMatches('...Invalid or unsuccessful callback:...',
138                          self.browser.contents)
139        #self.assertMatches('...Wrong amount...',
140        #                  self.browser.contents)
141        #self.applicant[value].amount_auth = self.applicant[
142        #    value].r_amount_approved
143        #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s'
144        #    % self.CONFIRMATION_NO)
145        #self.assertMatches('...Wrong transaction id...',
146        #                  self.browser.contents)
Note: See TracBrowser for help on using the repository browser.