Ignore:
Timestamp:
24 Dec 2014, 07:38:53 (10 years ago)
Author:
Henrik Bettermann
Message:

Turn ResultEntry? (school grades) components into ProductOptionEntry? components.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/tests/test_schoolgrades.py

    r11949 r12306  
    11# Tests for schoolgrades module.
    22import unittest
     3from decimal import Decimal
    34from zope.component import getGlobalSiteManager
    45from zope.interface.verify import verifyObject, verifyClass
    5 from zope.schema.interfaces import ConstraintNotSatisfied
    6 from waeup.ikoba.interfaces import IResultEntry, IResultEntryField, IIkobaUtils
    7 from waeup.ikoba.schoolgrades import ResultEntry, ResultEntryField
     6from zope.schema.interfaces import ConstraintNotSatisfied, WrongType
     7from waeup.ikoba.interfaces import IProductOptionEntry, IProductOptionEntryField, IIkobaUtils
     8from waeup.ikoba.schoolgrades import ProductOptionEntry, ProductOptionEntryField
    89from waeup.ikoba.utils.utils import IkobaUtils
    910
    10 class ResultEntryTests(unittest.TestCase):
     11class ProductOptionEntryTests(unittest.TestCase):
    1112
    1213    def setUp(self):
     
    1415        self.gsm = getGlobalSiteManager()
    1516        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'
    1820        return
    1921
     
    2426    def test_ifaces(self):
    2527        # make sure we implement the promised interfaces.
    26         obj = ResultEntry()
    27         verifyObject(IResultEntry, obj)
    28         verifyClass(IResultEntry, ResultEntry)
     28        obj = ProductOptionEntry()
     29        verifyObject(IProductOptionEntry, obj)
     30        verifyClass(IProductOptionEntry, ProductOptionEntry)
    2931        return
    3032
    3133    def test_init(self):
    3234        # 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)
    3944        return
    4045
    4146    def test_illegal_value(self):
    42         # we do not accept values not stored in IkobaUtils
    43         item = ResultEntry()
     47        # we do not accept values which do not meet the interface
     48        item = ProductOptionEntry()
    4449        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')
    5251        return
    5352
    5453    def test_to_string(self):
    5554        # 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))
    6161        return
    6262
    6363    def test_from_string(self):
    6464        # 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)
    7679        return
    7780
    78 class ResultEntryFieldTests(unittest.TestCase):
     81class ProductOptionEntryFieldTests(unittest.TestCase):
    7982
    8083    def test_ifaces(self):
    8184        # make sure we implement the promised interfaces.
    82         obj = ResultEntryField()
    83         verifyObject(IResultEntryField, obj)
    84         verifyClass(IResultEntryField, ResultEntryField)
     85        obj = ProductOptionEntryField()
     86        verifyObject(IProductOptionEntryField, obj)
     87        verifyClass(IProductOptionEntryField, ProductOptionEntryField)
    8588        return
    8689
Note: See TracChangeset for help on using the changeset viewer.