Back to index

plone3  3.1.7
testDocument.py
Go to the documentation of this file.
00001 #
00002 # Tests a Plone 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.PloneTestCase import PloneTestCase
00010 from Acquisition import aq_base
00011 
00012 PloneTestCase.setupPloneSite()
00013 
00014 
00015 class TestDocument(PloneTestCase.PloneTestCase):
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 testAcceptDocument(self):
00048         self.workflow.doActionFor(self.folder.doc, 'submit')
00049         self.setRoles(['Reviewer'])
00050         self.workflow.doActionFor(self.folder.doc, 'publish')
00051         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'published')
00052         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00053 
00054     def testPublishDocument(self):
00055         self.setRoles(['Reviewer'])
00056         self.workflow.doActionFor(self.folder.doc, 'publish')
00057         self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'published')
00058         self.assertEqual(len(self.catalog(getId='doc', review_state='published')), 1)
00059 
00060     if PloneTestCase.PLONE30:
00061 
00062         def testRejectDocument(self):
00063             self.workflow.doActionFor(self.folder.doc, 'submit')
00064             self.setRoles(['Reviewer'])
00065             self.workflow.doActionFor(self.folder.doc, 'reject')
00066             self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'private')
00067             self.assertEqual(len(self.catalog(getId='doc', review_state='private')), 1)
00068 
00069         def testRetractDocument(self):
00070             self.setRoles(['Reviewer'])
00071             self.workflow.doActionFor(self.folder.doc, 'publish')
00072             self.setRoles(['Member'])
00073             self.workflow.doActionFor(self.folder.doc, 'retract')
00074             self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'private')
00075             self.assertEqual(len(self.catalog(getId='doc', review_state='private')), 1)
00076 
00077     else:
00078 
00079         def testRejectDocument(self):
00080             self.workflow.doActionFor(self.folder.doc, 'submit')
00081             self.setRoles(['Reviewer'])
00082             self.workflow.doActionFor(self.folder.doc, 'reject')
00083             self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'visible')
00084             self.assertEqual(len(self.catalog(getId='doc', review_state='visible')), 1)
00085 
00086         def testRetractDocument(self):
00087             self.setRoles(['Reviewer'])
00088             self.workflow.doActionFor(self.folder.doc, 'publish')
00089             self.setRoles(['Member'])
00090             self.workflow.doActionFor(self.folder.doc, 'retract')
00091             self.assertEqual(self.workflow.getInfoFor(self.folder.doc, 'review_state'), 'visible')
00092             self.assertEqual(len(self.catalog(getId='doc', review_state='visible')), 1)
00093 
00094 
00095 def test_suite():
00096     from unittest import TestSuite, makeSuite
00097     suite = TestSuite()
00098     suite.addTest(makeSuite(TestDocument))
00099     return suite
00100 
00101 if __name__ == '__main__':
00102     framework()
00103