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

Last change on this file since 14395 was 12427, checked in by uli, 10 years ago

pep8.

  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[7794]1# Tests for schoolgrades module.
2import unittest
[7923]3from zope.component import getGlobalSiteManager
[7794]4from zope.interface.verify import verifyObject, verifyClass
[7923]5from zope.schema.interfaces import ConstraintNotSatisfied
6from waeup.kofa.interfaces import IResultEntry, IResultEntryField, IKofaUtils
[7811]7from waeup.kofa.schoolgrades import ResultEntry, ResultEntryField
[7923]8from waeup.kofa.utils.utils import KofaUtils
[7794]9
[12427]10
[7794]11class ResultEntryTests(unittest.TestCase):
12
[7922]13    def setUp(self):
14        self.utils = KofaUtils()
15        self.gsm = getGlobalSiteManager()
16        self.gsm.registerUtility(self.utils, IKofaUtils)
17        self.valid_subj = self.utils.EXAM_SUBJECTS_DICT.keys()[0]
18        self.valid_grade = self.utils.EXAM_GRADES[0][0]
19        return
20
21    def tearDown(self):
22        self.gsm.unregisterUtility(self.utils)
23        return
24
[7794]25    def test_ifaces(self):
26        # make sure we implement the promised interfaces.
27        obj = ResultEntry()
28        verifyObject(IResultEntry, obj)
29        verifyClass(IResultEntry, ResultEntry)
30        return
31
[7922]32    def test_init(self):
33        # we can pass initial values
34        item1 = ResultEntry()
35        item2 = ResultEntry(self.valid_subj, self.valid_grade)
36        self.assertTrue(item1.subject is None)
37        self.assertTrue(item1.grade is None)
38        self.assertEqual(item2.subject, self.valid_subj)
39        self.assertEqual(item2.grade, self.valid_grade)
40        return
41
42    def test_illegal_value(self):
43        # we do not accept values not stored in KofaUtils
44        item = ResultEntry()
45        self.assertRaises(
46            ConstraintNotSatisfied, ResultEntry, 'invalid', 'invalid')
47        self.assertRaises(
48            ConstraintNotSatisfied, ResultEntry, 'invalid')
49        self.assertRaises(
50            ConstraintNotSatisfied, setattr, item, 'subject', 'blah')
51        self.assertRaises(
52            ConstraintNotSatisfied, setattr, item, 'grade', 'blah')
53        return
54
55    def test_to_string(self):
56        # the string representation is handy for export
57        item1 = ResultEntry()
58        item2 = ResultEntry(self.valid_subj, self.valid_grade)
59        self.assertEqual(item1.to_string(), u"(None, None)")
60        self.assertEqual(item2.to_string(), u"('%s', '%s')" % (
61            self.valid_subj, self.valid_grade))
62        return
63
64    def test_from_string(self):
65        # we can create new result entries based on strings
66        myinput = u"(u'%s',u'%s')" % (
67            self.valid_subj, self.valid_grade)
68        item1 = ResultEntry.from_string(myinput)
69        item2 = ResultEntry.from_string(u"(u'',u'')")
70        item3 = ResultEntry.from_string(u"(None, None)")
71        self.assertEqual(item1.subject, self.valid_subj)
72        self.assertEqual(item1.grade, self.valid_grade)
73        self.assertTrue(item2.subject is None)
74        self.assertTrue(item2.grade is None)
75        self.assertTrue(item3.subject is None)
76        self.assertTrue(item3.grade is None)
77        return
78
[12425]79    def test_eq(self):
80        # we can compare equality of ResultEntry objects
81        item1 = ResultEntry(self.valid_subj, self.valid_grade)
82        item2 = ResultEntry(self.valid_subj, self.valid_grade)
83        item3 = ResultEntry()
84        item4 = ResultEntry()
85        assert item1 is not item2
86        assert item1 == item1
87        assert item1 == item2
88        assert item3 is not item4
89        assert item3 == item4
90        assert item1.__eq__(item2) is True
91        assert item1.__eq__(item3) is False
92
93    def test_ne(self):
94        # we can also tell, which ResultEntries are _not_ equal
95        item1 = ResultEntry(self.valid_subj, self.valid_grade)
96        item2 = ResultEntry()
97        assert item1 != item2
98        assert item1.__ne__(item2) is True
99        assert item1.__ne__(item1) is False
100
101
[7794]102class ResultEntryFieldTests(unittest.TestCase):
103
104    def test_ifaces(self):
105        # make sure we implement the promised interfaces.
106        obj = ResultEntryField()
107        verifyObject(IResultEntryField, obj)
108        verifyClass(IResultEntryField, ResultEntryField)
109        return
Note: See TracBrowser for help on using the repository browser.