source: main/waeup.kofa/trunk/src/waeup/kofa/tests/test_schoolgrades.py @ 9793

Last change on this file since 9793 was 8057, checked in by Henrik Bettermann, 13 years ago

Adjust copyright header and propset svn:keywords.

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1# Tests for schoolgrades module.
2import unittest
3from zope.component import getGlobalSiteManager
4from zope.interface.verify import verifyObject, verifyClass
5from zope.schema.interfaces import ConstraintNotSatisfied
6from waeup.kofa.interfaces import IResultEntry, IResultEntryField, IKofaUtils
7from waeup.kofa.schoolgrades import ResultEntry, ResultEntryField
8from waeup.kofa.utils.utils import KofaUtils
9
10class ResultEntryTests(unittest.TestCase):
11
12    def setUp(self):
13        self.utils = KofaUtils()
14        self.gsm = getGlobalSiteManager()
15        self.gsm.registerUtility(self.utils, IKofaUtils)
16        self.valid_subj = self.utils.EXAM_SUBJECTS_DICT.keys()[0]
17        self.valid_grade = self.utils.EXAM_GRADES[0][0]
18        return
19
20    def tearDown(self):
21        self.gsm.unregisterUtility(self.utils)
22        return
23
24    def test_ifaces(self):
25        # make sure we implement the promised interfaces.
26        obj = ResultEntry()
27        verifyObject(IResultEntry, obj)
28        verifyClass(IResultEntry, ResultEntry)
29        return
30
31    def test_init(self):
32        # we can pass initial values
33        item1 = ResultEntry()
34        item2 = ResultEntry(self.valid_subj, self.valid_grade)
35        self.assertTrue(item1.subject is None)
36        self.assertTrue(item1.grade is None)
37        self.assertEqual(item2.subject, self.valid_subj)
38        self.assertEqual(item2.grade, self.valid_grade)
39        return
40
41    def test_illegal_value(self):
42        # we do not accept values not stored in KofaUtils
43        item = ResultEntry()
44        self.assertRaises(
45            ConstraintNotSatisfied, ResultEntry, 'invalid', 'invalid')
46        self.assertRaises(
47            ConstraintNotSatisfied, ResultEntry, 'invalid')
48        self.assertRaises(
49            ConstraintNotSatisfied, setattr, item, 'subject', 'blah')
50        self.assertRaises(
51            ConstraintNotSatisfied, setattr, item, 'grade', 'blah')
52        return
53
54    def test_to_string(self):
55        # the string representation is handy for export
56        item1 = ResultEntry()
57        item2 = ResultEntry(self.valid_subj, self.valid_grade)
58        self.assertEqual(item1.to_string(), u"(None, None)")
59        self.assertEqual(item2.to_string(), u"('%s', '%s')" % (
60            self.valid_subj, self.valid_grade))
61        return
62
63    def test_from_string(self):
64        # we can create new result entries based on strings
65        myinput = u"(u'%s',u'%s')" % (
66            self.valid_subj, self.valid_grade)
67        item1 = ResultEntry.from_string(myinput)
68        item2 = ResultEntry.from_string(u"(u'',u'')")
69        item3 = ResultEntry.from_string(u"(None, None)")
70        self.assertEqual(item1.subject, self.valid_subj)
71        self.assertEqual(item1.grade, self.valid_grade)
72        self.assertTrue(item2.subject is None)
73        self.assertTrue(item2.grade is None)
74        self.assertTrue(item3.subject is None)
75        self.assertTrue(item3.grade is None)
76        return
77
78class ResultEntryFieldTests(unittest.TestCase):
79
80    def test_ifaces(self):
81        # make sure we implement the promised interfaces.
82        obj = ResultEntryField()
83        verifyObject(IResultEntryField, obj)
84        verifyClass(IResultEntryField, ResultEntryField)
85        return
86
Note: See TracBrowser for help on using the repository browser.