source: main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py @ 8293

Last change on this file since 8293 was 8267, checked in by Henrik Bettermann, 13 years ago

Optimize gataway tests. We can't test more.

  • Property svn:keywords set to Id
File size: 10.4 KB
Line 
1## $Id: test_browser.py 8267 2012-04-24 21:30:43Z 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##
18import os
19import shutil
20import tempfile
21from hurry.workflow.interfaces import IWorkflowState
22from zope.component.hooks import setSite, clearSite
23from waeup.kofa.app import University
24from waeup.kofa.students.tests.test_browser import StudentsFullSetup
25from waeup.kofa.testing import FunctionalTestCase
26from waeup.kofa.students.batching import StudentProcessor
27from waeup.uniben.students.batching import CustomStudentProcessor
28from waeup.uniben.testing import FunctionalLayer
29
30STUDENT_SAMPLE_DATA = open(
31    os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'),
32    'rb').read()
33
34STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split(
35    '\n')[0].split(',')
36
37class StudentProcessorTest(FunctionalTestCase):
38    """Perform some batching tests.
39    """
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(StudentProcessorTest, 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.processor_base = StudentProcessor()
61        self.processor = CustomStudentProcessor()
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(StudentProcessorTest, 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 have an empty column 'date_of_birth' in  the import file.
75        # The original processor will fail because 'date_of_birth' is required
76        # in the base package.
77        num, num_warns, fin_file, fail_file = self.processor_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 processor does not complain since 'date_of_birth' is
82        # not required in the custom package.
83        num, num_warns, fin_file, fail_file = self.processor.doImport(
84            self.csv_file, STUDENT_HEADER_FIELDS)
85        #print open(fail_file).read()
86        self.assertEqual(num_warns,0)
87        assert len(self.app['students'].keys()) == 3
88        shutil.rmtree(os.path.dirname(fin_file))
89
90
91class StudentUITests(StudentsFullSetup):
92    """Tests for customized student class views and pages
93    """
94
95    layer = FunctionalLayer
96
97    def test_manage_access(self):
98        # Managers can access the pages of students
99        # and can perform actions
100        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
101        # The student created in the base package is an ug student
102        self.browser.open(self.student_path)
103        self.browser.getLink("Clearance Data").click()
104        self.assertEqual(self.browser.headers['Status'], '200 Ok')
105        self.assertEqual(self.browser.url, self.clearance_path)
106        self.browser.getLink("Manage").click()
107        self.assertEqual(self.browser.headers['Status'], '200 Ok')
108        self.assertEqual(self.browser.url, self.manage_clearance_path)
109        self.browser.getControl(name="form.date_of_birth").value = '09/10/1961'
110        self.browser.getControl("Save").click()
111        self.assertMatches('...Form has been saved...',
112                           self.browser.contents)
113        self.assertMatches('...First Sitting Record...',
114                           self.browser.contents)
115        # Managers can open clearance slip of ug students
116        self.browser.open(self.student_path + '/clearance.pdf')
117        self.assertEqual(self.browser.headers['Status'], '200 Ok')
118        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
119        # There is no pg field in the clearance form
120        self.assertFalse('Second Higher Education Record'
121            in self.browser.contents)
122        # Now we change the study mode ...
123        self.certificate.study_mode = 'pg_ft'
124        self.browser.open(self.clearance_path)
125        # ... and additional pg clearance fields appear
126        self.assertMatches('...Second Higher Education Record...',
127                           self.browser.contents)
128        # But also fields from the ug form are displayed
129        self.assertMatches('...First Sitting Record...',
130                           self.browser.contents)
131        # Managers can open clearance slip of pg students
132        self.browser.open(self.student_path + '/clearance.pdf')
133        self.assertEqual(self.browser.headers['Status'], '200 Ok')
134        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
135
136    def test_manage_payments(self):
137        # Add missing configuration data
138        self.app['configuration']['2004'].gown_fee = 150.0
139        self.app['configuration']['2004'].transfer_fee = 90.0
140        self.app['configuration']['2004'].clearance_fee = 120.0
141        self.app['configuration']['2004'].maint_fee = 180.0
142
143        # Managers can add online payment tickets
144        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
145        self.browser.open(self.payments_path)
146        self.browser.getControl("Add online payment ticket").click()
147        self.browser.getControl("Create ticket").click()
148        self.assertMatches('...Amount could not be determined...',
149                           self.browser.contents)
150        IWorkflowState(self.student).setState('cleared')
151        self.browser.open(self.payments_path + '/addop')
152        self.browser.getControl("Create ticket").click()
153        self.assertMatches('...ticket created...',
154                           self.browser.contents)
155        ctrl = self.browser.getControl(name='val_id')
156        value = ctrl.options[0]
157        self.browser.getLink(value).click()
158        self.assertMatches('...Amount Authorized...',
159                           self.browser.contents)
160        # Managers can open payment slip
161        self.browser.getLink("Download payment slip").click()
162        self.assertEqual(self.browser.headers['Status'], '200 Ok')
163        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
164        # Set ticket paid
165        ticket = self.student['payments'].items()[0][1]
166        ticket.p_state = 'paid'
167        IWorkflowState(self.student).setState('returning')
168        self.browser.open(self.payments_path + '/addop')
169        self.browser.getControl("Create ticket").click()
170        self.assertMatches('...This type of payment has already been made...',
171                           self.browser.contents)
172        # Remove all payments so that we can add a school fee payment again
173        keys = [i for i in self.student['payments'].keys()]
174        for payment in keys:
175            del self.student['payments'][payment]
176        self.browser.open(self.payments_path + '/addop')
177        self.browser.getControl("Create ticket").click()
178        self.assertMatches('...ticket created...',
179                           self.browser.contents)
180        self.browser.open(self.payments_path + '/addop')
181        self.browser.getControl(name="form.p_category").value = ['gown']
182        self.browser.getControl("Create ticket").click()
183        self.browser.open(self.payments_path + '/addop')
184        self.browser.getControl(name="form.p_category").value = ['transfer']
185        self.browser.getControl("Create ticket").click()
186        self.browser.open(self.payments_path + '/addop')
187        self.browser.getControl(
188            name="form.p_category").value = ['bed_allocation']
189        self.browser.getControl("Create ticket").click()
190        self.browser.open(self.payments_path + '/addop')
191        self.browser.getControl(
192            name="form.p_category").value = ['hostel_maintenance']
193        self.browser.getControl("Create ticket").click()
194        self.browser.open(self.payments_path + '/addop')
195        self.browser.getControl(name="form.p_category").value = ['clearance']
196        self.browser.getControl("Create ticket").click()
197        self.certificate.study_mode = 'ug_pt'
198        self.browser.open(self.payments_path + '/addop')
199        self.browser.getControl(name="form.p_category").value = ['schoolfee']
200        self.browser.getControl("Create ticket").click()
201        self.assertMatches('...Amount could not be determined...',
202                           self.browser.contents)
203
204        # If the session configuration doesn't exist and error message will
205        # be shown
206        del self.app['configuration']['2004']
207        self.browser.open(self.payments_path)
208        self.browser.getControl("Add online payment ticket").click()
209        self.browser.getControl("Create ticket").click()
210        self.assertMatches('...Session configuration object is not...',
211                           self.browser.contents)
212
213    def test_student_access(self):
214        # Students can edit clearance data
215        IWorkflowState(self.student).setState('cleared')
216        self.student.clearance_locked = False
217        self.browser.open(self.login_path)
218        self.browser.getControl(name="form.login").value = self.student_id
219        self.browser.getControl(name="form.password").value = 'spwd'
220        self.browser.getControl("Login").click()
221        # Student can view and edit clearance data
222        self.browser.getLink("Clearance Data").click()
223        self.browser.getLink("Edit").click()
224        self.assertTrue('Save' in self.browser.contents)
225
226
Note: See TracBrowser for help on using the repository browser.