Back to index

plone3  3.1.7
test_ContentTypes.py
Go to the documentation of this file.
00001 #
00002 
00003 from Products.PloneTestCase import PloneTestCase
00004 PloneTestCase.setupPloneSite()
00005 
00006 import os
00007 from Products.CMFEditions import PACKAGE_HOME
00008 
00009 class TestPloneContents(PloneTestCase.PloneTestCase):
00010 
00011     def afterSetUp(self):
00012         self.membership = self.portal.portal_membership
00013         self.catalog = self.portal.portal_catalog
00014         self.workflow = self.portal.portal_workflow
00015         self.portal_repository = self.portal.portal_repository
00016         self.portal_archivist = self.portal.portal_archivist
00017 
00018     def getPermissionsOfRole(self, role):
00019         perms = self.portal.permissionsOfRole(role)
00020         return [p['name'] for p in perms if p['selected']]
00021 
00022     def metadata_test_one(self, obj):
00023         self.assertEqual(obj.Title(), 'content')
00024         self.assertEqual(obj.Subject(), ('content',))
00025         self.assertEqual(obj.Description(), 'content')
00026         self.assertEqual(obj.Contributors(), ('content',))
00027         self.assertEqual(obj.Language(), 'content')
00028         self.assertEqual(obj.Rights(), 'content')
00029 
00030     def metadata_test_two(self, obj):
00031         self.assertEqual(obj.Title(), 'contentOK')
00032         self.assertEqual(obj.Subject(), ('contentOK',))
00033         self.assertEqual(obj.Description(), 'contentOK')
00034         self.assertEqual(obj.Contributors(), ('contentOK',))
00035         self.assertEqual(obj.Language(), 'contentOK')
00036         self.assertEqual(obj.Rights(), 'contentOK')
00037 
00038     def testDocument(self):
00039         self.folder.invokeFactory('Document', id='doc')
00040         portal_repository = self.portal_repository
00041         portal_archivist = self.portal_archivist
00042         content = self.folder.doc
00043         content.edit('text/plain','text v1')
00044         content.editMetadata(title='content',
00045                               subject=['content'],
00046                               description='content',
00047                               contributors='content',
00048                               format='text/plain',
00049                               language='content',
00050                               rights='content',
00051                               )
00052         portal_repository.applyVersionControl(content, comment='save no 1')
00053         content.edit('text/plain','text v2')
00054         content.editMetadata(title='contentOK',
00055                               subject=['contentOK'],
00056                               description='contentOK',
00057                               contributors='contentOK',
00058                               format='text/plain',
00059                               language='contentOK',
00060                               rights='contentOK',
00061                               )
00062         portal_repository.save(content, comment='save no 2')
00063         obj = portal_repository.retrieve(content, 0).object
00064         self.assertEqual(obj.EditableBody(), 'text v1')
00065         self.metadata_test_one(obj)
00066         obj = portal_repository.retrieve(content, 1).object
00067         self.assertEqual(obj.EditableBody(), 'text v2')
00068         self.metadata_test_two(obj)
00069         portal_repository.revert(content, 0)
00070         self.assertEqual(content.EditableBody(), 'text v1')
00071         self.metadata_test_one(content)
00072 
00073     def testNewsItem(self):
00074         self.folder.invokeFactory('News Item', id='news_one')
00075         portal_repository = self.portal_repository
00076         portal_archivist = self.portal_archivist
00077         content = self.folder.news_one
00078         content.edit('text v1', text_format='text/plain')
00079         content.editMetadata(title='content',
00080                               subject=['content'],
00081                               description='content',
00082                               contributors='content',
00083                               format='text/plain',
00084                               language='content',
00085                               rights='content',
00086                               )
00087         portal_repository.applyVersionControl(content, comment='save no 1')
00088         content.edit('text v2', text_format='text/plain')
00089         content.editMetadata(title='contentOK',
00090                               subject=['contentOK'],
00091                               description='contentOK',
00092                               contributors='contentOK',
00093                               format='text/plain',
00094                               language='contentOK',
00095                               rights='contentOK',
00096                               )
00097         portal_repository.save(content, comment='save no 2')
00098         obj = portal_repository.retrieve(content, 0).object
00099         self.assertEqual(obj.EditableBody(), 'text v1')
00100         self.metadata_test_one(obj)
00101         obj = portal_repository.retrieve(content, 1).object
00102         self.assertEqual(obj.EditableBody(), 'text v2')
00103         self.metadata_test_two(obj)
00104         portal_repository.revert(content, 0)
00105         self.assertEqual(content.EditableBody(), 'text v1')
00106         self.metadata_test_one(content)
00107 
00108     def testImage(self):
00109         self.folder.invokeFactory('Image', id='image')
00110         portal_repository = self.portal_repository
00111         portal_archivist = self.portal_archivist
00112         img1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
00113         img2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
00114         content = self.folder.image
00115         content.edit(file=img1)
00116         content.editMetadata(title='content',
00117                               subject=['content'],
00118                               description='content',
00119                               contributors='content',
00120                               format='image/png',
00121                               language='content',
00122                               rights='content',
00123                               )
00124         portal_repository.applyVersionControl(content, comment='save no 1')
00125         content.edit(file=img2)
00126         content.editMetadata(title='contentOK',
00127                               subject=['contentOK'],
00128                               description='contentOK',
00129                               contributors='contentOK',
00130                               format='image/png',
00131                               language='contentOK',
00132                               rights='contentOK',
00133                               )
00134         portal_repository.save(content, comment='save no 2')
00135         obj = portal_repository.retrieve(content, 0).object
00136         self.assertEqual(obj.data, img1)
00137         self.metadata_test_one(obj)
00138         obj = portal_repository.retrieve(content, 1).object
00139         self.assertEqual(obj.data, img2)
00140         self.metadata_test_two(obj)
00141         portal_repository.revert(content, 0)
00142         self.assertEqual(content.data, img1)
00143         self.metadata_test_one(content)
00144 
00145     def testFile(self):
00146         self.folder.invokeFactory('Image', id='file')
00147         file1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
00148         file2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
00149         portal_repository = self.portal_repository
00150         portal_archivist = self.portal_archivist
00151         content = self.folder.file
00152         content.edit(file=file1)
00153         content.editMetadata(title='content',
00154                               subject=['content'],
00155                               description='content',
00156                               contributors='content',
00157                               format='image/png',
00158                               language='content',
00159                               rights='content',
00160                               )
00161         portal_repository.applyVersionControl(content, comment='save no 1')
00162         content.edit(file=file2)
00163         content.editMetadata(title='contentOK',
00164                               subject=['contentOK'],
00165                               description='contentOK',
00166                               contributors='contentOK',
00167                               format='image/png',
00168                               language='contentOK',
00169                               rights='contentOK',
00170                               )
00171         portal_repository.save(content, comment='save no 2')
00172         obj = portal_repository.retrieve(content, 0).object
00173         self.assertEqual(obj.data, file1)
00174         self.metadata_test_one(obj)
00175         obj = portal_repository.retrieve(content, 1).object
00176         self.assertEqual(obj.data, file2)
00177         self.metadata_test_two(obj)
00178         portal_repository.revert(content, 0)
00179         self.assertEqual(content.data, file1)
00180         self.metadata_test_one(content)
00181 
00182     def testFolder(self):
00183         self.folder.invokeFactory('Image', id='folder')
00184         portal_repository = self.portal_repository
00185         portal_archivist = self.portal_archivist
00186         content = self.folder.folder
00187         # Use private method because webDAV locking is tripping this up
00188         # using the public method and ATCT
00189         content._editMetadata(title='content',
00190                               subject=['content'],
00191                               description='content',
00192                               contributors='content',
00193                               format='image/png',
00194                               language='content',
00195                               rights='content',
00196                               )
00197         portal_repository.applyVersionControl(content, comment='save no 1')
00198         content._editMetadata(title='contentOK',
00199                               subject=['contentOK'],
00200                               description='contentOK',
00201                               contributors='contentOK',
00202                               format='image/png',
00203                               language='contentOK',
00204                               rights='contentOK',
00205                               )
00206         portal_repository.save(content, comment='save no 2')
00207         obj = portal_repository.retrieve(content, 0).object
00208         self.metadata_test_one(obj)
00209         obj = portal_repository.retrieve(content, 1).object
00210         self.metadata_test_two(obj)
00211         portal_repository.revert(content, 0)
00212         self.metadata_test_one(content)
00213 
00214 
00215 def test_suite():
00216     from unittest import TestSuite, makeSuite
00217     suite = TestSuite()
00218     suite.addTest(makeSuite(TestPloneContents))
00219     return suite