Back to index

plone3  3.1.7
testRelatedItems.py
Go to the documentation of this file.
00001 #
00002 # Tests the related items support
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 
00008 class TestRelatedItems(PloneTestCase.PloneTestCase):
00009 
00010     def testRelatedItems(self):
00011         # create two objects
00012         self.folder.invokeFactory('Document', id='obj1', title='Obj1')
00013         obj1 = self.folder.obj1
00014         self.folder.invokeFactory('Document', id='obj2', title='Obj2')
00015         obj2 = self.folder.obj2
00016 
00017         # relate them
00018         obj1.setRelatedItems([obj2.UID()])
00019 
00020         # call the script for retrieving the items
00021         related = obj1.computeRelatedItems()
00022 
00023         # check length
00024         self.assertEqual(len(related), 1)
00025 
00026         # check object
00027         self.assertEqual(related[0], obj2)
00028 
00029     def testNoRelatedItems(self):
00030         self.folder.invokeFactory('Document', id='obj1', title='Obj1')
00031         related = self.folder.obj1.computeRelatedItems()
00032         self.assertEqual(len(related), 0)
00033 
00034 
00035 def test_suite():
00036     from unittest import TestSuite, makeSuite
00037     suite = TestSuite()
00038     suite.addTest(makeSuite(TestRelatedItems))
00039     return suite