Back to index

plone3  3.1.7
testGetObjectSize.py
Go to the documentation of this file.
00001 #
00002 # Test the getObjSize script
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from Products.CMFPlone.tests import dummy
00007 
00008 
00009 class TestGetObjSize(PloneTestCase.PloneTestCase):
00010 
00011     def testZeroInt(self):
00012         self.assertEqual(self.portal.getObjSize(None, 0), "0 kB")
00013 
00014     def testBInt(self):
00015         self.assertEqual(self.portal.getObjSize(None, 234), "1 kB")
00016 
00017     def testKBInt(self):
00018         self.assertEqual(self.portal.getObjSize(None, 5678), "5.5 kB")
00019 
00020     def testMBInt(self):
00021         self.assertEqual(self.portal.getObjSize(None, 3307520), "3.2 MB")
00022 
00023     def testGBInt(self):
00024         self.assertEqual(self.portal.getObjSize(None, 7564738298), "7.0 GB")
00025 
00026     def testZeroFloat(self):
00027         self.assertEqual(self.portal.getObjSize(None, 0.0), "0 kB")
00028 
00029     def testBFloat(self):
00030         self.assertEqual(self.portal.getObjSize(None, 234.5), "1 kB")
00031 
00032     def testKBFloat(self):
00033         self.assertEqual(self.portal.getObjSize(None, 5678.5), "5.5 kB")
00034 
00035     def testMBFloat(self):
00036         self.assertEqual(self.portal.getObjSize(None, 3307520.5), "3.2 MB")
00037 
00038     def testGBFloat(self):
00039         self.assertEqual(self.portal.getObjSize(None, 7564738298.5), "7.0 GB")
00040 
00041     def testNone(self):
00042         self.assertEqual(self.portal.getObjSize(None, None), "0 kB")
00043 
00044     def testEmptyString(self):
00045         self.assertEqual(self.portal.getObjSize(None, ''), "0 kB")
00046 
00047     def testNonIntString(self):
00048         self.assertEqual(self.portal.getObjSize(None, 'barney'), 'barney')
00049 
00050     
00051 class TestGetObjSizedItem(PloneTestCase.PloneTestCase):
00052 
00053     def afterSetUp(self):
00054         self.ob = dummy.SizedItem()
00055 
00056     def testZero(self):
00057         self.ob.set_size(0)
00058         self.assertEquals(self.portal.getObjSize(self.ob), '0 kB')
00059 
00060     def testBInt(self):
00061         self.ob.set_size(884)
00062         self.assertEquals(self.portal.getObjSize(self.ob), '1 kB')
00063 
00064     def testKBInt(self):
00065         self.ob.set_size(1348)
00066         self.assertEquals(self.portal.getObjSize(self.ob), '1.3 kB')
00067 
00068     def testMBInt(self):
00069         self.ob.set_size(1024*1024+1024*687)
00070         self.assertEquals(self.portal.getObjSize(self.ob), '1.7 MB')
00071 
00072     def testGBInt(self):
00073         self.ob.set_size(1024*1024*1024+1024*1024*107)
00074         self.assertEquals(self.portal.getObjSize(self.ob), '1.1 GB')
00075 
00076     def testGBFloat(self):
00077         self.ob.set_size(float(1024*1024*1024+1024*1024*107))
00078         self.assertEquals(self.portal.getObjSize(self.ob), '1.1 GB')
00079 
00080 
00081 def test_suite():
00082     from unittest import TestSuite, makeSuite
00083     suite = TestSuite()
00084     suite.addTest(makeSuite(TestGetObjSize))
00085     suite.addTest(makeSuite(TestGetObjSizedItem))
00086     return suite