Back to index

plone3  3.1.7
testPloneTestCase.py
Go to the documentation of this file.
00001 #
00002 # Tests the PloneTestCase
00003 #
00004 
00005 import os, sys
00006 if __name__ == '__main__':
00007     execfile(os.path.join(sys.path[0], 'framework.py'))
00008 
00009 from Products.PloneTestCase import PloneTestCase
00010 from AccessControl import getSecurityManager
00011 from Acquisition import aq_base
00012 
00013 PloneTestCase.setupPloneSite()
00014 default_user = PloneTestCase.default_user
00015 
00016 if PloneTestCase.PLONE25:
00017     PREFIX = ''
00018 else:
00019     PREFIX = 'group_'
00020 
00021 def sortTuple(t):
00022     l = list(t)
00023     l.sort()
00024     return tuple(l)
00025 
00026 
00027 class TestPloneTestCase(PloneTestCase.PloneTestCase):
00028 
00029     def afterSetUp(self):
00030         self.membership = self.portal.portal_membership
00031         self.catalog = self.portal.portal_catalog
00032         self.workflow = self.portal.portal_workflow
00033         self.groups = self.portal.portal_groups
00034         self.groups.groupWorkspacesCreationFlag = 0
00035 
00036     def testDefaultMemberarea(self):
00037         self.assertEqual(self.folder.getOwner().getId(), default_user)
00038         self.assertEqual(self.folder.get_local_roles_for_userid(default_user), ('Owner',))
00039         self.failIf('index_html' in self.folder.objectIds())
00040 
00041     def testCreateMemberarea(self):
00042         self.membership.addMember('user2', 'secret', [], [])
00043         self.createMemberarea('user2')
00044         home = self.membership.getHomeFolder('user2')
00045         self.assertEqual(home.getOwner().getId(), 'user2')
00046         self.assertEqual(home.get_local_roles_for_userid('user2'), ('Owner',))
00047         self.assertEqual(home.get_local_roles_for_userid(default_user), ())
00048         self.failIf('index_html' in home.objectIds())
00049 
00050     def testSetRoles(self):
00051         self.setRoles(['Manager'])
00052         acl_user = self.portal.acl_users.getUserById(default_user)
00053         self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Manager'))
00054 
00055     def testSetRolesUser2(self):
00056         self.membership.addMember('user2', 'secret', ['Member'], [])
00057         self.setRoles(['Manager'], 'user2')
00058         acl_user = self.portal.acl_users.getUserById('user2')
00059         self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Manager'))
00060 
00061     def testSetRolesAuthUser(self):
00062         self.setRoles(['Manager'])
00063         auth_user = getSecurityManager().getUser()
00064         self.assertEqual(sortTuple(auth_user.getRoles()), ('Authenticated', 'Manager'))
00065 
00066     if PloneTestCase.PLONE30:
00067 
00068         def testSetGroups(self):
00069             self.groups.addGroup('Editors', [], [])
00070             self.setGroups(['Editors'])
00071             acl_user = self.portal.acl_users.getUserById(default_user)
00072                                                               # Auto group
00073             self.assertEqual(sortTuple(acl_user.getGroups()), ('AuthenticatedUsers', 'Editors'))
00074             self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Member'))
00075 
00076         def testSetGroupsUser2(self):
00077             self.membership.addMember('user2', 'secret', ['Member'], [])
00078             self.groups.addGroup('Editors', [], [])
00079             self.setGroups(['Editors'], 'user2')
00080             acl_user = self.portal.acl_users.getUserById('user2')
00081                                                               # Auto group
00082             self.assertEqual(sortTuple(acl_user.getGroups()), ('AuthenticatedUsers', 'Editors'))
00083             self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Member'))
00084 
00085         def testSetGroupsAuthUser(self):
00086             self.groups.addGroup('Editors', [], [])
00087             self.setGroups(['Editors'])
00088             auth_user = getSecurityManager().getUser()
00089                                                                # Auto group
00090             self.assertEqual(sortTuple(auth_user.getGroups()), ('AuthenticatedUsers', 'Editors'))
00091             self.assertEqual(sortTuple(auth_user.getRoles()), ('Authenticated', 'Member'))
00092 
00093     else:
00094 
00095         def testSetGroups(self):
00096             self.groups.addGroup('Editors', [], [])
00097             self.setGroups(['Editors'])
00098             acl_user = self.portal.acl_users.getUserById(default_user)
00099             self.assertEqual(sortTuple(acl_user.getGroups()), (PREFIX+'Editors',))
00100             self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Member'))
00101 
00102         def testSetGroupsUser2(self):
00103             self.membership.addMember('user2', 'secret', ['Member'], [])
00104             self.groups.addGroup('Editors', [], [])
00105             self.setGroups(['Editors'], 'user2')
00106             acl_user = self.portal.acl_users.getUserById('user2')
00107             self.assertEqual(sortTuple(acl_user.getGroups()), (PREFIX+'Editors',))
00108             self.assertEqual(sortTuple(acl_user.getRoles()), ('Authenticated', 'Member'))
00109 
00110         def testSetGroupsAuthUser(self):
00111             self.groups.addGroup('Editors', [], [])
00112             self.setGroups(['Editors'])
00113             auth_user = getSecurityManager().getUser()
00114             self.assertEqual(sortTuple(auth_user.getGroups()), (PREFIX+'Editors',))
00115             self.assertEqual(sortTuple(auth_user.getRoles()), ('Authenticated', 'Member'))
00116 
00117     def testAddDocument(self):
00118         self.folder.invokeFactory('Document', id='doc')
00119         self.failUnless('doc' in self.folder.objectIds())
00120 
00121     def testEditDocument(self):
00122         self.folder.invokeFactory('Document', id='doc')
00123         self.folder.doc.edit(text_format='plain', text='data')
00124         self.assertEqual(self.folder.doc.EditableBody(), 'data')
00125 
00126     def testPublishDocument(self):
00127         self.folder.invokeFactory('Document', id='doc')
00128         self.setRoles(['Reviewer'])
00129         self.workflow.doActionFor(self.folder.doc, 'publish')
00130         review_state = self.workflow.getInfoFor(self.folder.doc, 'review_state')
00131         self.assertEqual(review_state, 'published')
00132         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00133 
00134     def testSkinScript(self):
00135         self.folder.invokeFactory('Document', id='doc', title='Foo')
00136         self.assertEqual(self.folder.doc.TitleOrId(), 'Foo')
00137 
00138     if PloneTestCase.PLONE30:
00139 
00140         def testGetSite(self):
00141             from zope.app.component.hooks import getSite
00142             self.failUnless(aq_base(getSite()) is aq_base(self.portal))
00143 
00144 
00145 class TestVersionConstants(PloneTestCase.PloneTestCase):
00146 
00147     def testConstants(self):
00148         if PloneTestCase.PLONE25:
00149             self.failUnless(PloneTestCase.PLONE21)
00150         if PloneTestCase.PLONE30:
00151             self.failUnless(PloneTestCase.PLONE25)
00152             self.failUnless(PloneTestCase.PLONE21)
00153         if PloneTestCase.PLONE31:
00154             self.failUnless(PloneTestCase.PLONE30)
00155             self.failUnless(PloneTestCase.PLONE25)
00156             self.failUnless(PloneTestCase.PLONE21)
00157         if PloneTestCase.PLONE40:
00158             self.failUnless(PloneTestCase.PLONE31)
00159             self.failUnless(PloneTestCase.PLONE30)
00160             self.failUnless(PloneTestCase.PLONE25)
00161             self.failUnless(PloneTestCase.PLONE21)
00162 
00163 
00164 def test_suite():
00165     from unittest import TestSuite, makeSuite
00166     suite = TestSuite()
00167     suite.addTest(makeSuite(TestPloneTestCase))
00168     suite.addTest(makeSuite(TestVersionConstants))
00169     return suite
00170 
00171 if __name__ == '__main__':
00172     framework()
00173