Back to index

plone3  3.1.7
test_sitepolicy.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 
00026 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00027 from Products.Archetypes.tests.utils import makeContent
00028 from Products.Archetypes.examples import ComplexType as complextype
00029 from Products.Archetypes.ClassGen import generateCtor
00030 
00031 from DateTime import DateTime
00032 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
00033 
00034 
00035 class SitePolicyTests(ATSiteTestCase):
00036     demo_types = ['DDocument', 'SimpleType', 'SimpleFolder',
00037                   'Fact', 'ComplexType']
00038 
00039     # This test sucks, it doesn't test a unit, or assert anything
00040     # useful --bcsaller
00041     ##def test_new( self ):
00042     ##    # catalog should have one entry, for index_html or frontpage
00043     ##    # and another for Members
00044     ##    self.assertEqual( len( self.portal.portal_catalog ), 2 )
00045 
00046     def test_availabledemotypes(self):
00047         portal_types = self.portal.portal_types.listContentTypes()
00048         for t in self.demo_types:
00049             self.failUnless(t in portal_types,
00050                             "%s not available in portal_types." % t)
00051 
00052     def test_creationdemotypes(self):
00053         for t in self.demo_types:
00054             content = makeContent(self.folder, portal_type=t, id=t)
00055             self.failUnless(t in self.folder.contentIds())
00056             self.failUnless(not isinstance(content, DefaultDublinCoreImpl))
00057 
00058     # XXX Tests for some basic methods. Should be moved to
00059     # a separate test suite.
00060     def test_ComplexTypeGetSize(self):
00061         content = makeContent(self.folder, portal_type='ComplexType', id='ct')
00062         size = content.get_size()
00063         now = DateTime()
00064         content.setExpirationDate(now)
00065         # subtract 4 because an empty DateTime field has this size
00066         new_size = size + len(str(now)) - 4
00067         self.assertEqual(new_size, content.get_size())
00068         content.setEffectiveDate(now)
00069         new_size = new_size + len(str(now)) - 4
00070         self.assertEqual(new_size, content.get_size())
00071         content.setIntegerfield(100)
00072         new_size = new_size -1
00073         self.assertEqual(new_size, content.get_size())
00074         content.setIntegerfield(1)
00075         new_size = new_size - 2
00076         self.assertEqual(new_size, content.get_size())
00077         text = 'Bla bla bla'
00078         content.setTextfield(text)
00079         new_size = new_size + len(text)
00080         self.assertEqual(new_size, content.get_size())
00081 
00082     def test_SimpleFolderGetSize(self):
00083         content = makeContent(self.folder, portal_type='SimpleFolder', id='sf')
00084         size = content.get_size()
00085         now = DateTime()
00086         content.setExpirationDate(now)
00087         new_size = size + len(str(now)) - 4
00088         self.assertEqual(new_size, content.get_size())
00089         content.setEffectiveDate(now)
00090         new_size = new_size + len(str(now)) - 4
00091         self.assertEqual(new_size, content.get_size())
00092         text = 'Bla bla bla'
00093         content.setTitle(text)
00094         new_size = new_size + len(text)
00095         self.assertEqual(new_size, content.get_size())
00096 
00097     def test_addComplexTypeCtor(self):
00098         addComplexType = generateCtor('ComplexType', complextype)
00099         id = addComplexType(self.folder, id='complex_type',
00100                             textfield='Bla', integerfield=1,
00101                             stringfield='A String')
00102         obj = getattr(self.folder, id)
00103         self.assertEqual(obj.getTextfield(), 'Bla')
00104         self.assertEqual(obj.getStringfield(), 'A String')
00105         self.assertEqual(obj.getIntegerfield(), 1)
00106 
00107 
00108 def test_suite():
00109     from unittest import TestSuite, makeSuite
00110     suite = TestSuite()
00111     suite.addTest(makeSuite(SitePolicyTests))
00112     return suite