Changeset 7922 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 20 Mar 2012, 00:52:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_schoolgrades.py
r7811 r7922 7 7 class ResultEntryTests(unittest.TestCase): 8 8 9 def setUp(self): 10 from waeup.kofa.interfaces import IKofaUtils 11 from waeup.kofa.utils.utils import KofaUtils 12 from zope.component import getGlobalSiteManager 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 9 24 def test_ifaces(self): 10 25 # make sure we implement the promised interfaces. … … 12 27 verifyObject(IResultEntry, obj) 13 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 from zope.schema.interfaces import ConstraintNotSatisfied 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) 14 77 return 15 78 … … 22 85 verifyClass(IResultEntryField, ResultEntryField) 23 86 return 87
Note: See TracChangeset for help on using the changeset viewer.