Back to index

plone3  3.1.7
test_fti.py
Go to the documentation of this file.
00001 from Products.CMFDynamicViewFTI.tests import CMFDVFTITestCase
00002 
00003 from zope.interface import Interface
00004 
00005 from Interface.Verify import verifyObject
00006 from Products.CMFCore.utils import getToolByName
00007 
00008 try:
00009     from Products.CMFCore.interfaces import ITypeInformation
00010 except ImportError:
00011     from Products.CMFCore.interfaces.portal_types import ContentTypeInformation as \
00012         ITypeInformation
00013 
00014 from Products.CMFDynamicViewFTI.interfaces import IDynamicViewTypeInformation
00015 from Products.CMFDynamicViewFTI.fti import DynamicViewTypeInformation
00016 
00017 fti_meta_type = DynamicViewTypeInformation.meta_type
00018 
00019 
00020 class TestFTI(CMFDVFTITestCase.CMFDVFTITestCase):
00021 
00022     def afterSetUp(self):
00023         self.types = getToolByName(self.portal, 'portal_types')
00024         self.fti = self.types['DynFolder']
00025 
00026     def _makeOne(self):
00027         # Create and return a DynFolder
00028         self.folder.invokeFactory('DynFolder', id='dynfolder')
00029         return self.folder.dynfolder
00030 
00031     def test_doesImplementITypeInformation(self):
00032         iface = ITypeInformation
00033         if issubclass(iface, Interface):
00034             self.failUnless(iface.providedBy(self.fti))
00035         else:
00036             self.failUnless(iface.isImplementedBy(self.fti))
00037             self.failUnless(verifyObject(iface, self.fti))
00038 
00039     def test_doesImplementIDynamicViewTypeInformation(self):
00040         iface = IDynamicViewTypeInformation
00041         self.failUnless(iface.isImplementedBy(self.fti))
00042         self.failUnless(verifyObject(iface, self.fti))
00043 
00044     def test_meta_type(self):
00045         self.failUnlessEqual(self.fti.meta_type, fti_meta_type)
00046 
00047     def test_paranoid_subclass_test(self):
00048         self.failUnless(isinstance(self.fti, DynamicViewTypeInformation))
00049 
00050     def test_CreateDynFolder(self):
00051         dynfolder = self._makeOne()
00052         self.assertEqual(dynfolder.getPortalTypeName(), 'DynFolder')
00053         info = self.types.getTypeInfo(dynfolder)
00054         self.assertEqual(info.getId(), 'DynFolder')
00055         self.assertEqual(info.Title(), 'DynFolder')
00056         self.assertEqual(info.getDefaultViewMethod(dynfolder), 'index_html')
00057         self.assertEqual(info.getAvailableViewMethods(dynfolder), ('index_html', 'custom_view', 'zope3_view'))
00058 
00059     def test_DynFolderDefaultView(self):
00060         dynfolder = self._makeOne()
00061         info = self.types.getTypeInfo(dynfolder)
00062         self.assertEqual(info.getViewMethod(dynfolder), 'index_html')
00063 
00064     def test_DynFolderCustomView(self):
00065         dynfolder = self._makeOne()
00066         self.types.DynFolder.manage_changeProperties(default_view='custom_view')
00067         info = self.types.getTypeInfo(dynfolder)
00068         self.assertEqual(info.getViewMethod(dynfolder), 'custom_view')
00069 
00070     def test_DynFolderViewFromLayout(self):
00071         dynfolder = self._makeOne()
00072         dynfolder.layout = 'custom_view'
00073         info = self.types.getTypeInfo(dynfolder)
00074         self.assertEqual(info.getViewMethod(dynfolder), 'custom_view')
00075 
00076     def test_DynFolderViewFromCallableLayout(self):
00077         dynfolder = self._makeOne()
00078         dynfolder.layout = lambda: 'custom_view'
00079         info = self.types.getTypeInfo(dynfolder)
00080         self.assertEqual(info.getViewMethod(dynfolder), 'custom_view')
00081 
00082     def test_NoneLayoutReturnsDefaultView(self):
00083         dynfolder = self._makeOne()
00084         dynfolder.layout = None
00085         info = self.types.getTypeInfo(dynfolder)
00086         self.assertEqual(info.getViewMethod(dynfolder), 'index_html')
00087 
00088     def test_EmptyLayoutReturnsDefaultView(self):
00089         dynfolder = self._makeOne()
00090         dynfolder.layout = ''
00091         info = self.types.getTypeInfo(dynfolder)
00092         self.assertEqual(info.getViewMethod(dynfolder), 'index_html')
00093 
00094     def test_InvalidLayoutRaisesTypeError(self):
00095         dynfolder = self._makeOne()
00096         dynfolder.layout = object()
00097         info = self.types.getTypeInfo(dynfolder)
00098         self.assertRaises(TypeError, info.getViewMethod, dynfolder)
00099 
00100     def test_EnforceLayoutAvailable(self):
00101         dynfolder = self._makeOne()
00102         dynfolder.layout = 'custom_view'
00103         info = self.types.getTypeInfo(dynfolder)
00104         self.assertEqual(info.getViewMethod(dynfolder, enforce_available=True), 'custom_view')
00105 
00106     def test_UnavailableLayoutReturnsDefaultView(self):
00107         dynfolder = self._makeOne()
00108         dynfolder.layout = 'bad_view'
00109         info = self.types.getTypeInfo(dynfolder)
00110         self.assertEqual(info.getViewMethod(dynfolder, enforce_available=True), 'index_html')
00111 
00112     def test_CheckLayoutExists(self):
00113         dynfolder = self._makeOne()
00114         dynfolder.manage_addDTMLMethod('custom_view', file='')
00115         dynfolder.layout = 'custom_view'
00116         info = self.types.getTypeInfo(dynfolder)
00117         self.assertEqual(info.getViewMethod(dynfolder, check_exists=True), 'custom_view')
00118 
00119     def test_MissingLayoutReturnsDefaultView(self):
00120         dynfolder = self._makeOne()
00121         dynfolder.layout = 'bad_view'
00122         info = self.types.getTypeInfo(dynfolder)
00123         self.assertEqual(info.getViewMethod(dynfolder, check_exists=True), 'index_html')
00124 
00125     def test_DynFolderDefaultPage(self):
00126         dynfolder = self._makeOne()
00127         info = self.types.getTypeInfo(dynfolder)
00128         self.assertEqual(info.getDefaultPage(dynfolder), None)
00129 
00130     def test_DynFolderDefaultPageFromAttribute(self):
00131         dynfolder = self._makeOne()
00132         dynfolder.default_page = 'custom_page'
00133         info = self.types.getTypeInfo(dynfolder)
00134         self.assertEqual(info.getDefaultPage(dynfolder), 'custom_page')
00135 
00136     def test_DynFolderDefaultPageFromCallable(self):
00137         dynfolder = self._makeOne()
00138         dynfolder.default_page = lambda: 'custom_page'
00139         info = self.types.getTypeInfo(dynfolder)
00140         self.assertEqual(info.getDefaultPage(dynfolder), 'custom_page')
00141 
00142     def test_NoneDefaultPageReturnsNone(self):
00143         dynfolder = self._makeOne()
00144         dynfolder.default_page = None
00145         info = self.types.getTypeInfo(dynfolder)
00146         self.assertEqual(info.getDefaultPage(dynfolder), None)
00147 
00148     def test_EmptyDefaultPageReturnsNone(self):
00149         dynfolder = self._makeOne()
00150         dynfolder.default_page = ''
00151         info = self.types.getTypeInfo(dynfolder)
00152         self.assertEqual(info.getDefaultPage(dynfolder), None)
00153 
00154     def test_InvalidDefaultPageRaisesTypeError(self):
00155         dynfolder = self._makeOne()
00156         dynfolder.default_page = object()
00157         info = self.types.getTypeInfo(dynfolder)
00158         self.assertRaises(TypeError, info.getDefaultPage, dynfolder)
00159 
00160     def test_CheckDefaultPageExists(self):
00161         dynfolder = self._makeOne()
00162         dynfolder.manage_addDTMLMethod('custom_page', file='')
00163         dynfolder.default_page = 'custom_page'
00164         info = self.types.getTypeInfo(dynfolder)
00165         self.assertEqual(info.getDefaultPage(dynfolder, check_exists=True), 'custom_page')
00166 
00167     def test_MissingDefaultPageReturnsNone(self):
00168         dynfolder = self._makeOne()
00169         dynfolder.default_page = 'bad_page'
00170         info = self.types.getTypeInfo(dynfolder)
00171         self.assertEqual(info.getDefaultPage(dynfolder, check_exists=True), None)
00172 
00173     def test_NonFolderishObjectReturnsNone(self):
00174         dynfolder = self._makeOne()
00175         dynfolder.isPrincipiaFolderish = 0
00176         dynfolder.default_page = 'custom_page'
00177         info = self.types.getTypeInfo(dynfolder)
00178         self.assertEqual(info.getDefaultPage(dynfolder), None)
00179 
00180 
00181 class TestEmptyLayoutBug(CMFDVFTITestCase.FunctionalTestCase):
00182     # Finally, here is why we did all this...
00183 
00184     def afterSetUp(self):
00185         # Make a DynFolder
00186         self.folder.invokeFactory('DynFolder', id='dynfolder')
00187         self.dynfolder = self.folder.dynfolder
00188         self.dynfolder.layout = '' # Empty layout triggers bug
00189         self.dynfolder_path = self.dynfolder.absolute_url(1)
00190 
00191         # Make a DynDocument
00192         self.folder.invokeFactory('DynDocument', id='dyndocument')
00193         self.dyndocument = self.folder.dyndocument
00194         self.dyndocument.layout = '' # Empty layout triggers bug
00195         self.dyndocument_path = self.dyndocument.absolute_url(1)
00196 
00197         self.basic = '%s:%s' % (CMFDVFTITestCase.default_user,
00198                                 CMFDVFTITestCase.default_password)
00199 
00200     def test_FolderEmptyLayoutBug(self):
00201         response = self.publish(self.dynfolder_path+'/view', basic=self.basic)
00202         self.assertEqual(response.getStatus(), 200)
00203 
00204     def test_DocumentEmptyLayoutBug(self):
00205         response = self.publish(self.dyndocument_path+'/view', basic=self.basic)
00206         self.assertEqual(response.getStatus(), 200)
00207 
00208 
00209 def test_suite():
00210     from unittest import TestSuite, makeSuite
00211     suite = TestSuite()
00212     suite.addTest(makeSuite(TestFTI))
00213     suite.addTest(makeSuite(TestEmptyLayoutBug))
00214     return suite