source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py @ 11597

Last change on this file since 11597 was 11597, checked in by Henrik Bettermann, 11 years ago

View and viewlet added which enable students to generate a matric number.

  • Property svn:keywords set to Id
File size: 16.8 KB
Line 
1## $Id: test_browser.py 11597 2014-04-23 10:29:32Z 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 shutil
19import tempfile
20import grok
21from mechanize import LinkNotFoundError
22from hurry.workflow.interfaces import IWorkflowState
23from zope.component.hooks import setSite, clearSite
24from zope.component import getUtility, createObject
25from waeup.kofa.app import University
26from waeup.kofa.students.tests.test_browser import StudentsFullSetup
27from waeup.kofa.students.accommodation import BedTicket
28from waeup.kofa.testing import FunctionalTestCase
29from waeup.aaue.testing import FunctionalLayer
30
31
32class StudentProcessorTest(FunctionalTestCase):
33    """Perform some batching tests.
34    """
35
36    layer = FunctionalLayer
37
38    def setUp(self):
39        super(StudentProcessorTest, self).setUp()
40        # Setup a sample site for each test
41        app = University()
42        self.dc_root = tempfile.mkdtemp()
43        app['datacenter'].setStoragePath(self.dc_root)
44
45        # Prepopulate the ZODB...
46        self.getRootFolder()['app'] = app
47        # we add the site immediately after creation to the
48        # ZODB. Catalogs and other local utilities are not setup
49        # before that step.
50        self.app = self.getRootFolder()['app']
51        # Set site here. Some of the following setup code might need
52        # to access grok.getSite() and should get our new app then
53        setSite(app)
54
55
56    def tearDown(self):
57        super(StudentProcessorTest, self).tearDown()
58        shutil.rmtree(self.workdir)
59        shutil.rmtree(self.dc_root)
60        clearSite()
61        return
62
63class OfficerUITests(StudentsFullSetup):
64    # Tests for Student class views and pages
65
66    layer = FunctionalLayer
67
68    def test_gpa_calculation(self):
69        studylevel = createObject(u'waeup.StudentStudyLevel')
70        studylevel.level = 100
71        studylevel.level_session = 2005
72        self.student['studycourse'].entry_mode = 'ug_ft'
73        self.student['studycourse'].addStudentStudyLevel(
74            self.certificate, studylevel)
75        # First course has been added automatically.
76        # Set score.
77        studylevel['COURSE1'].score = 55
78        # GPA is 3.0.
79        self.assertEqual(studylevel.gpa_params[0], 3.0)
80        courseticket = createObject('waeup.CourseTicket')
81        courseticket.code = 'ANYCODE'
82        courseticket.title = u'Any TITLE'
83        courseticket.credits = 13
84        courseticket.score = 66
85        courseticket.semester = 1
86        courseticket.dcode = u'ANYDCODE'
87        courseticket.fcode = u'ANYFCODE'
88        studylevel['COURSE2'] = courseticket
89        # total credits
90        self.assertEqual(self.student['studycourse']['100'].gpa_params[1], 23)
91        # weigheted credits = 3 * 10 + 4 * 13
92        self.assertEqual(self.student['studycourse']['100'].gpa_params[2], 82.0)
93        # sgpa = 82 / 23
94        self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 3.565)
95        return
96
97class StudentUITests(StudentsFullSetup):
98    """Tests for customized student class views and pages
99    """
100
101    layer = FunctionalLayer
102
103    def setUp(self):
104        super(StudentUITests, self).setUp()
105
106        bedticket = BedTicket()
107        bedticket.booking_session = 2004
108        bedticket.bed_type = u'any bed type'
109        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
110        bedticket.bed_coordinates = u'My bed coordinates'
111        self.student['accommodation'].addBedTicket(bedticket)
112
113    def test_manage_payments(self):
114        # Add missing configuration data
115        self.app['configuration']['2004'].gown_fee = 150.0
116        self.app['configuration']['2004'].transfer_fee = 90.0
117        self.app['configuration']['2004'].booking_fee = 150.0
118        self.app['configuration']['2004'].maint_fee = 180.0
119        self.app['configuration']['2004'].late_fee = 80.0
120
121        # Managers can add online payment tickets
122        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
123        self.browser.open(self.payments_path)
124        self.browser.getLink("Add current session payment ticket").click()
125        self.browser.getControl(name="form.p_category").value = ['schoolfee']
126        self.browser.getControl("Create ticket").click()
127        self.assertMatches('...Wrong state...',
128                           self.browser.contents)
129        IWorkflowState(self.student).setState('cleared')
130        self.browser.open(self.payments_path + '/addop')
131        self.browser.getControl("Create ticket").click()
132        self.assertMatches('...Amount could not be determined...',
133                           self.browser.contents)
134        self.app['configuration']['2004'].school_fee = 6666.0
135        self.browser.getControl(name="form.p_category").value = ['schoolfee']
136        self.browser.getControl("Create ticket").click()
137        self.assertMatches('...ticket created...',
138                           self.browser.contents)
139        ctrl = self.browser.getControl(name='val_id')
140        value = ctrl.options[0]
141        self.browser.getLink(value).click()
142        self.assertMatches('...Amount Authorized...',
143                           self.browser.contents)
144        # Managers can open payment slip
145        self.browser.getLink("Download payment slip").click()
146        self.assertEqual(self.browser.headers['Status'], '200 Ok')
147        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
148        # Set ticket paid
149        ticket = self.student['payments'].items()[0][1]
150        ticket.p_state = 'paid'
151        self.browser.open(self.payments_path + '/addop')
152        self.browser.getControl(name="form.p_category").value = ['schoolfee']
153        self.browser.getControl("Create ticket").click()
154        self.assertMatches('...This type of payment has already been made...',
155                           self.browser.contents)
156        self.browser.open(self.payments_path + '/addop')
157        # Also the other payments can be made
158        self.browser.getControl(name="form.p_category").value = ['gown']
159        self.browser.getControl("Create ticket").click()
160        self.assertMatches('...ticket created...',
161                           self.browser.contents)
162        self.browser.open(self.payments_path + '/addop')
163        self.browser.getControl(name="form.p_category").value = ['transfer']
164        self.browser.getControl("Create ticket").click()
165        self.assertMatches('...ticket created...',
166                           self.browser.contents)
167        self.browser.open(self.payments_path + '/addop')
168        self.browser.getControl(
169            name="form.p_category").value = ['bed_allocation']
170        self.browser.getControl("Create ticket").click()
171        self.assertMatches('...ticket created...',
172                           self.browser.contents)
173        self.browser.open(self.payments_path + '/addop')
174        self.browser.getControl(
175            name="form.p_category").value = ['hostel_maintenance']
176        self.browser.getControl("Create ticket").click()
177        self.assertMatches('...ticket created...',
178                           self.browser.contents)
179        self.browser.open(self.payments_path + '/addop')
180        self.browser.getControl(name="form.p_category").value = ['clearance']
181        self.browser.getControl("Create ticket").click()
182        self.assertMatches('...ticket created...',
183                           self.browser.contents)
184        self.browser.open(self.payments_path + '/addop')
185        self.browser.getControl(name="form.p_category").value = ['late_registration']
186        self.browser.getControl("Create ticket").click()
187        self.assertMatches('...ticket created...',
188                           self.browser.contents)
189
190
191    def deactivated_test_for_instalment_payments(self):
192        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
193        self.browser.open(self.payments_path)
194        self.browser.open(self.payments_path + '/addop')
195        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
196        self.browser.getControl("Create ticket").click()
197        self.assertMatches('...ticket created...',
198                           self.browser.contents)
199        # We can't add the 2nd instalment ticket because the
200        # first one has not yet been approved.
201        self.browser.open(self.payments_path + '/addop')
202        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
203        self.browser.getControl("Create ticket").click()
204        self.assertMatches('...1st school fee instalment has not yet been paid...',
205                           self.browser.contents)
206        # Ok, then we approve the first instalment ...
207        self.browser.open(self.payments_path)
208        ctrl = self.browser.getControl(name='val_id')
209        p_id = ctrl.options[0]
210        self.browser.open(self.payments_path + '/' + p_id + '/approve')
211        # ... add the second instalment ...
212        self.browser.open(self.payments_path + '/addop')
213        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
214        self.browser.getControl("Create ticket").click()
215        self.assertMatches('...ticket created...',
216                           self.browser.contents)
217        # ... approve the second instalment ...
218        ctrl = self.browser.getControl(name='val_id')
219        p_id = ctrl.options[1]
220        self.browser.open(self.payments_path + '/' + p_id + '/approve')
221        # ... and finally add the 1st instalment for the next session
222        # provided that student is returning.
223        IWorkflowState(self.student).setState('returning')
224        self.browser.open(self.payments_path + '/addop')
225        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
226        self.browser.getControl("Create ticket").click()
227        self.assertMatches('...Session configuration object is not...',
228                           self.browser.contents)
229        # Uups, we forgot to add a session configuration for next session
230        configuration = createObject('waeup.SessionConfiguration')
231        configuration.academic_session = 2005
232        self.app['configuration'].addSessionConfiguration(configuration)
233        self.app['configuration']['2005'].school_base = 7777.0
234        self.browser.open(self.payments_path + '/addop')
235        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
236        self.browser.getControl("Create ticket").click()
237        self.assertMatches('...ticket created...',
238                           self.browser.contents)
239        # If the session configuration doesn't exist an error message will
240        # be shown. No other requirement is being checked.
241        del self.app['configuration']['2004']
242        self.browser.open(self.payments_path)
243        self.browser.getLink("Add current session payment ticket").click()
244        self.browser.getControl("Create ticket").click()
245        self.assertMatches('...Session configuration object is not...',
246                           self.browser.contents)
247
248    def test_student_payments(self):
249        # Login
250        IWorkflowState(self.student).setState('returning')
251        self.browser.open(self.login_path)
252        self.browser.getControl(name="form.login").value = self.student_id
253        self.browser.getControl(name="form.password").value = 'spwd'
254        self.browser.getControl("Login").click()
255        self.browser.open(self.student_path + '/payments')
256        self.assertTrue(
257          'Add current session payment ticket' in self.browser.contents)
258        self.assertFalse(
259          'Add previous session payment ticket' in self.browser.contents)
260        return
261
262    def deactivated_test_student_course_registration(self):
263
264        # Add more courses
265        self.course2 = createObject('waeup.Course')
266        self.course2.code = 'COURSE2'
267        self.course2.semester = 2
268        self.course2.credits = 10
269        self.course2.passmark = 40
270        self.app['faculties']['fac1']['dep1'].courses.addCourse(
271            self.course2)
272        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
273            self.course2, level=100)
274        self.course3 = createObject('waeup.Course')
275        self.course3.code = 'COURSE3'
276        self.course3.semester = 3
277        self.course3.credits = 10
278        self.course3.passmark = 40
279        self.app['faculties']['fac1']['dep1'].courses.addCourse(
280            self.course3)
281        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
282            self.course3, level=100)
283
284        # Login as student
285        self.browser.open(self.login_path)
286        IWorkflowState(self.student).setState('school fee paid')
287        self.browser.open(self.login_path)
288        self.browser.getControl(name="form.login").value = self.student_id
289        self.browser.getControl(name="form.password").value = 'spwd'
290        self.browser.getControl("Login").click()
291        # Students can add the current study level
292        self.browser.getLink("Study Course").click()
293        self.browser.getLink("Add course list").click()
294        self.assertMatches('...Add current level 100 (Year 1)...',
295                           self.browser.contents)
296        self.browser.getControl("Create course list now").click()
297        # Student has not paid second instalment, therefore a level
298        # with two course ticket was created (semester 1 and combined)
299        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
300        self.browser.getLink("100").click()
301        self.browser.getLink("Edit course list").click()
302        self.browser.getControl("Add course ticket").click()
303        # Student can't add second semester course
304        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
305        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
306        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
307
308        # Let's remove level and see what happens after 2nd instalment payment
309        del(self.student['studycourse']['100'])
310        payment2 = createObject('waeup.StudentOnlinePayment')
311        payment2.p_category = u'schoolfee_2'
312        payment2.p_session = self.student.current_session
313        self.student['payments']['anykey'] = payment2
314        self.browser.open(self.studycourse_path)
315        self.browser.getLink("Add course list").click()
316        self.browser.getControl("Create course list now").click()
317        # Still only 2 tickets have been created since payment ticket
318        # was not paid
319        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
320        payment2.p_state = u'paid'
321        del(self.student['studycourse']['100'])
322        self.browser.open(self.studycourse_path)
323        self.browser.getLink("Add course list").click()
324        self.browser.getControl("Create course list now").click()
325        # Now 2nd semester course has been added
326        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
327        # Student can add second semester course
328        self.browser.getLink("100").click()
329        self.browser.getLink("Edit course list").click()
330        self.browser.getControl("Add course ticket").click()
331        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
332        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
333        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
334        return
335
336    def test_set_matric_number(self):
337        # Login as student
338        self.browser.open(self.login_path)
339        #IWorkflowState(self.student).setState('school fee paid')
340        self.browser.open(self.login_path)
341        self.browser.getControl(name="form.login").value = self.student_id
342        self.browser.getControl(name="form.password").value = 'spwd'
343        self.browser.getControl("Login").click()
344        self.assertRaises(
345            LinkNotFoundError,
346            self.browser.getLink, 'Get Matriculation Number')
347        self.student.matric_number = None
348        site = grok.getSite()
349        site['configuration'].next_matric_integer = 1
350        self.student['studycourse'].certificate.study_mode = 'ug_pt'
351        self.browser.open(self.student_path)
352        self.browser.getLink("Get Matriculation Number").click()
353        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
354            in self.browser.contents)
355        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
356        self.assertRaises(
357            LinkNotFoundError,
358            self.browser.getLink, 'Get Matriculation Number')
359        return
360
Note: See TracBrowser for help on using the repository browser.