[11640] | 1 | ## $Id: tests.py 11767 2014-07-23 12:42:22Z 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 | ## |
---|
| 18 | import os |
---|
| 19 | from datetime import datetime |
---|
| 20 | from zope.component import createObject, getUtility |
---|
| 21 | from zope.catalog.interfaces import ICatalog |
---|
| 22 | from hurry.workflow.interfaces import IWorkflowState |
---|
| 23 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
| 24 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 25 | from waeup.kofa.configuration import SessionConfiguration |
---|
| 26 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
| 27 | |
---|
| 28 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
| 29 | """Tests for the Interswitch payment gateway. |
---|
| 30 | """ |
---|
| 31 | |
---|
| 32 | layer = FunctionalLayer |
---|
| 33 | |
---|
| 34 | def setUp(self): |
---|
| 35 | super(InterswitchTestsStudents, self).setUp() |
---|
| 36 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 37 | self.browser.open(self.payments_path) |
---|
| 38 | IWorkflowState(self.student).setState('cleared') |
---|
| 39 | self.student.nationality = u'NG' |
---|
| 40 | self.browser.open(self.payments_path + '/addop') |
---|
| 41 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 42 | self.browser.getControl("Create ticket").click() |
---|
| 43 | self.assertMatches('...ticket created...', |
---|
| 44 | self.browser.contents) |
---|
| 45 | ctrl = self.browser.getControl(name='val_id') |
---|
| 46 | self.value = ctrl.options[0] |
---|
| 47 | self.browser.getLink(self.value).click() |
---|
| 48 | self.assertMatches('...Amount Authorized...', |
---|
| 49 | self.browser.contents) |
---|
| 50 | self.assertMatches( |
---|
| 51 | '...<span>40000.0</span>...', |
---|
| 52 | self.browser.contents) |
---|
| 53 | self.payment_url = self.browser.url |
---|
| 54 | |
---|
| 55 | def test_interswitch_form(self): |
---|
| 56 | # Manager can access InterswitchForm |
---|
| 57 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 58 | # The total amount to be processed by Interswitch |
---|
| 59 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 60 | self.assertMatches('...<input type="hidden" name="pay_item_id" />...', |
---|
| 61 | self.browser.contents) |
---|
| 62 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 63 | self.browser.contents) |
---|
| 64 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
| 65 | self.assertMatches( |
---|
[11767] | 66 | '...<input type="hidden" name="amount" value="4000000" />...', |
---|
[11640] | 67 | self.browser.contents) |
---|
| 68 | |
---|
| 69 | # Create school fee ticket for returning students. Payment is made |
---|
| 70 | # for next session. |
---|
| 71 | current_payment_key = self.student['payments'].keys()[0] |
---|
| 72 | self.certificate.study_mode = u'ug_pt' |
---|
| 73 | IWorkflowState(self.student).setState('returning') |
---|
| 74 | configuration = createObject('waeup.SessionConfiguration') |
---|
| 75 | configuration.academic_session = 2005 |
---|
| 76 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
| 77 | self.browser.open(self.payments_path + '/addop') |
---|
| 78 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
| 79 | self.browser.getControl("Create ticket").click() |
---|
| 80 | |
---|
| 81 | ctrl = self.browser.getControl(name='val_id') |
---|
| 82 | value = ctrl.options[1] |
---|
| 83 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
| 84 | self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) |
---|
| 85 | self.browser.getLink(value).click() |
---|
| 86 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 87 | # Split amounts have been set. |
---|
| 88 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
| 89 | self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) |
---|
| 90 | self.assertMatches('...<input type="hidden" name="pay_item_id" />...', |
---|
| 91 | self.browser.contents) |
---|
| 92 | self.assertMatches( |
---|
[11767] | 93 | '...<input type="hidden" name="amount" value="2000000" />...', |
---|
[11640] | 94 | self.browser.contents) |
---|
| 95 | |
---|
| 96 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
| 97 | """Tests for the Interswitch payment gateway. |
---|
| 98 | """ |
---|
| 99 | |
---|
| 100 | layer = FunctionalLayer |
---|
| 101 | |
---|
| 102 | def setUp(self): |
---|
| 103 | super(InterswitchTestsApplicants, self).setUp() |
---|
| 104 | configuration = SessionConfiguration() |
---|
| 105 | configuration.academic_session = datetime.now().year - 2 |
---|
| 106 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
| 107 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 108 | self.browser.open(self.manage_path) |
---|
| 109 | #IWorkflowState(self.student).setState('started') |
---|
| 110 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
| 111 | self.applicantscontainer.application_fee = 1000.0 |
---|
| 112 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
| 113 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 114 | self.browser.getControl("Save").click() |
---|
| 115 | self.browser.getControl("Add online").click() |
---|
| 116 | self.assertMatches('...ticket created...', |
---|
| 117 | self.browser.contents) |
---|
| 118 | #ctrl = self.browser.getControl(name='val_id') |
---|
| 119 | #value = ctrl.options[0] |
---|
| 120 | #self.browser.getLink(value).click() |
---|
| 121 | self.payment_url = self.browser.url |
---|
| 122 | |
---|
| 123 | def test_interswitch_form(self): |
---|
| 124 | self.assertMatches('...Amount Authorized...', |
---|
| 125 | self.browser.contents) |
---|
| 126 | self.assertMatches( |
---|
| 127 | '...<span>1000.0</span>...', |
---|
| 128 | self.browser.contents) |
---|
| 129 | # Manager can access InterswitchForm |
---|
| 130 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 131 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 132 | self.browser.contents) |
---|
| 133 | self.assertMatches( |
---|
[11767] | 134 | '...<input type="hidden" name="amount" value="100000" />...', |
---|
[11640] | 135 | self.browser.contents) |
---|
| 136 | |
---|