Back to index

plone3  3.1.7
test_ATContentTypes.py
Go to the documentation of this file.
00001 #########################################################################
00002 # Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber,
00003 # Reflab (Vincenzo Di Somma, Francesco Ciriaci, Riccardo Lemmi)
00004 # All Rights Reserved.
00005 #
00006 # This file is part of CMFEditions.
00007 #
00008 # CMFEditions is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # CMFEditions is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with CMFEditions; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021 #########################################################################
00022 """Test the ATContentTypes content
00023 """
00024 
00025 from Products.PloneTestCase import PloneTestCase
00026 PloneTestCase.setupPloneSite()
00027 
00028 import os
00029 from Products.CMFEditions import PACKAGE_HOME
00030 
00031 class TestATContents(PloneTestCase.PloneTestCase):
00032 
00033     def afterSetUp(self):
00034         self.membership = self.portal.portal_membership
00035         self.catalog = self.portal.portal_catalog
00036         self.workflow = self.portal.portal_workflow
00037         self.portal_repository = self.portal.portal_repository
00038 
00039     def set_metadata(self, obj, text):
00040         obj.setTitle(text)
00041         obj.setSubject(text)
00042         obj.setDescription(text)
00043         obj.setContributors(text)
00044         obj.setLanguage(text)
00045         obj.setRights(text)
00046 
00047     def metadata_test(self, obj, text):
00048         self.assertEqual(obj.Title(), text)
00049         self.assertEqual(obj.Subject(), (text,))
00050         self.assertEqual(obj.Description(), text)
00051         self.assertEqual(obj.Contributors(), (text,))
00052         self.assertEqual(obj.Language(), text)
00053         self.assertEqual(obj.Rights(), text)
00054 
00055     def getPermissionsOfRole(self, role):
00056         perms = self.portal.permissionsOfRole(role)
00057         return [p['name'] for p in perms if p['selected']]
00058 
00059     def testATDocument(self):
00060         self.folder.invokeFactory('Document', id='doc')
00061         portal_repository = self.portal_repository
00062         content = self.folder.doc
00063         content.setText('text v1')
00064         self.set_metadata(content, 'content')
00065         portal_repository.applyVersionControl(content, comment='save no 1')
00066         content.setText('text v2')
00067         self.set_metadata(content, 'contentOK')
00068         portal_repository.save(content, comment='save no 2')
00069         vdata = portal_repository.retrieve(content, 0)
00070         obj = vdata.object
00071         self.assertEqual(obj.getRawText(), 'text v1')
00072         self.metadata_test(obj, 'content')
00073         vdata = portal_repository.retrieve(content, 1)
00074         obj = vdata.object
00075         self.assertEqual(obj.getRawText(), 'text v2')
00076         self.metadata_test(obj, 'contentOK')
00077         portal_repository.revert(content, 0)
00078         self.assertEqual(content.getRawText(), 'text v1')
00079         self.metadata_test(content, 'content')
00080 
00081     def testNewsItem(self):
00082         self.folder.invokeFactory('News Item', id='news_one')
00083         portal_repository = self.portal_repository
00084         content = self.folder.news_one
00085         content.text = 'text v1'
00086         portal_repository.applyVersionControl(content, comment='save no 1')
00087         content.text = 'text v2'
00088         portal_repository.save(content, comment='save no 2')
00089         vdata = portal_repository.retrieve(content, 0)
00090         obj = vdata.object
00091         self.assertEqual(obj.text, 'text v1')
00092         vdata = portal_repository.retrieve(content, 1)
00093         obj = vdata.object
00094         self.assertEqual(obj.text, 'text v2')
00095         portal_repository.revert(content, 0)
00096         self.assertEqual(content.text, 'text v1')
00097 
00098     def testImage(self):
00099         self.folder.invokeFactory('Image', id='image')
00100         img1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
00101         img2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
00102         portal_repository = self.portal_repository
00103         content = self.folder.image
00104         content.edit(file=img1)
00105         portal_repository.applyVersionControl(content, comment='save no 1')
00106         content.edit(file=img2)
00107         portal_repository.save(content, comment='save no 2')
00108         vdata = portal_repository.retrieve(content, 0)
00109         obj = vdata.object
00110         self.assertEqual(obj.data, img1)
00111         vdata = portal_repository.retrieve(content, 1)
00112         obj = vdata.object
00113         self.assertEqual(obj.data, img2)
00114         portal_repository.revert(content, 0)
00115         self.assertEqual(content.data, img1)
00116 
00117     def testFile(self):
00118         self.folder.invokeFactory('File', id='file')
00119         file1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
00120         file2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
00121         portal_repository = self.portal_repository
00122         content = self.folder.file
00123         content.edit(file=file1)
00124         portal_repository.applyVersionControl(content, comment='save no 1')
00125         content.edit(file=file2)
00126         portal_repository.save(content, comment='save no 2')
00127         vdata = portal_repository.retrieve(content, 0)
00128         obj = vdata.object
00129         self.assertEqual(obj.data, file1)
00130         vdata = portal_repository.retrieve(content, 1)
00131         obj = vdata.object
00132         self.assertEqual(obj.data, file2)
00133         portal_repository.revert(content, 0)
00134         self.assertEqual(content.data, file1)
00135 
00136     def testFolder(self):
00137         titleOne = 'folderOne'
00138         titleTwo = 'folderTwo'
00139         self.folder.invokeFactory('Folder', id='myfolder')
00140         portal_repository = self.portal_repository
00141         content = self.folder.myfolder
00142         content.setTitle(titleOne)
00143         portal_repository.applyVersionControl(content, comment='save no 0')
00144         content.setTitle(titleTwo)
00145         portal_repository.save(content, comment='save no 1')
00146         vdata = portal_repository.retrieve(content, 0)
00147         obj = vdata.object
00148         self.assertEqual(obj.Title(), titleOne)
00149         vdata = portal_repository.retrieve(content, 1)
00150         obj = vdata.object
00151         self.assertEqual(obj.Title(), titleTwo)
00152         portal_repository.revert(content, 0)
00153         self.assertEqual(content.Title(), titleOne)
00154 
00155 
00156 def test_suite():
00157     from unittest import TestSuite, makeSuite
00158     suite = TestSuite()
00159     suite.addTest(makeSuite(TestATContents))
00160     return suite
00161