source: main/waeup.kofa/branches/uli-fix-zc-async/src/waeup/kofa/students/tests/test_vocabularies.py @ 17389

Last change on this file since 17389 was 16812, checked in by Henrik Bettermann, 3 years ago

Add 'Modules Level'.

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1## $Id: test_vocabularies.py 16812 2022-02-16 15:50:47Z henrik $
2##
3## Copyright (C) 2012 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 unittest
19from waeup.kofa.students.vocabularies import (
20    StudyLevelSource, levels_from_range,
21    )
22from waeup.kofa.university.certificate import Certificate
23
24class HelperTests(unittest.TestCase):
25
26    def test_levels_from_range(self):
27        # default
28        self.assertEqual(
29            levels_from_range(),
30            [10,
31             100, 110, 120, 200, 210, 220, 300, 310, 320, 400, 410, 420,
32             500, 510, 520, 600, 610, 620, 700, 710, 720, 800, 810, 820,
33             900, 910, 920, 999, 1000,])
34        # edge-case: level 10
35        self.assertEqual(
36            levels_from_range(10, 10), [10])
37        # edge-case: level 999
38        self.assertEqual(
39            levels_from_range(999, 10), [999])
40        self.assertEqual(
41            levels_from_range(10, 999), [999])
42        self.assertEqual(
43            levels_from_range(10, 200),
44            [10, 100, 110, 120, 200, 210, 220, 300, 310, 320])
45        self.assertEqual(
46            levels_from_range(100, 300),
47            [100, 110, 120, 200, 210, 220, 300, 310, 320, 400, 410, 420])
48        self.assertEqual(
49            levels_from_range(800, 900),
50            [800, 810, 820, 900, 910, 920])
51        return
52
53class FakeStudyCourse(object):
54
55    def __init__(self):
56        cert = Certificate(code="CERT1")
57        cert.start_level = 100
58        cert.end_level = 500
59        self.certificate = cert
60
61class VocabularyTests(unittest.TestCase):
62
63    def test_studylevelsource(self):
64        studycourse = FakeStudyCourse()
65        studylevelsource = StudyLevelSource().factory
66        values = studylevelsource.getValues(studycourse)
67        self.assertEqual(values, [0, 100, 110, 120, 200, 210, 220, 300, 310, 320,
68            400, 410, 420, 500, 510, 520, 600, 610, 620])
69        # All titles do exist
70        titles = [studylevelsource.getTitle(studycourse, value)
71            for value in values]
72        self.assertEqual(len(titles), 19)
73        # Unfortunately, unittests don't know about internationalization
74        self.assertEqual(studylevelsource.getTitle(studycourse, None),
75            'Error: level id ${value} out of range')
76        self.assertEqual(studylevelsource.getTitle(studycourse, 0),
77            'Level Zero')
78        self.assertEqual(studylevelsource.getTitle(studycourse, 1),
79            'Error: level id ${value} out of range')
80        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
81            'Error: level id ${value} out of range')
82        self.assertEqual(studylevelsource.getTitle(studycourse, 100),
83            '100 (Year 1)')
84        self.assertEqual(studylevelsource.getTitle(studycourse, 110),
85            '${title} on 1st probation')
86        self.assertEqual(studylevelsource.getTitle(studycourse, 120),
87            '${title} on 2nd probation')
88        self.assertEqual(studylevelsource.getTitle(studycourse, 500),
89            '500 (Year 5)')
90        self.assertEqual(studylevelsource.getTitle(studycourse, 600),
91            '${title} 1st spillover')
92        self.assertEqual(studylevelsource.getTitle(studycourse, 610),
93            '${title} 2nd spillover')
94        self.assertEqual(studylevelsource.getTitle(studycourse, 620),
95            '${title} 3rd spillover')
96        self.assertEqual(studylevelsource.getTitle(studycourse, 630),
97            'Error: level id ${value} out of range')
98        self.assertEqual(studylevelsource.getTitle(studycourse, 700),
99            'Error: level id ${value} out of range')
100        # Now we modify the certificates to be a pure pre-studies
101        # course
102        studycourse.certificate.start_level = 10
103        studycourse.certificate.end_level = 10
104        values = studylevelsource.getValues(studycourse)
105        self.assertEqual(values, [0, 10])
106        titles = [studylevelsource.getTitle(studycourse, value)
107            for value in values]
108        self.assertEqual(len(titles), 2)
109        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
110            'Pre-Studies')
111        self.assertEqual(studylevelsource.getTitle(studycourse, 100),
112            'Error: level id ${value} out of range')
113        self.assertEqual(studylevelsource.getTitle(studycourse, 200),
114            'Error: level id ${value} out of range')
115        # Finally we modify the certificate to be a mixed course,
116        # starting with pre-studies.
117        studycourse.certificate.end_level = 200
118        values = studylevelsource.getValues(studycourse)
119        self.assertEqual(values, [0, 10, 100, 110, 120,
120            200, 210, 220, 300, 310, 320])
121        titles = [studylevelsource.getTitle(studycourse, value)
122            for value in values]
123        self.assertEqual(len(titles), 11)
Note: See TracBrowser for help on using the repository browser.