1 | ## $Id: tests.py 7822 2012-03-09 07:26:31Z 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 | import shutil |
---|
20 | import tempfile |
---|
21 | from zope.component.hooks import setSite, clearSite |
---|
22 | from waeup.kofa.app import University |
---|
23 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
24 | from waeup.kofa.testing import FunctionalTestCase |
---|
25 | from waeup.kofa.students.batching import StudentProcessor as StudentProcessorBase |
---|
26 | from waeup.custom.students.batching import StudentProcessor |
---|
27 | from waeup.custom.testing import FunctionalLayer |
---|
28 | from waeup.custom.configuration import SessionConfiguration |
---|
29 | |
---|
30 | STUDENT_SAMPLE_DATA = open( |
---|
31 | os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'), |
---|
32 | 'rb').read() |
---|
33 | |
---|
34 | STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split( |
---|
35 | '\n')[0].split(',') |
---|
36 | |
---|
37 | class StudentImporterTest(FunctionalTestCase): |
---|
38 | """Perform some batching tests. |
---|
39 | """ |
---|
40 | |
---|
41 | layer = FunctionalLayer |
---|
42 | |
---|
43 | def setUp(self): |
---|
44 | super(StudentImporterTest, self).setUp() |
---|
45 | # Setup a sample site for each test |
---|
46 | app = University() |
---|
47 | self.dc_root = tempfile.mkdtemp() |
---|
48 | app['datacenter'].setStoragePath(self.dc_root) |
---|
49 | |
---|
50 | # Prepopulate the ZODB... |
---|
51 | self.getRootFolder()['app'] = app |
---|
52 | # we add the site immediately after creation to the |
---|
53 | # ZODB. Catalogs and other local utilities are not setup |
---|
54 | # before that step. |
---|
55 | self.app = self.getRootFolder()['app'] |
---|
56 | # Set site here. Some of the following setup code might need |
---|
57 | # to access grok.getSite() and should get our new app then |
---|
58 | setSite(app) |
---|
59 | |
---|
60 | self.importer_base = StudentProcessorBase() |
---|
61 | self.importer = StudentProcessor() |
---|
62 | self.workdir = tempfile.mkdtemp() |
---|
63 | self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv') |
---|
64 | open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA) |
---|
65 | |
---|
66 | def tearDown(self): |
---|
67 | super(StudentImporterTest, self).tearDown() |
---|
68 | shutil.rmtree(self.workdir) |
---|
69 | shutil.rmtree(self.dc_root) |
---|
70 | clearSite() |
---|
71 | return |
---|
72 | |
---|
73 | def test_import(self): |
---|
74 | # We added empty columns 'nationality' and 'lga' to the import file. |
---|
75 | # The original importer will fail because these fields are required |
---|
76 | # in the base package. |
---|
77 | num, num_warns, fin_file, fail_file = self.importer_base.doImport( |
---|
78 | self.csv_file, STUDENT_HEADER_FIELDS) |
---|
79 | self.assertEqual(num_warns,3) |
---|
80 | assert len(self.app['students'].keys()) == 0 |
---|
81 | # The customized importer does not complain since both fields are |
---|
82 | # not required in the custom package. |
---|
83 | num, num_warns, fin_file, fail_file = self.importer.doImport( |
---|
84 | self.csv_file, STUDENT_HEADER_FIELDS) |
---|
85 | self.assertEqual(num_warns,0) |
---|
86 | assert len(self.app['students'].keys()) == 3 |
---|
87 | shutil.rmtree(os.path.dirname(fin_file)) |
---|
88 | |
---|
89 | |
---|
90 | class StudentUITests(StudentsFullSetup): |
---|
91 | """Tests for customized student class views and pages |
---|
92 | """ |
---|
93 | |
---|
94 | layer = FunctionalLayer |
---|
95 | |
---|
96 | def test_manage_payments(self): |
---|
97 | # Add missing configuration data |
---|
98 | self.app['configuration']['2004'].gown_fee = 150 |
---|
99 | self.app['configuration']['2004'].transfer_fee = 90 |
---|
100 | self.app['configuration']['2004'].clearance_fee = 120 |
---|
101 | self.app['configuration']['2004'].maint_fee = 180 |
---|
102 | |
---|
103 | # Managers can add online payment tickets |
---|
104 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
105 | self.browser.open(self.payments_student_path) |
---|
106 | self.browser.getControl("Add online payment ticket").click() |
---|
107 | self.browser.getControl("Create ticket").click() |
---|
108 | self.assertMatches('...Amount could not be determined...', |
---|
109 | self.browser.contents) |
---|
110 | self.browser.open(self.manage_student_path) |
---|
111 | self.browser.getControl(name="transition").value = ['admit'] |
---|
112 | self.browser.getControl("Save").click() |
---|
113 | self.browser.getControl(name="transition").value = ['start_clearance'] |
---|
114 | self.browser.getControl("Save").click() |
---|
115 | self.browser.getControl(name="transition").value = ['request_clearance'] |
---|
116 | self.browser.getControl("Save").click() |
---|
117 | self.browser.getControl(name="transition").value = ['clear'] |
---|
118 | self.browser.getControl("Save").click() |
---|
119 | self.browser.open(self.payments_student_path + '/addop') |
---|
120 | self.browser.getControl("Create ticket").click() |
---|
121 | self.assertMatches('...ticket created...', |
---|
122 | self.browser.contents) |
---|
123 | ctrl = self.browser.getControl(name='val_id') |
---|
124 | value = ctrl.options[0] |
---|
125 | self.browser.getLink(value).click() |
---|
126 | self.assertMatches('...Amount Authorized...', |
---|
127 | self.browser.contents) |
---|
128 | #payment_url = self.browser.url |
---|
129 | #self.browser.open(payment_url) |
---|
130 | self.browser.getLink("Request callback").click() |
---|
131 | self.assertMatches('...Valid callback received...', |
---|
132 | self.browser.contents) |
---|
133 | self.browser.open(self.manage_student_path) |
---|
134 | self.browser.getControl( |
---|
135 | name="transition").value = ['pay_first_school_fee'] |
---|
136 | self.browser.getControl("Save").click() |
---|
137 | # Reset to returning |
---|
138 | self.browser.getControl(name="transition").value = ['reset6'] |
---|
139 | self.browser.getControl("Save").click() |
---|
140 | self.browser.open(self.payments_student_path + '/addop') |
---|
141 | self.browser.getControl("Create ticket").click() |
---|
142 | self.assertMatches('...This type of payment has already been made...', |
---|
143 | self.browser.contents) |
---|
144 | # Remove all payments so that we can add a school fee payment again |
---|
145 | for payment in self.student['payments'].keys(): |
---|
146 | del self.student['payments'][payment] |
---|
147 | self.browser.open(self.payments_student_path + '/addop') |
---|
148 | self.browser.getControl("Create ticket").click() |
---|
149 | self.assertMatches('...ticket created...', |
---|
150 | self.browser.contents) |
---|
151 | self.browser.open(self.payments_student_path + '/addop') |
---|
152 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
153 | self.browser.getControl("Create ticket").click() |
---|
154 | self.browser.open(self.payments_student_path + '/addop') |
---|
155 | self.browser.getControl(name="form.p_category").value = ['transfer'] |
---|
156 | self.browser.getControl("Create ticket").click() |
---|
157 | self.browser.open(self.payments_student_path + '/addop') |
---|
158 | self.browser.getControl( |
---|
159 | name="form.p_category").value = ['bed_allocation'] |
---|
160 | self.browser.getControl("Create ticket").click() |
---|
161 | self.browser.open(self.payments_student_path + '/addop') |
---|
162 | self.browser.getControl( |
---|
163 | name="form.p_category").value = ['hostel_maintenance'] |
---|
164 | self.browser.getControl("Create ticket").click() |
---|
165 | self.browser.open(self.payments_student_path + '/addop') |
---|
166 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
167 | self.browser.getControl("Create ticket").click() |
---|
168 | self.certificate.study_mode = 'ug_pt' |
---|
169 | self.browser.open(self.payments_student_path + '/addop') |
---|
170 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
171 | self.browser.getControl("Create ticket").click() |
---|
172 | self.assertMatches('...Amount could not be determined...', |
---|
173 | self.browser.contents) |
---|
174 | |
---|
175 | # If the session configuration doesn't exist and error message will |
---|
176 | # be shown |
---|
177 | del self.app['configuration']['2004'] |
---|
178 | self.browser.open(self.payments_student_path) |
---|
179 | self.browser.getControl("Add online payment ticket").click() |
---|
180 | self.browser.getControl("Create ticket").click() |
---|
181 | self.assertMatches('...Session configuration object is not...', |
---|
182 | self.browser.contents) |
---|
183 | |
---|
184 | |
---|