source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_utils.py @ 17387

Last change on this file since 17387 was 14587, checked in by Henrik Bettermann, 8 years ago

Replace maxCreditsExceeded by warnCreditsOOR.

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1# -*- coding: utf-8 -*-
2import grok
3from hurry.workflow.interfaces import IWorkflowState
4from zope.component import getUtility
5from waeup.kofa.testing import FunctionalTestCase
6from waeup.kofa.university.faculty import Faculty
7from waeup.kofa.university.department import Department
8from waeup.kofa.students.student import Student
9from waeup.kofa.students.interfaces import IStudentsUtils
10from waeup.kofa.students.tests.test_browser import StudentsFullSetup
11from waeup.kwarapoly.testing import FunctionalLayer
12
13class StudentsUtilsTests(StudentsFullSetup):
14
15    layer = FunctionalLayer
16
17    def test_getAccommodationDetails(self):
18        students_utils = getUtility(IStudentsUtils)
19        acc_details  = students_utils.getAccommodationDetails(self.student)
20        self.assertEqual(acc_details['bt'], 'regular_male_fr')
21
22        self.student['studycourse'].current_level = 200
23        acc_details  = students_utils.getAccommodationDetails(self.student)
24        self.assertEqual(acc_details['bt'], 'regular_male_re')
25
26        self.student['studycourse'].current_level = 210
27        acc_details  = students_utils.getAccommodationDetails(self.student)
28        self.assertEqual(acc_details['bt'], 'regular_male_re')
29
30        self.student['studycourse'].current_level = 300
31        acc_details  = students_utils.getAccommodationDetails(self.student)
32        self.assertEqual(acc_details['bt'], 'regular_male_fi')
33
34        self.student['studycourse'].current_level = 400
35        acc_details  = students_utils.getAccommodationDetails(self.student)
36        self.assertEqual(acc_details['bt'], 'regular_male_fr')
37
38        self.student['studycourse'].current_level = 500
39        acc_details  = students_utils.getAccommodationDetails(self.student)
40        self.assertEqual(acc_details['bt'], 'regular_male_re')
41
42        self.student['studycourse'].current_level = 510
43        acc_details  = students_utils.getAccommodationDetails(self.student)
44        self.assertEqual(acc_details['bt'], 'regular_male_re')
45
46        self.student['studycourse'].current_level = 600
47        acc_details  = students_utils.getAccommodationDetails(self.student)
48        self.assertEqual(acc_details['bt'], 'regular_male_fi')
49        return
50
51    def test_setMatricNumber(self):
52        # Add second student
53        secondstudent = Student()
54        secondstudent.firstname = u'second'
55        secondstudent.lastname = u'Student'
56        self.app['students'].addStudent(secondstudent)
57        student_id = secondstudent.student_id
58        secondstudent['studycourse'].certificate = self.certificate
59        secondstudent['studycourse'].entry_session = 2015
60        secondstudent['studycourse'].entry_mode = 'nd_ft'
61        IWorkflowState(secondstudent).setState('school fee paid')
62        utils = getUtility(IStudentsUtils)
63        self.student.matric_number = None
64        msg, mnumber = utils.setMatricNumber(self.student)
65        self.assertEqual(msg, 'Available from session 2015/2016')
66        self.student['studycourse'].entry_mode = 'nd_ft'
67        self.student['studycourse'].entry_session = 2015
68        msg, mnumber = utils.setMatricNumber(self.student)
69        self.assertEqual(mnumber, None)
70        self.assertEqual(msg, 'Wrong state.')
71        IWorkflowState(self.student).setState('school fee paid')
72        msg, mnumber = utils.setMatricNumber(self.student)
73        self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/001')
74        msg, mnumber = utils.setMatricNumber(self.student)
75        self.assertEqual(msg, 'Matriculation number already set.')
76        # Second student gets nex matric number
77        msg, mnumber = utils.setMatricNumber(secondstudent)
78        self.assertEqual(secondstudent.matric_number, 'ND/15/dep1/FT/002')
79        self.student.matric_number = u'ND/15/dep1/FT/011'
80        secondstudent.matric_number = None
81        msg, mnumber = utils.setMatricNumber(secondstudent)
82        self.assertEqual(secondstudent.matric_number, 'ND/15/dep1/FT/012')
83        # Certificate must be set.
84        self.student.matric_number = None
85        self.student['studycourse'].certificate = None
86        msg, mnumber = utils.setMatricNumber(self.student)
87        self.assertEqual(msg, 'No certificate assigned.')
88        return
89
90    def test_maxCreditsExceeded(self):
91        students_utils = getUtility(IStudentsUtils)
92        studylevel = grok.Container()
93        studylevel.total_credits = 60
94        course = grok.Model()
95        course.credits = 88
96        warning = students_utils.warnCreditsOOR(studylevel, course)
97        self.assertEqual(warning, None)
98        return
Note: See TracBrowser for help on using the repository browser.