1 | ## $Id: tests.py 12973 2015-05-21 11:00:24Z 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, timedelta, date |
---|
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 | self.payment = self.student['payments'][self.value] |
---|
55 | |
---|
56 | def test_interswitch_form(self): |
---|
57 | # Manager can access InterswitchForm |
---|
58 | self.browser.getLink("CollegePAY", index=0).click() |
---|
59 | # The total amount to be processed by Interswitch |
---|
60 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
61 | self.assertMatches('...<input type="hidden" name="pay_item_id" />...', |
---|
62 | self.browser.contents) |
---|
63 | self.assertMatches('...Total Amount Authorized:...', |
---|
64 | self.browser.contents) |
---|
65 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
66 | self.assertMatches( |
---|
67 | '...<input type="hidden" name="amount" value="4000000" />...', |
---|
68 | self.browser.contents) |
---|
69 | |
---|
70 | # Create school fee ticket for returning students. Payment is made |
---|
71 | # for next session. |
---|
72 | current_payment_key = self.student['payments'].keys()[0] |
---|
73 | self.certificate.study_mode = u'ug_pt' |
---|
74 | IWorkflowState(self.student).setState('returning') |
---|
75 | configuration = createObject('waeup.SessionConfiguration') |
---|
76 | configuration.academic_session = 2005 |
---|
77 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
78 | self.browser.open(self.payments_path + '/addop') |
---|
79 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
80 | self.browser.getControl("Create ticket").click() |
---|
81 | |
---|
82 | ctrl = self.browser.getControl(name='val_id') |
---|
83 | value = ctrl.options[1] |
---|
84 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
85 | self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) |
---|
86 | self.browser.getLink(value).click() |
---|
87 | self.browser.getLink("CollegePAY", index=0).click() |
---|
88 | # Split amounts have been set. |
---|
89 | self.assertEqual(self.student['payments'][value].provider_amt, 0.0) |
---|
90 | self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) |
---|
91 | self.assertMatches('...<input type="hidden" name="pay_item_id" />...', |
---|
92 | self.browser.contents) |
---|
93 | self.assertMatches( |
---|
94 | '...<input type="hidden" name="amount" value="2000000" />...', |
---|
95 | self.browser.contents) |
---|
96 | |
---|
97 | def test_interswitch_form_ticket_expired(self): |
---|
98 | # Manager can access InterswitchForm |
---|
99 | self.browser.getLink("CollegePAY", index=0).click() |
---|
100 | self.assertMatches('...<input type="hidden" name="pay_item_id" />...', |
---|
101 | self.browser.contents) |
---|
102 | self.assertMatches('...Total Amount Authorized:...', |
---|
103 | self.browser.contents) |
---|
104 | self.assertEqual(self.student.current_mode, 'ug_ft') |
---|
105 | self.assertMatches( |
---|
106 | '...<input type="hidden" name="amount" value="4000000" />...', |
---|
107 | self.browser.contents) |
---|
108 | delta = timedelta(minutes=61) |
---|
109 | self.payment.creation_date -= delta |
---|
110 | self.browser.open(self.payment_url) |
---|
111 | self.browser.getLink("CollegePAY", index=0).click() |
---|
112 | self.assertMatches( |
---|
113 | '...This payment ticket is too old. Please create a new ticket...', |
---|
114 | self.browser.contents) |
---|
115 | delta = timedelta(minutes=2) |
---|
116 | self.payment.creation_date += delta |
---|
117 | self.browser.open(self.payment_url) |
---|
118 | self.browser.getLink("CollegePAY", index=0).click() |
---|
119 | self.assertMatches('...Total Amount Authorized:...', |
---|
120 | self.browser.contents) |
---|
121 | |
---|
122 | class InterswitchTestsApplicants(ApplicantsFullSetup): |
---|
123 | """Tests for the Interswitch payment gateway. |
---|
124 | """ |
---|
125 | |
---|
126 | layer = FunctionalLayer |
---|
127 | |
---|
128 | def setUp(self): |
---|
129 | super(InterswitchTestsApplicants, self).setUp() |
---|
130 | configuration = SessionConfiguration() |
---|
131 | configuration.academic_session = datetime.now().year - 2 |
---|
132 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
133 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
134 | self.browser.open(self.manage_path) |
---|
135 | #IWorkflowState(self.student).setState('started') |
---|
136 | super(InterswitchTestsApplicants, self).fill_correct_values() |
---|
137 | self.applicantscontainer.application_fee = 1000.0 |
---|
138 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
139 | self.browser.getControl(name="transition").value = ['start'] |
---|
140 | self.browser.getControl("Save").click() |
---|
141 | self.browser.getControl("Add online").click() |
---|
142 | self.assertMatches('...ticket created...', |
---|
143 | self.browser.contents) |
---|
144 | self.payment = self.applicant.values()[0] |
---|
145 | self.payment_url = self.browser.url |
---|
146 | |
---|
147 | def test_interswitch_form(self): |
---|
148 | self.assertMatches('...Amount Authorized...', |
---|
149 | self.browser.contents) |
---|
150 | self.assertMatches( |
---|
151 | '...<span>1000.0</span>...', |
---|
152 | self.browser.contents) |
---|
153 | # Manager can access InterswitchForm |
---|
154 | self.browser.getLink("CollegePAY", index=0).click() |
---|
155 | self.assertMatches('...Total Amount Authorized:...', |
---|
156 | self.browser.contents) |
---|
157 | self.assertMatches( |
---|
158 | '...<input type="hidden" name="amount" value="100000" />...', |
---|
159 | self.browser.contents) |
---|
160 | delta = timedelta(minutes=61) |
---|
161 | self.payment.creation_date -= delta |
---|
162 | self.browser.open(self.payment_url) |
---|
163 | self.browser.getLink("CollegePAY", index=0).click() |
---|
164 | self.assertMatches( |
---|
165 | '...This payment ticket is too old. Please create a new ticket...', |
---|
166 | self.browser.contents) |
---|
167 | delta = timedelta(minutes=2) |
---|
168 | self.payment.creation_date += delta |
---|
169 | self.browser.getLink("CollegePAY", index=0).click() |
---|
170 | self.assertMatches('...Total Amount Authorized:...', |
---|
171 | self.browser.contents) |
---|
172 | |
---|