## $Id: tests.py 9370 2012-10-20 19:58:10Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
from hurry.workflow.interfaces import IWorkflowState
from waeup.kofa.students.tests.test_browser import StudentsFullSetup
from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
from waeup.kofa.configuration import SessionConfiguration
from waeup.kwarapoly.testing import FunctionalLayer
# Also run tests that send requests to external servers?
# If you enable this, please make sure the external services
# do exist really and are not bothered by being spammed by a test programme.
EXTERNAL_TESTS = False
def external_test(func):
if not EXTERNAL_TESTS:
myself = __file__
if myself.endswith('.pyc'):
myself = myself[:-2]
print "WARNING: external tests are skipped!"
print "WARNING: edit %s to enable them." % myself
return
return func
class InterswitchTestsStudents(StudentsFullSetup):
"""Tests for the Interswitch payment gateway.
"""
layer = FunctionalLayer
def setUp(self):
super(InterswitchTestsStudents, self).setUp()
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open(self.payments_path)
IWorkflowState(self.student).setState('cleared')
self.browser.open(self.payments_path + '/addop')
self.browser.getControl("Create ticket").click()
# def callback_url(self, payment_url, resp, apprAmt):
# return payment_url + (
# '/isw_callback?echo=' +
# '&resp=%s' +
# '&desc=Something went wrong' +
# '&txnRef=p1331792385335' +
# '&payRef=' + '&retRef=' +
# '&cardNum=0' +
# '&apprAmt=%s' +
# '&url=http://xyz') % (resp, apprAmt)
def test_interswitch_form(self):
# In the setup method we created the ticket
self.assertMatches('...ticket created...',
self.browser.contents)
ctrl = self.browser.getControl(name='val_id')
value = ctrl.options[0]
self.browser.getLink(value).click()
self.assertMatches('...Amount Authorized...',
self.browser.contents)
self.assertMatches(
'...12495.0...',
self.browser.contents)
self.payment_url = self.browser.url
# Manager can access InterswitchForm
self.browser.getLink("CollegePAY", index=0).click()
self.assertMatches('...Total Amount Authorized:...',
self.browser.contents)
self.assertMatches(
'......',
self.browser.contents)
self.assertMatches(
'...item_name="schoolfee" item_amt="1044500" bank_id="117" acct_num="6216801033"...',
self.browser.contents)
self.assertMatches(
'...item_name="KwaraPoly Split" item_amt="140000" bank_id="117" acct_num="6216801058"...',
self.browser.contents)
self.assertMatches(
'...item_name="BT Education" item_amt="50000" bank_id="31" acct_num="0026781725"...',
self.browser.contents)
# @external_test
# def test_callback(self):
# Manager can call callback manually
# self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
# self.assertMatches('...Unsuccessful callback: Something went wrong...',
# self.browser.contents)
# self.assertMatches('...Failed...',
# self.browser.contents)
# self.browser.open(self.payment_url + '/isw_callback')
# self.assertMatches('...Unsuccessful callback: Incomplete query string...',
# self.browser.contents)
# self.assertMatches('...Failed...',
# self.browser.contents)
# self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
# self.assertMatches('...Wrong amount...',
# self.browser.contents)
# self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
# self.assertMatches('...Valid callback received...',
# self.browser.contents)
@external_test
def test_webservice(self):
self.browser.open(self.payment_url + '/request_webservice')
self.assertMatches('...Unsuccessful callback...',
self.browser.contents)
# The payment is now in state failed
self.assertMatches('...Failed...',
self.browser.contents)
class InterswitchTestsApplicants(ApplicantsFullSetup):
"""Tests for the Interswitch payment gateway.
"""
layer = FunctionalLayer
def setUp(self):
super(InterswitchTestsApplicants, self).setUp()
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open(self.manage_path)
#IWorkflowState(self.student).setState('started')
super(InterswitchTestsApplicants, self).fill_correct_values()
self.applicantscontainer.application_fee = 1000.0
self.browser.getControl(name="transition").value = ['start']
self.browser.getControl("Save").click()
self.browser.getControl("Add online").click()
self.assertMatches('...ticket created...',
self.browser.contents)
#ctrl = self.browser.getControl(name='val_id')
#value = ctrl.options[0]
#self.browser.getLink(value).click()
self.assertMatches('...Amount Authorized...',
self.browser.contents)
self.assertMatches(
'...1000.0...',
self.browser.contents)
self.payment_url = self.browser.url
def test_interswitch_form(self):
# Manager can access InterswitchForm
self.browser.getLink("CollegePAY", index=0).click()
self.assertMatches('...Total Amount Authorized:...',
self.browser.contents)
self.assertMatches(
'......',
self.browser.contents)
@external_test
def test_webservice(self):
self.browser.open(self.payment_url + '/request_webservice')
self.assertMatches('...Unsuccessful callback...',
self.browser.contents)
# The payment is now in state failed
self.assertMatches('...Failed...',
self.browser.contents)