Back to index

plone3  3.1.7
test_ListC.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 ListCriterion module.
00014 
00015 $Id: test_ListC.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 ListCriterionTests(CriterionTestCase):
00025 
00026     def _getTargetClass(self):
00027         from Products.CMFTopic.ListCriterion import ListCriterion
00028 
00029         return ListCriterion
00030 
00031     def test_Empty( self ):
00032         listc = self._makeOne('foo', 'foofield')
00033 
00034         self.assertEqual( listc.getId(), 'foo' )
00035         self.assertEqual( listc.field, 'foofield' )
00036         self.assertEqual( listc.value, ('',) )
00037         self.assertEqual( len(listc.getCriteriaItems()), 0 )
00038 
00039     def test_Edit_withString( self ):
00040         listc = self._makeOne('foo', 'foofield')
00041 
00042         listc.edit('bar\nbaz')
00043         self.assertEqual( listc.getId(), 'foo' )
00044         self.assertEqual( listc.field, 'foofield' )
00045         self.assertEqual( listc.value, ( 'bar', 'baz' ) )
00046 
00047         items = listc.getCriteriaItems()
00048         self.assertEqual( len( items ), 1 )
00049         self.assertEqual( len( items[0] ), 2 )
00050         self.assertEqual( items[0][0], 'foofield' )
00051         self.assertEqual( items[0][1], ( 'bar', 'baz' ) )
00052 
00053     def test_Edit_withList( self ):
00054         listc = self._makeOne('foo', 'foofield')
00055 
00056         abc = [ 'a', 'b', 'c' ]
00057         listc.edit( abc )
00058 
00059         items = listc.getCriteriaItems()
00060         self.failUnless( 'foofield' in map( lambda x: x[0], items ) )
00061         self.failUnless( tuple( abc ) in map( lambda x: x[1], items ) )
00062 
00063     def test_operator( self ):
00064         listc = self._makeOne('foo', 'foofield')
00065 
00066         abc = [ 'a', 'b', 'c' ]
00067 
00068         listc.edit( abc )
00069         items = listc.getCriteriaItems()
00070         self.assertEqual( len( items ), 1 )
00071 
00072         listc.edit( abc, 'or' )
00073         items = listc.getCriteriaItems()
00074         self.assertEqual( len( items ), 2 )
00075         self.failUnless( ( 'foofield_operator', 'or' ) in items )
00076 
00077         listc.edit( abc, 'and' )
00078         items = listc.getCriteriaItems()
00079         self.assertEqual( len( items ), 2 )
00080         self.failUnless( ( 'foofield_operator', 'and' ) in items )
00081 
00082 
00083 def test_suite():
00084     return unittest.TestSuite((
00085         unittest.makeSuite(ListCriterionTests),
00086         ))
00087 
00088 if __name__ == '__main__':
00089     unittest.main(defaultTest='test_suite')