Back to index

plone3  3.1.7
test_SIC.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for SimpleIntCriterion module.
00014 
00015 $Id: test_SIC.py 68496 2006-06-05 16:30:18Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from common import CriterionTestCase
00022 
00023 
00024 class SimpleIntCriterionTests(CriterionTestCase):
00025 
00026     def _getTargetClass(self):
00027         from Products.CMFTopic.SimpleIntCriterion import SimpleIntCriterion
00028 
00029         return SimpleIntCriterion
00030 
00031     def test_Empty( self ):
00032         sic = self._makeOne('foo', 'foofield')
00033         self.assertEqual( sic.getId(), 'foo' )
00034         self.assertEqual( sic.field, 'foofield' )
00035         self.assertEqual( sic.value, None )
00036         self.assertEqual( sic.getValueString(), '' )
00037         self.assertEqual( len(sic.getCriteriaItems() ), 0 )
00038 
00039     def test_EditWithString( self ):
00040         sic = self._makeOne('foo', 'foofield')
00041         sic.edit('0')
00042         self.assertEqual( sic.value, 0 )
00043         self.assertEqual( sic.getValueString(), '0' )
00044 
00045         items = sic.getCriteriaItems()
00046         self.assertEqual( len( items ), 1 )
00047         self.assertEqual( len( items[0] ), 2 )
00048         self.assertEqual( items[0][0], 'foofield' )
00049         self.assertEqual( items[0][1], 0 )
00050 
00051     def test_EditWithInt( self ):
00052         sic = self._makeOne('foo', 'foofield')
00053         sic.edit( 32 )
00054         self.assertEqual( sic.value, 32 )
00055         self.assertEqual( sic.getValueString(), '32' )
00056 
00057         items = sic.getCriteriaItems()
00058         self.assertEqual( len(items), 1 )
00059         self.assertEqual( len(items[0]), 2 )
00060         self.assertEqual( items[0][1], 32 )
00061 
00062     def test_RangeMin( self ):
00063         sic = self._makeOne('foo', 'foofield')
00064         sic.edit( '32', self._getTargetClass().MINIMUM )
00065 
00066         self.assertEqual( sic.value, 32 )
00067         self.assertEqual( sic.getValueString(), '32' )
00068 
00069         items = sic.getCriteriaItems()
00070         self.assertEqual( len(items), 1 )
00071         self.assertEqual( len( items[0] ), 2 )
00072         self.assertEqual( items[0][0], 'foofield' )
00073         self.assertEqual( items[0][1]['query'], 32 )
00074         self.assertEqual( items[0][1]['range'], 'min' )
00075 
00076     def test_RangeMin_withInt( self ):
00077         sic = self._makeOne('foo', 'foofield')
00078         sic.edit( 32, self._getTargetClass().MINIMUM )
00079 
00080         self.assertEqual( sic.value, 32 )
00081         self.assertEqual( sic.getValueString(), '32' )
00082 
00083         items = sic.getCriteriaItems()
00084         self.assertEqual( len(items), 1 )
00085         self.assertEqual( len( items[0] ), 2 )
00086         self.assertEqual( items[0][0], 'foofield' )
00087         self.assertEqual( items[0][1]['query'], 32 )
00088         self.assertEqual( items[0][1]['range'], 'min' )
00089 
00090     def test_RangeMax( self ):
00091         sic = self._makeOne('foo', 'foofield')
00092         sic.edit( '32', self._getTargetClass().MAXIMUM )
00093 
00094         self.assertEqual( sic.value, 32 )
00095         self.assertEqual( sic.getValueString(), '32' )
00096 
00097         items = sic.getCriteriaItems()
00098         self.assertEqual( len(items), 1 )
00099         self.assertEqual( len( items[0] ), 2 )
00100         self.assertEqual( items[0][0], 'foofield' )
00101         self.assertEqual( items[0][1]['query'], 32 )
00102         self.assertEqual( items[0][1]['range'], 'max' )
00103 
00104     def test_RangeMax_withInt( self ):
00105         sic = self._makeOne('foo', 'foofield')
00106         sic.edit( 32, self._getTargetClass().MAXIMUM )
00107 
00108         self.assertEqual( sic.value, 32 )
00109         self.assertEqual( sic.getValueString(), '32' )
00110 
00111         items = sic.getCriteriaItems()
00112         self.assertEqual( len(items), 1 )
00113         self.assertEqual( len( items[0] ), 2 )
00114         self.assertEqual( items[0][0], 'foofield' )
00115         self.assertEqual( items[0][1]['query'], 32 )
00116         self.assertEqual( items[0][1]['range'], 'max' )
00117 
00118     def test_RangeMinMax( self ):
00119         sic = self._makeOne('foo', 'foofield')
00120         sic.edit( '32 34', self._getTargetClass().MINMAX )
00121 
00122         self.assertEqual( sic.value, ( 32, 34 ) )
00123         self.assertEqual( sic.getValueString(), '32 34' )
00124 
00125         items = sic.getCriteriaItems()
00126         self.assertEqual( len(items), 1 )
00127         self.assertEqual( len( items[0] ), 2 )
00128         self.assertEqual( items[0][0], 'foofield' )
00129         self.assertEqual( items[0][1]['query'], ( 32, 34 ) )
00130         self.assertEqual( items[0][1]['range'], 'min:max' )
00131 
00132     def test_RangeMinMax_withTuple( self ):
00133         sic = self._makeOne('foo', 'foofield')
00134         sic.edit( ( 32, 34 ), self._getTargetClass().MINMAX )
00135 
00136         self.assertEqual( sic.value, ( 32, 34 ) )
00137         self.assertEqual( sic.getValueString(), '32 34' )
00138 
00139         items = sic.getCriteriaItems()
00140         self.assertEqual( len(items), 1 )
00141         self.assertEqual( len( items[0] ), 2 )
00142         self.assertEqual( items[0][0], 'foofield' )
00143         self.assertEqual( items[0][1]['query'], ( 32, 34 ) )
00144         self.assertEqual( items[0][1]['range'], 'min:max' )
00145 
00146 
00147 def test_suite():
00148     return unittest.TestSuite((
00149         unittest.makeSuite(SimpleIntCriterionTests),
00150         ))
00151 
00152 if __name__ == '__main__':
00153     unittest.main(defaultTest='test_suite')