Changeset 12306 for main/waeup.ikoba/trunk/src/waeup/ikoba/tests
- Timestamp:
- 24 Dec 2014, 07:38:53 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/tests/test_schoolgrades.py
r11949 r12306 1 1 # Tests for schoolgrades module. 2 2 import unittest 3 from decimal import Decimal 3 4 from zope.component import getGlobalSiteManager 4 5 from zope.interface.verify import verifyObject, verifyClass 5 from zope.schema.interfaces import ConstraintNotSatisfied 6 from waeup.ikoba.interfaces import I ResultEntry, IResultEntryField, IIkobaUtils7 from waeup.ikoba.schoolgrades import ResultEntry, ResultEntryField6 from zope.schema.interfaces import ConstraintNotSatisfied, WrongType 7 from waeup.ikoba.interfaces import IProductOptionEntry, IProductOptionEntryField, IIkobaUtils 8 from waeup.ikoba.schoolgrades import ProductOptionEntry, ProductOptionEntryField 8 9 from waeup.ikoba.utils.utils import IkobaUtils 9 10 10 class ResultEntryTests(unittest.TestCase):11 class ProductOptionEntryTests(unittest.TestCase): 11 12 12 13 def setUp(self): … … 14 15 self.gsm = getGlobalSiteManager() 15 16 self.gsm.registerUtility(self.utils, IIkobaUtils) 16 self.valid_subj = self.utils.EXAM_SUBJECTS_DICT.keys()[0] 17 self.valid_grade = self.utils.EXAM_GRADES[0][0] 17 self.valid_title = u'Option 1' 18 self.valid_fee = Decimal(55.5) 19 self.valid_currency = 'usd' 18 20 return 19 21 … … 24 26 def test_ifaces(self): 25 27 # make sure we implement the promised interfaces. 26 obj = ResultEntry()27 verifyObject(I ResultEntry, obj)28 verifyClass(I ResultEntry, ResultEntry)28 obj = ProductOptionEntry() 29 verifyObject(IProductOptionEntry, obj) 30 verifyClass(IProductOptionEntry, ProductOptionEntry) 29 31 return 30 32 31 33 def test_init(self): 32 34 # 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) 35 item1 = ProductOptionEntry() 36 item2 = ProductOptionEntry( 37 self.valid_title, self.valid_fee, self.valid_currency) 38 self.assertTrue(item1.title is None) 39 self.assertTrue(item1.fee is None) 40 self.assertTrue(item1.currency is None) 41 self.assertEqual(item2.title, self.valid_title) 42 self.assertEqual(item2.fee, self.valid_fee) 43 self.assertEqual(item2.currency, self.valid_currency) 39 44 return 40 45 41 46 def test_illegal_value(self): 42 # we do not accept values not stored in IkobaUtils43 item = ResultEntry()47 # we do not accept values which do not meet the interface 48 item = ProductOptionEntry() 44 49 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') 50 WrongType, ProductOptionEntry, 6, 500, 'invalid') 52 51 return 53 52 54 53 def test_to_string(self): 55 54 # 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)) 55 item1 = ProductOptionEntry() 56 item2 = ProductOptionEntry( 57 self.valid_title, self.valid_fee, self.valid_currency) 58 self.assertEqual(item1.to_string(), u"(None, None, None)") 59 self.assertEqual(item2.to_string(), u"(u'%s', u'%s', u'%s')" % ( 60 self.valid_title, self.valid_fee, self.valid_currency)) 61 61 return 62 62 63 63 def test_from_string(self): 64 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) 65 myinput = u"(u'%s',u'%s',u'%s')" % ( 66 self.valid_title, self.valid_fee, self.valid_currency) 67 item1 = ProductOptionEntry.from_string(myinput) 68 item2 = ProductOptionEntry.from_string(u"(u'', u'', u'')") 69 item3 = ProductOptionEntry.from_string(u"(None, None, None)") 70 self.assertEqual(item1.title, self.valid_title) 71 self.assertEqual(item1.fee, self.valid_fee) 72 self.assertEqual(item1.currency, self.valid_currency) 73 self.assertTrue(item2.title is None) 74 self.assertTrue(item2.fee is None) 75 self.assertEqual(item2.currency, None) 76 self.assertTrue(item3.title is None) 77 self.assertTrue(item3.fee is None) 78 self.assertEqual(item3.currency, None) 76 79 return 77 80 78 class ResultEntryFieldTests(unittest.TestCase):81 class ProductOptionEntryFieldTests(unittest.TestCase): 79 82 80 83 def test_ifaces(self): 81 84 # make sure we implement the promised interfaces. 82 obj = ResultEntryField()83 verifyObject(I ResultEntryField, obj)84 verifyClass(I ResultEntryField, ResultEntryField)85 obj = ProductOptionEntryField() 86 verifyObject(IProductOptionEntryField, obj) 87 verifyClass(IProductOptionEntryField, ProductOptionEntryField) 85 88 return 86 89
Note: See TracChangeset for help on using the changeset viewer.