Back to index

plone3  3.1.7
test_atfolder.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 
00022 __author__ = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase, atctftestcase
00027 
00028 import transaction
00029 from Acquisition import aq_base
00030 
00031 from Products.Archetypes.atapi import *
00032 from Products.ATContentTypes.tests.utils import dcEdit
00033 
00034 from Products.ATContentTypes.content.folder import ATFolder
00035 from Products.ATContentTypes.content.folder import ATBTreeFolder
00036 from Products.CMFPlone.PloneFolder import PloneFolder
00037 from OFS.IOrderSupport import IOrderedContainer as IZopeOrderedContainer
00038 from OFS.interfaces import IOrderedContainer as OFSIOrderedContainer
00039 from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer
00040 from Products.ATContentTypes.interfaces import IATFolder
00041 from Products.ATContentTypes.interfaces import IATBTreeFolder
00042 
00043 from zope.interface.verify import verifyClass
00044 
00045 from Products.ATContentTypes.interfaces import IAutoSortSupport
00046 from Products.ATContentTypes.interfaces import IAutoOrderSupport
00047 from Interface.Verify import verifyObject
00048 
00049 from Products.CMFPlone.interfaces.ConstrainTypes import ISelectableConstrainTypes
00050 
00051 # z3 imports
00052 from Products.ATContentTypes.interface import IAutoSortSupport as Z3IAutoSortSupport
00053 from Products.ATContentTypes.interface import IAutoOrderSupport as Z3IAutoOrderSupport
00054 from Products.ATContentTypes.interface import IATFolder as Z3IATFolder
00055 from Products.ATContentTypes.interface import IATBTreeFolder as Z3IATBTreeFolder
00056 from zope.interface.verify import verifyObject as Z3verifyObject
00057 
00058 def editATCT(obj):
00059     dcEdit(obj)
00060 
00061 tests = []
00062 
00063 
00064 class FolderTestMixin:
00065     """Contains some general tests for both ATFolder and ATBTreeFolder
00066     """
00067     def test_implementsConstrainTypes(self):
00068         self.failUnless(ISelectableConstrainTypes.isImplementedBy(self._ATCT))
00069         self.failUnless(verifyObject(ISelectableConstrainTypes, self._ATCT))
00070 
00071     def test_implements_autosort(self):
00072         self.failUnless(IAutoSortSupport.isImplementedBy(self._ATCT))
00073         self.failUnless(verifyObject(IAutoSortSupport, self._ATCT))
00074 
00075     def test_implementsZ3_autosort(self):
00076         iface = Z3IAutoSortSupport
00077         self.failUnless(Z3verifyObject(iface, self._ATCT))
00078 
00079 class TestSiteATFolder(atcttestcase.ATCTTypeTestCase, FolderTestMixin):
00080 
00081     klass = ATFolder
00082     portal_type = 'Folder'
00083     title = 'Folder'
00084     meta_type = 'ATFolder'
00085     icon = 'folder_icon.gif'
00086 
00087     def test_implementsOrderInterface(self):
00088         self.failUnless(OFSIOrderedContainer.providedBy(self._ATCT))
00089         self.failUnless(IZopeOrderedContainer.isImplementedBy(self._ATCT))
00090         self.failUnless(IOrderedContainer.isImplementedBy(self._ATCT))
00091         self.failUnless(verifyObject(IZopeOrderedContainer, self._ATCT))
00092         self.failUnless(verifyObject(IOrderedContainer, self._ATCT))
00093 
00094     def test_implementsATFolder(self):
00095         iface = IATFolder
00096         self.failUnless(iface.isImplementedBy(self._ATCT))
00097         self.failUnless(verifyObject(iface, self._ATCT))
00098 
00099     def test_Z3implementsATFolder(self):
00100         iface = Z3IATFolder
00101         self.failUnless(Z3verifyObject(iface, self._ATCT))
00102 
00103     def test_implementsConstrainTypes(self):
00104         iface = ISelectableConstrainTypes
00105         self.failUnless(iface.isImplementedBy(self._ATCT))
00106         self.failUnless(verifyObject(iface, self._ATCT))
00107 
00108     def test_edit(self):
00109         new = self._ATCT
00110         editATCT(new)
00111 
00112     def test_implements_autoorder(self):
00113         self.failUnless(IAutoOrderSupport.isImplementedBy(self._ATCT))
00114         self.failUnless(verifyObject(IAutoOrderSupport, self._ATCT))
00115 
00116     def test_Z3implements_autoorder(self):
00117         pass
00118         #iface = Z3IAutoOrderSupport
00119         #self.failUnless(Z3verifyObject(iface, self._ATCT))
00120         # XXX Archetypes not ready for Zope3 OrderedContainer (see zope.app.container.interfaces)
00121 
00122     def test_get_size(self):
00123         atct = self._ATCT
00124         self.failUnlessEqual(atct.get_size(), 1)
00125 
00126     def test_schema_marshall(self):
00127         pass
00128 
00129 tests.append(TestSiteATFolder)
00130 
00131 class TestSiteATBTreeFolder(atcttestcase.ATCTTypeTestCase, FolderTestMixin):
00132 
00133     klass = ATBTreeFolder
00134     portal_type = 'Large Plone Folder'
00135     title = 'Large Folder'
00136     meta_type = 'ATBTreeFolder'
00137     icon = 'folder_icon.gif'
00138 
00139     def test_implementsATBTreeFolder(self):
00140         iface = IATBTreeFolder
00141         self.failUnless(iface.isImplementedBy(self._ATCT))
00142         self.failUnless(verifyObject(iface, self._ATCT))
00143 
00144     def test_Z3implementsATBTreeFolder(self):
00145         iface = Z3IATBTreeFolder
00146         self.failUnless(Z3verifyObject(iface, self._ATCT))
00147 
00148     def test_implementsConstrainTypes(self):
00149         iface = ISelectableConstrainTypes
00150         self.failUnless(iface.isImplementedBy(self._ATCT))
00151         self.failUnless(verifyObject(iface, self._ATCT))
00152 
00153     def test_isNotOrdered(self):
00154         iface = IZopeOrderedContainer
00155         self.failIf(iface.isImplementedBy(self._ATCT))
00156 
00157     def test_edit(self):
00158         new = self._ATCT
00159         editATCT(new)
00160         self.failUnless('Test title' == new.Title())
00161         self.failUnless('Test description' == new.Description())
00162 
00163     def test_get_size(self):
00164         atct = self._ATCT
00165         self.failUnlessEqual(atct.get_size(), 1)
00166 
00167     def test_schema_marshall(self):
00168         pass
00169 
00170 tests.append(TestSiteATBTreeFolder)
00171 
00172 class TestATFolderFields(atcttestcase.ATCTFieldTestCase):
00173 
00174     def afterSetUp(self):
00175         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00176         self._dummy = self.createDummy(klass=ATFolder)
00177 
00178     def test_field_enableConstrainMixin(self):
00179         pass
00180         #self.fail('not implemented')
00181 
00182     def test_field_locallyAllowedTypes(self):
00183         pass
00184         #self.fail('not implemented')
00185 
00186 tests.append(TestATFolderFields)
00187 
00188 class TestATBTreeFolderFields(TestATFolderFields):
00189 
00190     def afterSetUp(self):
00191         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00192         self._dummy = self.createDummy(klass=ATBTreeFolder)
00193 
00194 tests.append(TestATBTreeFolderFields)
00195 
00196 class TestAutoSortSupport(atcttestcase.ATCTSiteTestCase):
00197 
00198     def afterSetUp(self):
00199         atcttestcase.ATCTSiteTestCase.afterSetUp(self)
00200         self.folder.invokeFactory('Folder', 'fobj', title='folder 1')
00201         self.fobj = self.folder.fobj
00202         self.objs = (('Document', 'x1', 'Document 3'),
00203                      ('Document', 'x2', 'Document 4'),
00204                      ('Document', 'doc1', 'Document 1'),
00205                      ('Document', 'doc2', 'Document 2'),
00206                      ('Folder', 'folder1', 'Folder 1'),
00207                      ('Folder', 'folder2', 'Folder 2'),
00208                     )
00209         for pt, id, title in self.objs:
00210             self.fobj.invokeFactory(pt, id, title=title)
00211 
00212     def test_autoordering(self):
00213         f = self.fobj
00214         self.failUnlessEqual(f.getDefaultSorting(), ('Title', False))
00215         self.failUnlessEqual(f.getSortFolderishFirst(), True)
00216         self.failUnlessEqual(f.getSortReverse(), False)
00217         self.failUnlessEqual(f.getSortAuto(), True)
00218 
00219         f.setDefaultSorting('getId', reverse=True)
00220         f.setSortFolderishFirst(False)
00221         f.setSortReverse(True)
00222         f.setSortAuto(False)
00223 
00224         self.failUnlessEqual(f.getDefaultSorting(), ('getId', True))
00225         self.failUnlessEqual(f.getSortFolderishFirst(), False)
00226         self.failUnlessEqual(f.getSortReverse(), True)
00227         self.failUnlessEqual(f.getSortAuto(), False)
00228 
00229     def test_strangeUnallowedIds(self):
00230         """ Certain IDs used to give an error and are unusable
00231 
00232         They're set in zope's lib/python/App/Product.py. Examples:
00233         home, version. This test used to include 'icon', too, but that's
00234         apparently really an id that's already been taken (instead of
00235         a bug).
00236         """
00237         strangeIds = ['home', 'version']
00238         for id in strangeIds:
00239             self.folder.invokeFactory('Folder', id)
00240             self.assert_(id in self.folder.objectIds())
00241 
00242     # TODO: more tests
00243 
00244 tests.append(TestAutoSortSupport)
00245 
00246 class TestATFolderFunctional(atctftestcase.ATCTIntegrationTestCase):
00247     
00248     portal_type = 'Folder'
00249     views = ('folder_listing', 'atct_album_view', )
00250 
00251     def test_dynamic_view_without_view(self):
00252         # dynamic view mixin should work
00253         response = self.publish('%s/' % self.obj_path, self.basic_auth)
00254         self.assertStatusEqual(response.getStatus(), 200) #
00255         
00256     def test_selectViewTemplate(self):
00257         # create an object using the createObject script
00258         response = self.publish(self.obj_path +
00259                                 '/selectViewTemplate?templateId=atct_album_view',
00260                                 self.owner_auth)
00261         self.failUnlessEqual(self.obj.getLayout(), 'atct_album_view')
00262 
00263 tests.append(TestATFolderFunctional)
00264 
00265 class TestATBTreeFolderFunctional(atctftestcase.ATCTIntegrationTestCase):
00266 
00267     portal_type = 'Large Plone Folder'
00268     views = ('folder_listing', 'atct_album_view', )
00269 
00270     def afterSetUp(self):
00271         # enable global allow for BTree Folder
00272         fti = getattr(self.portal.portal_types, self.portal_type)
00273         fti.manage_changeProperties(global_allow=1)
00274         atctftestcase.ATCTIntegrationTestCase.afterSetUp(self)
00275 
00276     def test_templatemixin_view_without_view(self):
00277         # template mixin magic should work
00278         response = self.publish('%s/' % self.obj_path, self.basic_auth)
00279         self.assertStatusEqual(response.getStatus(), 200) #
00280 
00281 tests.append(TestATBTreeFolderFunctional)
00282 
00283 import unittest
00284 def test_suite():
00285     suite = unittest.TestSuite()
00286     for test in tests:
00287         suite.addTest(unittest.makeSuite(test))
00288     return suite