source: main/waeup.kofa/trunk/src/waeup/kofa/tests/test_refereeentries.py @ 17211

Last change on this file since 17211 was 14012, checked in by Henrik Bettermann, 8 years ago

Add email_sent attribute.

Add tests.

File size: 4.0 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, WrongType
6from waeup.kofa.interfaces import (
7    IRefereeEntry, IRefereeEntryField, IKofaUtils, NotAnEmailAddress)
8from waeup.kofa.refereeentries import RefereeEntry, RefereeEntryField
9from waeup.kofa.utils.utils import KofaUtils
10
11
12class RefereeEntryTests(unittest.TestCase):
13
14    def setUp(self):
15        self.valid_name = u'Otis Stone'
16        self.valid_email = 'otis@stones.de'
17        return
18
19    def tearDown(self):
20        return
21
22    def test_ifaces(self):
23        # make sure we implement the promised interfaces
24        obj = RefereeEntry()
25        verifyObject(IRefereeEntry, obj)
26        verifyClass(IRefereeEntry, RefereeEntry)
27        return
28
29    def test_init(self):
30        # we can pass initial values
31        item1 = RefereeEntry()
32        item2 = RefereeEntry(self.valid_name, self.valid_email)
33        self.assertTrue(item1.name is None)
34        self.assertTrue(item1.email is None)
35        self.assertEqual(item2.name, self.valid_name)
36        self.assertEqual(item2.email, self.valid_email)
37        self.assertFalse(item1.email_sent)
38        self.assertFalse(item2.email_sent)
39        return
40
41    def test_illegal_value(self):
42        # we do not accept wrong values
43        item = RefereeEntry()
44        self.assertRaises(
45            WrongType, RefereeEntry, 'invalid', 'invalid')
46        self.assertRaises(
47            WrongType, RefereeEntry, 'invalid')
48        self.assertRaises(
49            WrongType, setattr, item, 'name', 99)
50        self.assertRaises(
51            NotAnEmailAddress, setattr, item, 'email', 'blah')
52        return
53
54    def test_to_string(self):
55        # the string representation is handy for export
56        item1 = RefereeEntry()
57        item2 = RefereeEntry(self.valid_name, self.valid_email)
58        self.assertEqual(item1.to_string(), u"(None, None, False)")
59        self.assertEqual(item2.to_string(), u"(u'%s', '%s', False)" % (
60            self.valid_name, self.valid_email))
61        return
62
63    def test_from_string(self):
64        # we can create new result entries based on strings
65        myinput = u"(u'%s','%s',True)" % (
66            self.valid_name, self.valid_email)
67        item1 = RefereeEntry.from_string(myinput)
68        item2 = RefereeEntry.from_string(u"(u'','',999)")
69        item3 = RefereeEntry.from_string(u"(None, None, False)")
70        self.assertEqual(item1.name, self.valid_name)
71        self.assertEqual(item1.email, self.valid_email)
72        self.assertTrue(item1.email_sent is True)
73        self.assertTrue(item2.name is None)
74        self.assertTrue(item2.email is None)
75        self.assertTrue(item2.email_sent is False)
76        self.assertTrue(item3.name is None)
77        self.assertTrue(item3.email is None)
78        self.assertTrue(item3.email_sent is False)
79        return
80
81    def test_eq(self):
82        # we can compare equality of RefereeEntry objects
83        item1 = RefereeEntry(self.valid_name, self.valid_email)
84        item2 = RefereeEntry(self.valid_name, self.valid_email)
85        item3 = RefereeEntry()
86        item4 = RefereeEntry()
87        assert item1 is not item2
88        assert item1 == item1
89        assert item1 == item2
90        assert item3 is not item4
91        assert item3 == item4
92        assert item1.__eq__(item2) is True
93        assert item1.__eq__(item3) is False
94
95    def test_ne(self):
96        # we can also tell, which ResultEntries are _not_ equal
97        item1 = RefereeEntry(self.valid_name, self.valid_email)
98        item2 = RefereeEntry()
99        assert item1 != item2
100        assert item1.__ne__(item2) is True
101        assert item1.__ne__(item1) is False
102
103
104class RefereeEntryFieldTests(unittest.TestCase):
105
106    def test_ifaces(self):
107        # make sure we implement the promised interfaces.
108        obj = RefereeEntryField()
109        verifyObject(IRefereeEntryField, obj)
110        verifyClass(IRefereeEntryField, RefereeEntryField)
111        return
Note: See TracBrowser for help on using the repository browser.