source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py @ 11846

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

Add interswitch module.

Disable clearance payments.

File size: 4.0 KB
Line 
1## $Id: tests.py 11813 2014-09-24 06:36:19Z 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 datetime import datetime, date, timedelta
20from zope.component import createObject, getUtility
21from zope.catalog.interfaces import ICatalog
22from hurry.workflow.interfaces import IWorkflowState
23from waeup.kofa.students.tests.test_browser import StudentsFullSetup
24from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
25from waeup.kofa.configuration import SessionConfiguration
26from waeup.aaue.testing import FunctionalLayer
27
28# Also run tests that send requests to external servers?
29#   If you enable this, please make sure the external services
30#   do exist really and are not bothered by being spammed by a test programme.
31EXTERNAL_TESTS = False
32
33def external_test(func):
34    if not EXTERNAL_TESTS:
35        myself = __file__
36        if myself.endswith('.pyc'):
37            myself = myself[:-2]
38        print "WARNING: external tests are skipped!"
39        print "WARNING: edit %s to enable them." % myself
40        return
41    return func
42
43
44class InterswitchTestsApplicants(ApplicantsFullSetup):
45    """Tests for the Interswitch payment gateway.
46    """
47
48    layer = FunctionalLayer
49
50    def setUp(self):
51        super(InterswitchTestsApplicants, self).setUp()
52        configuration = SessionConfiguration()
53        configuration.academic_session = datetime.now().year - 2
54        self.app['configuration'].addSessionConfiguration(configuration)
55        self.configuration = configuration
56        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
57        self.browser.open(self.manage_path)
58        #IWorkflowState(self.student).setState('started')
59        super(InterswitchTestsApplicants, self).fill_correct_values()
60        self.browser.getControl(name="form.programme_type").value = ['regular']
61        self.applicantscontainer.application_fee = 1000.0
62        self.browser.getControl(name="form.nationality").value = ['NG']
63        self.browser.getControl(name="transition").value = ['start']
64        self.browser.getControl("Save").click()
65        self.browser.getControl("Add online").click()
66        self.assertMatches('...ticket created...',
67                           self.browser.contents)
68        #ctrl = self.browser.getControl(name='val_id')
69        #value = ctrl.options[0]
70        #self.browser.getLink(value).click()
71        self.assertMatches('...Amount Authorized...',
72                           self.browser.contents)
73        self.assertMatches(
74            '...<span>1000.0</span>...',
75            self.browser.contents)
76        self.payment_url = self.browser.url
77
78
79    def test_interswitch_form(self):
80
81        # Manager can access InterswitchForm
82        self.browser.getLink("CollegePAY", index=0).click()
83        self.assertMatches('...Total Amount Authorized:...',
84                           self.browser.contents)
85        self.assertMatches(
86            '...<input type="hidden" name="amount" value="100000" />...',
87            self.browser.contents)
88
89    @external_test
90    def test_webservice(self):
91
92        self.browser.open(self.payment_url + '/request_webservice')
93        self.assertMatches('...Unsuccessful callback...',
94                          self.browser.contents)
95        # The payment is now in state failed
96        self.assertMatches('...<span>Failed</span>...',
97                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.