source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_vocabularies.py @ 9644

Last change on this file since 9644 was 9325, checked in by Henrik Bettermann, 12 years ago

Test if all titles for the various start_level and end_level combinations do exist.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1## $Id: test_vocabularies.py 9325 2012-10-10 20:44:33Z 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 StudyLevelSource
20from waeup.kofa.university.certificate import Certificate
21
22
23class FakeStudyCourse(object):
24
25    def __init__(self):
26        cert = Certificate(code="CERT1")
27        cert.start_level = 100
28        cert.end_level = 500
29        self.certificate = cert
30
31class VocabularyTests(unittest.TestCase):
32
33    def test_studylevelsource(self):
34        studycourse = FakeStudyCourse()
35        studylevelsource = StudyLevelSource().factory
36        values = studylevelsource.getValues(studycourse)
37        self.assertEqual(values, [100, 110, 120, 200, 210, 220, 300, 310, 320,
38            400, 410, 420, 500, 510, 520, 600, 610, 620])
39        # All titles do exist
40        titles = [studylevelsource.getTitle(studycourse, value)
41            for value in values]
42        self.assertEqual(len(titles), 18)
43        # Unfortunately, unittests don't know about internationalization
44        self.assertEqual(studylevelsource.getTitle(studycourse, None),
45            'Error: level id ${value} out of range')
46        self.assertEqual(studylevelsource.getTitle(studycourse, 0),
47            'Error: level id ${value} out of range')
48        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
49            'Error: level id ${value} out of range')
50        self.assertEqual(studylevelsource.getTitle(studycourse, 100),
51            '100 (Year 1)')
52        self.assertEqual(studylevelsource.getTitle(studycourse, 110),
53            '${title} on 1st probation')
54        self.assertEqual(studylevelsource.getTitle(studycourse, 120),
55            '${title} on 2nd probation')
56        self.assertEqual(studylevelsource.getTitle(studycourse, 500),
57            '500 (Year 5)')
58        self.assertEqual(studylevelsource.getTitle(studycourse, 600),
59            '${title} 1st spillover')
60        self.assertEqual(studylevelsource.getTitle(studycourse, 610),
61            '${title} 2nd spillover')
62        self.assertEqual(studylevelsource.getTitle(studycourse, 620),
63            '${title} 3rd spillover')
64        self.assertEqual(studylevelsource.getTitle(studycourse, 630),
65            'Error: level id ${value} out of range')
66        self.assertEqual(studylevelsource.getTitle(studycourse, 700),
67            'Error: level id ${value} out of range')
68        # Now we modify the certificates to be a pure to pre-studies
69        # course
70        studycourse.certificate.start_level = 10
71        studycourse.certificate.end_level = 10
72        values = studylevelsource.getValues(studycourse)
73        self.assertEqual(values, [10])
74        titles = [studylevelsource.getTitle(studycourse, value)
75            for value in values]
76        self.assertEqual(len(titles), 1)
77        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
78            'Pre-Studies')
79        # Finally we modify the certificate to be a mixed course,
80        # starting with pre-studies.
81        studycourse.certificate.end_level = 200
82        values = studylevelsource.getValues(studycourse)
83        self.assertEqual(values, [10, 100, 110, 120,
84            200, 210, 220, 300, 310, 320])
85        titles = [studylevelsource.getTitle(studycourse, value)
86            for value in values]
87        self.assertEqual(len(titles), 10)
88        # Repeating Pre-Studies level does not exist and raises a KeyError
89        # when trying to get its title
90        self.assertRaises(KeyError,studylevelsource.getTitle,studycourse,20)
Note: See TracBrowser for help on using the repository browser.