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

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

Uups, that was a slip.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: test_vocabularies.py 9134 2012-08-31 14:59:01Z 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
31    def get(self, attr, default=None):
32        try:
33            return self.__getattribute__(attr)
34        except AttributeError:
35            return default
36
37class VocabularyTests(unittest.TestCase):
38
39    def test_studylevelsource(self):
40        studycourse = FakeStudyCourse()
41        studylevelsource = StudyLevelSource().factory
42        values = studylevelsource.getValues(studycourse)
43        self.assertEqual(values, [100, 110, 120, 200, 210, 220, 300, 310, 320,
44            400, 410, 420, 500, 510, 520, 600, 610, 620])
45        # Unfortunately, unittests don't know about internationalization
46        self.assertEqual(studylevelsource.getTitle(studycourse, None),
47            'Error: level id ${value} out of range')
48        self.assertEqual(studylevelsource.getTitle(studycourse, 0),
49            'Error: level id ${value} out of range')
50        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
51            'Error: level id ${value} out of range')
52        self.assertEqual(studylevelsource.getTitle(studycourse, 100),
53            '100 (Year 1)')
54        self.assertEqual(studylevelsource.getTitle(studycourse, 110),
55            '${title} on 1st probation')
56        self.assertEqual(studylevelsource.getTitle(studycourse, 120),
57            '${title} on 2nd probation')
58        self.assertEqual(studylevelsource.getTitle(studycourse, 500),
59            '500 (Year 5)')
60        self.assertEqual(studylevelsource.getTitle(studycourse, 600),
61            '${title} 1st spillover')
62        self.assertEqual(studylevelsource.getTitle(studycourse, 610),
63            '${title} 2nd spillover')
64        self.assertEqual(studylevelsource.getTitle(studycourse, 620),
65            '${title} 3rd spillover')
66        self.assertEqual(studylevelsource.getTitle(studycourse, 630),
67            'Error: level id ${value} out of range')
68        self.assertEqual(studylevelsource.getTitle(studycourse, 700),
69            'Error: level id ${value} out of range')
70        # Now we change the certificates start_level to pre-studies
71        studycourse.certificate.start_level = 10
72        self.assertEqual(studylevelsource.getTitle(studycourse, 10),
73            'Pre-Studies')
74        # Repeating Pre-Studies level does not exist
75        self.assertRaises(KeyError,studylevelsource.getTitle,studycourse,20)
Note: See TracBrowser for help on using the repository browser.