[CMF-checkins] CVS: CMF - test_AllTopic.py:1.1 test_DateC.py:1.1

Jeffrey Shell jeffrey@digicool.com
Fri, 30 Mar 2001 11:51:43 -0500 (EST)


Update of /cvs-repository/CMF/CMFTopic/tests
In directory korak:/home/jeffrey/InstanceHomes/cmf-dev/CMF/CMFTopic/tests

Added Files:
	test_AllTopic.py test_DateC.py 
Log Message:
Added new DateCriteria module, which currently only has the FriendlyDate criterion class, and will have a couple more date oriented ones in the future.  Also added new test suite for the Date Criteria, and an all singing AllTopic test module that runs all of the topic test suites in one.


--- Added File test_AllTopic.py in package CMF ---
import unittest
from Products.CMFTopic.tests import test_Topic, test_DateC, test_ListC, \
     test_SIC, test_SSC

def main():
    suite = unittest.TestSuite((
        test_Topic.test_suite(),
        test_DateC.test_suite(),
        test_ListC.test_suite(),
        test_SIC.test_suite(),
        test_SSC.test_suite(),
        ))
    unittest.TextTestRunner().run(suite)

if __name__ == '__main__':
    main()
    

--- Added File test_DateC.py in package CMF ---
import unittest
import Products.CMFTopic.DateCriteria
from DateTime.DateTime import DateTime

FriendlyDate = Products.CMFTopic.DateCriteria.FriendlyDateCriterion

class FriendlyDateTest(unittest.TestCase):
    lessThanFiveDaysOld = {
        'value': 4,
        'operation': 'min',
        'daterange': 'old',
        }

    lessThanOneMonthAhead = {
        'value': 30,
        'operation': 'max',
        'daterange': 'ahead',
        }

    def test_Empty(self):
        friendly = FriendlyDate('foo', 'foofield')
        assert friendly.id == 'foo'
        assert friendly.field == 'foofield'
        assert friendly.value == None, 'Value should be None'
        assert friendly.operation == 'min', 'Operator should be min'
        assert friendly.daterange == 'old'
        assert len(friendly.getCriteriaItems()) == 0

    def test_ListOfDefaultDates(self):
        friendly = FriendlyDate('foo','foofield')
        d = friendly.defaultDateOptions()
        assert d[1][0] == 2, 'Expected 2, got %s' % d[1][0]

    def test_Basic(self):
        friendly = FriendlyDate('foo', 'foofield')
        friendly.edit(value=None)
        assert friendly.value == None
        assert friendly.daterange == 'old'
        assert friendly.operation == 'min'
        
        apply(friendly.edit, (), self.lessThanFiveDaysOld)
        assert friendly.value == 4
        assert friendly.operation == 'min'
        assert friendly.daterange == 'old'

        # Bogus value on the operation
        try: friendly.edit(4, 'min:max', 'new')
        except ValueError: pass
        except: raise

    def test_StringAsValue(self):
        friendly = FriendlyDate('foo', 'foofield')
        friendly.edit('4')
        assert friendly.value == 4

        friendly.edit('-4')
        assert friendly.value == -4

        friendly.edit('')
        assert friendly.value is None

        # Bogus value on the, well, value
        try: friendly.edit('blah')
        except ValueError: pass
        except: raise

    def test_FiveDaysOld(self):
        date = (DateTime() - 4).Date()
        friendly = FriendlyDate('foo', 'foofield')
        apply(friendly.edit, (), self.lessThanFiveDaysOld)

        result = friendly.getCriteriaItems()
        assert friendly.daterange == 'old'
        
        assert len(result) == 2
        assert result[0][0] == 'foofield'
        assert result[0][1].Date() == date, 'Result %s not expected %s' % (
            result[0][1].Date(), date)
        assert result[1][0] == 'foofield_usage'
        assert result[1][1] == 'range:min'

    def test_OneMonthAhead(self):
        date = (DateTime() + 30).Date()
        friendly = FriendlyDate('foo', 'foofield')
        apply(friendly.edit, (), self.lessThanOneMonthAhead)
        result = friendly.getCriteriaItems()
        assert friendly.daterange == 'ahead'

        assert result[0][1].Date() == date, 'Result %s not expected %s' % (
            result[0][1].Date(), date)
        assert result[1][1] == 'range:max'

def test_suite():
    return unittest.makeSuite(FriendlyDateTest)

if __name__ == '__main__':
    unittest.TextTestRunner().run(test_suite())