Back to index

plone3  3.1.7
testDocument.py
Go to the documentation of this file.
00001 #
00002 # Tests a CMF Document
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 
00014 
00015 class TestDocument(CMFTestCase.CMFTestCase):
00016 
00017     def afterSetUp(self):
00018         self.membership = self.portal.portal_membership
00019         self.catalog = self.portal.portal_catalog
00020         self.workflow = self.portal.portal_workflow
00021         self.folder.invokeFactory('Document', id='doc')
00022 
00023     def testAddDocument(self):
00024         self.failUnless(hasattr(aq_base(self.folder), 'doc'))
00025         self.failUnless(self.catalog(getId='doc'))
00026 
00027     def testEditDocument(self):
00028         self.folder.doc.edit(text_format='plain', text='data')
00029         self.assertEqual(self.folder.doc.EditableBody(), 'data')
00030 
00031     def testReindexDocument(self):
00032         self.assertEqual(len(self.catalog(getId='doc', Title='Foo')), 0)
00033         self.folder.doc.setTitle('Foo')
00034         self.folder.doc.reindexObject()
00035         self.assertEqual(len(self.catalog(getId='doc', Title='Foo')), 1)
00036 
00037     def testDeleteDocument(self):
00038         self.assertEqual(len(self.catalog(getId='doc')), 1)
00039         self.folder._delObject('doc')
00040         self.assertEqual(len(self.catalog(getId='doc')), 0)
00041 
00042     def testSubmitDocument(self):
00043         self.workflow.doActionFor(self.folder.doc, 'submit')
00044         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'pending')
00045         self.assertEqual(len(self.catalog(getId='doc', review_state='pending')), 1)
00046 
00047     def testRejectDocument(self):
00048         self.workflow.doActionFor(self.folder.doc, 'submit')
00049         self.setRoles(['Reviewer'])
00050         self.workflow.doActionFor(self.folder.doc, 'reject')
00051         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'private')
00052         self.assertEqual(len(self.catalog(getId='doc', review_state='private')), 1)
00053 
00054     def testAcceptDocument(self):
00055         self.workflow.doActionFor(self.folder.doc, 'submit')
00056         self.setRoles(['Reviewer'])
00057         self.workflow.doActionFor(self.folder.doc, 'publish')
00058         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'published')
00059         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00060 
00061     def testPublishDocument(self):
00062         self.setRoles(['Reviewer'])
00063         self.workflow.doActionFor(self.folder.doc, 'publish')
00064         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'published')
00065         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00066 
00067     def testRetractDocument(self):
00068         self.setRoles(['Reviewer'])
00069         self.workflow.doActionFor(self.folder.doc, 'publish')
00070         self.setRoles(['Member'])
00071         self.workflow.doActionFor(self.folder.doc, 'retract')
00072         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'private')
00073         self.assertEqual(len(self.catalog(getId='doc', review_state='private')), 1)
00074 
00075 
00076 def test_suite():
00077     from unittest import TestSuite, makeSuite
00078     suite = TestSuite()
00079     suite.addTest(makeSuite(TestDocument))
00080     return suite
00081 
00082 if __name__ == '__main__':
00083     framework()
00084