## $Id: tests.py 13015 2015-05-28 14:13:36Z 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 ## import os from datetime import datetime, timedelta, date from zope.component import createObject, getUtility from zope.catalog.interfaces import ICatalog 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 kofacustom.nigeria.testing import FunctionalLayer 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.student.nationality = u'NG' self.browser.open(self.payments_path + '/addop') self.browser.getControl(name="form.p_category").value = ['schoolfee'] self.browser.getControl("Create ticket").click() self.assertMatches('...ticket created...', self.browser.contents) ctrl = self.browser.getControl(name='val_id') self.value = ctrl.options[0] self.browser.getLink(self.value).click() self.assertMatches('...Amount Authorized...', self.browser.contents) self.assertMatches( '...40000.0...', self.browser.contents) self.payment_url = self.browser.url self.payment = self.student['payments'][self.value] def test_interswitch_form(self): # Manager can access InterswitchForm self.browser.getLink("CollegePAY", index=0).click() # The total amount to be processed by Interswitch # has been reduced by the Interswitch fee of 150 Nairas self.assertMatches('......', self.browser.contents) self.assertMatches('...Total Amount Authorized:...', self.browser.contents) self.assertEqual(self.student.current_mode, 'ug_ft') self.assertMatches( '......', self.browser.contents) # Create school fee ticket for returning students. Payment is made # for next session. current_payment_key = self.student['payments'].keys()[0] self.certificate.study_mode = u'ug_pt' IWorkflowState(self.student).setState('returning') configuration = createObject('waeup.SessionConfiguration') configuration.academic_session = 2005 self.app['configuration'].addSessionConfiguration(configuration) self.browser.open(self.payments_path + '/addop') self.browser.getControl(name="form.p_category").value = ['schoolfee'] self.browser.getControl("Create ticket").click() ctrl = self.browser.getControl(name='val_id') value = ctrl.options[1] self.assertEqual(self.student['payments'][value].provider_amt, 0.0) self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) self.browser.getLink(value).click() self.browser.getLink("CollegePAY", index=0).click() # Split amounts have been set. self.assertEqual(self.student['payments'][value].provider_amt, 0.0) self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) self.assertMatches('......', self.browser.contents) self.assertMatches( '......', self.browser.contents) def test_interswitch_form_ticket_expired(self): # Manager can access InterswitchForm self.browser.getLink("CollegePAY", index=0).click() self.assertMatches('......', self.browser.contents) self.assertMatches('...Total Amount Authorized:...', self.browser.contents) self.assertEqual(self.student.current_mode, 'ug_ft') self.assertMatches( '......', self.browser.contents) delta = timedelta(days=8) self.payment.creation_date -= delta self.browser.open(self.payment_url) self.browser.getLink("CollegePAY", index=0).click() self.assertMatches( '...This payment ticket is too old. Please create a new ticket...', self.browser.contents) delta = timedelta(days=2) self.payment.creation_date += delta self.browser.open(self.payment_url) self.browser.getLink("CollegePAY", index=0).click() self.assertMatches('...Total Amount Authorized:...', self.browser.contents) class InterswitchTestsApplicants(ApplicantsFullSetup): """Tests for the Interswitch payment gateway. """ layer = FunctionalLayer def setUp(self): super(InterswitchTestsApplicants, self).setUp() configuration = SessionConfiguration() configuration.academic_session = datetime.now().year - 2 self.app['configuration'].addSessionConfiguration(configuration) 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="form.nationality").value = ['NG'] 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) self.payment = self.applicant.values()[0] self.payment_url = self.browser.url def test_interswitch_form(self): self.assertMatches('...Amount Authorized...', self.browser.contents) self.assertMatches( '...1000.0...', self.browser.contents) # Manager can access InterswitchForm self.browser.getLink("CollegePAY", index=0).click() self.assertMatches('...Total Amount Authorized:...', self.browser.contents) self.assertMatches( '......', self.browser.contents) delta = timedelta(days=8) self.payment.creation_date -= delta self.browser.open(self.payment_url) self.browser.getLink("CollegePAY", index=0).click() self.assertMatches( '...This payment ticket is too old. Please create a new ticket...', self.browser.contents) delta = timedelta(days=2) self.payment.creation_date += delta self.browser.getLink("CollegePAY", index=0).click() self.assertMatches('...Total Amount Authorized:...', self.browser.contents)