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

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

This requirement applies to students in state 'cleared' and entry_session
greater than 2013 only.

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