Back to index

plone3  3.1.7
testCMFTestCase.py
Go to the documentation of this file.
00001 #
00002 # Tests the CMFTestCase
00003 #
00004 
00005 import os, sys
00006 if __name__ == '__main__':
00007     execfile(os.path.join(sys.path[0], 'framework.py'))
00008 
00009 from Products.CMFTestCase import CMFTestCase
00010 from Acquisition import aq_base
00011 
00012 CMFTestCase.setupCMFSite()
00013 default_user = CMFTestCase.default_user
00014 
00015 
00016 class TestCMFTestCase(CMFTestCase.CMFTestCase):
00017 
00018     def afterSetUp(self):
00019         self.membership = self.portal.portal_membership
00020         self.catalog = self.portal.portal_catalog
00021         self.workflow = self.portal.portal_workflow
00022 
00023     def testDefaultMemberarea(self):
00024         self.assertEqual(self.folder.getOwner().getId(), default_user)
00025         self.assertEqual(self.folder.get_local_roles_for_userid(default_user), ('Owner',))
00026         self.failIf('index_html' in self.folder.objectIds())
00027 
00028     def testCreateMemberarea(self):
00029         self.membership.addMember('user2', 'secret', [], [])
00030         self.createMemberarea('user2')
00031         home = self.membership.getHomeFolder('user2')
00032         self.assertEqual(home.getOwner().getId(), 'user2')
00033         self.assertEqual(home.get_local_roles_for_userid('user2'), ('Owner',))
00034         self.assertEqual(home.get_local_roles_for_userid(default_user), ())
00035         self.failIf('index_html' in home.objectIds())
00036 
00037     def testAddDocument(self):
00038         self.folder.invokeFactory('Document', id='doc')
00039         self.failUnless('doc' in self.folder.objectIds())
00040 
00041     def testEditDocument(self):
00042         self.folder.invokeFactory('Document', id='doc')
00043         self.folder.doc.edit(text_format='plain', text='data')
00044         self.assertEqual(self.folder.doc.EditableBody(), 'data')
00045 
00046     def testPublishDocument(self):
00047         self.folder.invokeFactory('Document', id='doc')
00048         self.setRoles(['Reviewer'])
00049         self.workflow.doActionFor(self.folder.doc, 'publish')
00050         review_state = self.workflow.getInfoFor(self.folder.doc, 'review_state')
00051         self.assertEqual(review_state, 'published')
00052         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00053 
00054     def testSkinScript(self):
00055         self.folder.invokeFactory('Document', id='doc', title='Foo')
00056         self.assertEqual(self.folder.doc.TitleOrId(), 'Foo')
00057 
00058     if CMFTestCase.CMF21:
00059 
00060         def testGetSite(self):
00061             from zope.app.component.hooks import getSite
00062             self.failUnless(aq_base(getSite()) is aq_base(self.portal))
00063 
00064 
00065 class TestVersionConstants(CMFTestCase.CMFTestCase):
00066 
00067     def testConstants(self):
00068         if CMFTestCase.CMF16:
00069             self.failUnless(CMFTestCase.CMF15)
00070         if CMFTestCase.CMF20:
00071             self.failUnless(CMFTestCase.CMF16)
00072             self.failUnless(CMFTestCase.CMF15)
00073         if CMFTestCase.CMF21:
00074             self.failUnless(CMFTestCase.CMF20)
00075             self.failUnless(CMFTestCase.CMF16)
00076             self.failUnless(CMFTestCase.CMF15)
00077 
00078 
00079 def test_suite():
00080     from unittest import TestSuite, makeSuite
00081     suite = TestSuite()
00082     suite.addTest(makeSuite(TestCMFTestCase))
00083     suite.addTest(makeSuite(TestVersionConstants))
00084     return suite
00085 
00086 if __name__ == '__main__':
00087     framework()
00088