source: main/waeup.aaua/trunk/src/waeup/aaua/interswitch/tests.py @ 14148

Last change on this file since 14148 was 11805, checked in by Henrik Bettermann, 10 years ago

Update tests.

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1## $Id: tests.py 11805 2014-09-24 06:06:51Z 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##
18import os
19from zope.component import getUtility
20from zope.catalog.interfaces import ICatalog
21from hurry.workflow.interfaces import IWorkflowState
22from waeup.kofa.students.tests.test_browser import StudentsFullSetup
23from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
24from waeup.kofa.configuration import SessionConfiguration
25from waeup.aaua.testing import FunctionalLayer
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.
30EXTERNAL_TESTS = False
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
42
43class InterswitchTestsStudents(StudentsFullSetup):
44    """Tests for the Interswitch payment gateway.
45    """
46
47    layer = FunctionalLayer
48
49    def setUp(self):
50        super(InterswitchTestsStudents, self).setUp()
51        self.certificate.school_fee_1 = 10000.0
52        self.certificate.school_fee_2 = 20000.0
53        self.certificate.study_mode = 'ug_pt'
54        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
55        self.browser.open(self.payments_path)
56        IWorkflowState(self.student).setState('cleared')
57        self.browser.open(self.payments_path + '/addop')
58        self.browser.getControl(name="form.p_category").value = ['schoolfee']
59        self.browser.getControl("Create ticket").click()
60        self.assertMatches('...ticket created...',
61                           self.browser.contents)
62        ctrl = self.browser.getControl(name='val_id')
63        self.value = ctrl.options[0]
64        self.browser.getLink(self.value).click()
65        self.assertMatches('...Amount Authorized...',
66                           self.browser.contents)
67        self.assertTrue(
68            '<span>10000.0</span>' in self.browser.contents)
69        self.payment_url = self.browser.url
70
71    def test_interswitch_form(self):
72
73        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
74        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
75        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0)
76        # Manager can access InterswitchForm for the created school fee ticket
77        self.browser.getLink("CollegePAY", index=0).click()
78        # Split amounts have been set
79        self.assertEqual(self.student['payments'][self.value].provider_amt, 3000.0)
80        self.assertEqual(self.student['payments'][self.value].gateway_amt, 150.0)
81        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0)
82        self.assertMatches('...Total Amount Authorized:...',
83                           self.browser.contents)
84        self.assertTrue(
85            '<input type="hidden" name="amount" value="1000000" />'
86            in self.browser.contents)
87        self.assertTrue(
88            'item_name="School Fee" item_amt="685000" bank_id="89" acct_num="0321100000000046"'
89            in self.browser.contents)
90        self.assertTrue(
91            'item_name="BT Education" item_amt="300000" bank_id="117" acct_num="6012015294"'
92            in self.browser.contents)
93
94        self.certificate.study_mode = 'ug_sw'
95        self.browser.open(self.payments_path + '/addop')
96        self.browser.getControl(name="form.p_category").value = ['schoolfee']
97        self.browser.getControl("Create ticket").click()
98        ctrl = self.browser.getControl(name='val_id')
99        self.value = ctrl.options[1]
100        self.browser.getLink(self.value).click()
101        self.assertTrue(
102            '<span>10000.0</span>' in self.browser.contents)
103        self.browser.getLink("CollegePAY", index=0).click()
104        self.assertTrue(
105            '<input type="hidden" name="amount" value="1000000" />'
106            in self.browser.contents)
107        self.assertTrue(
108            'item_name="School Fee" item_amt="685000" bank_id="120" acct_num="2461770000021"'
109            in self.browser.contents)
110
111        self.certificate.ratio = 0.5
112        self.browser.open(self.payments_path + '/addop')
113        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
114        self.browser.getControl("Create ticket").click()
115        ctrl = self.browser.getControl(name='val_id')
116        self.value = ctrl.options[2]
117        self.browser.getLink(self.value).click()
118        self.assertTrue(
119            '<span>5000.0</span>' in self.browser.contents)
120        self.browser.getLink("CollegePAY", index=0).click()
121        self.assertTrue(
122            '<input type="hidden" name="amount" value="500000" />'
123            in self.browser.contents)
124        self.assertTrue(
125            'item_name="School Fee 2nd instalment" item_amt="485000" bank_id="120" acct_num="2461770000021"'
126            in self.browser.contents)
Note: See TracBrowser for help on using the repository browser.