Back to index

plone3  3.1.7
test_IntegrationTests.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 """Top level integration tests (without UI)
00023 
00024 $Id: test_IntegrationTests.py,v 1.15 2005/06/24 11:42:01 gregweb Exp $
00025 """
00026 
00027 from Products.PloneTestCase import PloneTestCase
00028 PloneTestCase.setupPloneSite()
00029 
00030 import transaction
00031 
00032 class TestIntegration(PloneTestCase.PloneTestCase):
00033 
00034     def afterSetUp(self):
00035         # we need to have the Manager role to be able to add things
00036         # to the portal root
00037         self.setRoles(['Manager',])
00038 
00039         # add an additional user
00040         self.portal.acl_users.userFolderAddUser('reviewer', 'reviewer',
00041                                                 ['Manager'], '')
00042         # add a document
00043         self.portal.invokeFactory('Document', 'doc')
00044 
00045         # add a folder with two documents in it
00046         self.portal.invokeFactory('Folder', 'fol')
00047         self.portal.fol.invokeFactory('Document', 'doc1')
00048         self.portal.fol.invokeFactory('Document', 'doc2')
00049 
00050     def test01_assertApplyVersionControlSavesOnlyOnce(self):
00051         portal_repo = self.portal.portal_repository
00052         doc = self.portal.doc
00053 
00054         doc.setTitle('doc title v1')
00055         portal_repo.applyVersionControl(doc, comment='First version')
00056 
00057         # there should be only one history entry and not two or more
00058         self.assertEqual(len(portal_repo.getHistory(doc)), 1)
00059 
00060     def test02_storeAndRevertToPreviousVersion(self):
00061         portal_repo = self.portal.portal_repository
00062         doc = self.portal.doc
00063 
00064         doc.setTitle("v1")
00065         portal_repo.applyVersionControl(doc)
00066         doc.setTitle("v2")
00067         portal_repo.save(doc)
00068         doc.setTitle("v3")
00069 
00070         self.assertEqual(doc.Title(), "v3")
00071 
00072         portal_repo.revert(doc)
00073         # just a remark: we don't do "doc = self.portal.doc" to check for
00074         # inplace replacement
00075         self.assertEqual(doc.Title(), "v2")
00076 
00077     def test03_revertToSpecificVersion(self):
00078         portal_repo = self.portal.portal_repository
00079         doc = self.portal.doc
00080 
00081         # store the work edition two times
00082         doc.setTitle("v1")
00083         portal_repo.applyVersionControl(doc)
00084         doc.setTitle("v2")
00085         portal_repo.save(doc)
00086         doc.setTitle("v3")
00087         portal_repo.save(doc)
00088         doc.setTitle("v4")
00089         self.assertEqual(doc.Title(), "v4")
00090 
00091         # revert to the the last but one version
00092         portal_repo.revert(doc, 1)
00093         self.assertEqual(doc.Title(), "v2")
00094 
00095     def test04_storeAndRevertToPreviousVersionAndStoreAgain(self):
00096         portal_repo = self.portal.portal_repository
00097         doc = self.portal.doc
00098 
00099         doc.setTitle("v1")
00100         portal_repo.applyVersionControl(doc)
00101         doc.setTitle("v2")
00102         portal_repo.save(doc)
00103         doc.setTitle("v3")
00104         self.assertEqual(doc.Title(), "v3")
00105 
00106         portal_repo.revert(doc, 0)
00107         doc = self.portal.doc
00108         self.assertEqual(doc.Title(), "v1")
00109         doc.setTitle("v4")
00110         portal_repo.save(doc)
00111         self.assertEqual(doc.Title(), "v4")
00112 
00113     def test05_getHistory(self):
00114         portal_repo = self.portal.portal_repository
00115         doc = self.portal.doc
00116 
00117         # store and publish certain times
00118         portal_repo.applyVersionControl(doc)
00119 
00120         portal_repo.save(doc, metadata="v2\nsecond line")
00121         portal_repo.save(doc)
00122 
00123         history = portal_repo.getHistory(doc)
00124 
00125         # test the number of history entries
00126         self.assertEqual(len(history), 3)
00127 
00128         """XXX we like to test that but implementation isn't there yet
00129         # test some of the log entries"""
00130         h1 = history[1]
00131         self.assertEqual(h1.version_id, 1)
00132         #self.assertEqual(h1.action, h1.ACTION_CHECKIN)
00133         #self.assertEqual(h1.message, 'v2\nsecond line')
00134         #self.failUnless(h1.user_id)
00135         #self.assertEqual(h1.path, '/'.join(doc.getPhysicalPath()))
00136         #self.failUnless(h1.timestamp)
00137         """"""
00138 
00139     def test06_retrieveSpecificVersion(self):
00140         portal_repo = self.portal.portal_repository
00141         doc = self.portal.doc
00142 
00143         review_state = self.portal.portal_workflow.getInfoFor(doc, 'review_state')
00144 
00145         # store the work edition two times
00146         doc.setTitle("v1")
00147         portal_repo.applyVersionControl(doc)
00148         doc.setTitle("v2")
00149         portal_repo.save(doc)
00150         doc.setTitle("v3")
00151         portal_repo.save(doc)
00152         doc.setTitle("v4")
00153         self.assertEqual(doc.Title(), "v4")
00154 
00155         retrieved_doc = portal_repo.retrieve(doc, 1)
00156 
00157         self.assertEqual(retrieved_doc.object.Title(), "v2")
00158         self.assertEqual(doc.Title(), "v4")
00159         self.assertEqual(self.portal.doc.Title(), "v4")
00160 
00161         # since 1.0beta1 the workflows review state is saved to the
00162         # system metadata by a modifier.
00163         self.assertEqual(retrieved_doc.sys_metadata["review_state"], review_state)
00164 
00165     def test07_cloneObjectUnderVersionControlRemovesOriginalsHistory(self):
00166         portal_repo = self.portal.portal_repository
00167         portal_historyidhandler = self.portal.portal_historyidhandler
00168         UniqueIdError = portal_historyidhandler.UniqueIdError
00169         doc = self.portal.doc
00170 
00171         # put the object under version control
00172         portal_repo.applyVersionControl(doc)
00173 
00174         # copy
00175         self.portal.manage_pasteObjects(self.portal.manage_copyObjects(ids=['doc']))
00176         copy = self.portal.copy_of_doc
00177 
00178         # the copy shall not have a history yet: that's correct
00179         self.failIf(portal_repo.getHistory(copy))
00180 
00181         # just to be sure the history is definitivels different
00182         self.failIfEqual(
00183             portal_historyidhandler.queryUid(doc),
00184             portal_historyidhandler.queryUid(copy)) # may be None
00185 
00186     def test08_loopOverHistory(self):
00187         portal_repo = self.portal.portal_repository
00188         portal_historyidhandler = self.portal.portal_historyidhandler
00189         UniqueIdError = portal_historyidhandler.UniqueIdError
00190         doc = self.portal.doc
00191 
00192         # put the object under version control
00193         portal_repo.applyVersionControl(doc)
00194 
00195         counter = 0
00196         for v in portal_repo.getHistory(doc):
00197             counter += 1
00198 
00199         # check if history iterator returned just one element
00200         self.assertEquals(counter, 1)
00201 
00202     def test09_retrieveAndRevertRetainWorkingCopiesWorkflowInfo(self):
00203         portal_repo = self.portal.portal_repository
00204         doc = self.portal.doc
00205 
00206         doc.review_state = "fake rev state v1"
00207         doc.workflow_history = {0: "fake wf history v1"}
00208 
00209         portal_repo.applyVersionControl(doc)
00210 
00211         doc.review_state = "fake rev state v2"
00212         doc.workflow_history = {0: "fake wf history v2"}
00213         portal_repo.save(doc)
00214 
00215         # just check the original is unchanged
00216         self.assertEqual(doc.review_state, "fake rev state v2")
00217         self.assertEqual(doc.workflow_history[0], "fake wf history v2")
00218 
00219         # ----- retrieve
00220         # check if retrieved object carries the working copies workflow info
00221         retrieved_data = portal_repo.retrieve(doc, 0, preserve=['review_state',
00222                                                       'workflow_history'])
00223         self.assertEqual(retrieved_data.object.review_state,
00224                          "fake rev state v2")
00225         self.assertEqual(retrieved_data.object.workflow_history[0],
00226                          "fake wf history v2")
00227 
00228         # check that the working copies workflow info is unchanged
00229         self.assertEqual(doc.review_state, "fake rev state v2")
00230         self.assertEqual(doc.workflow_history[0], "fake wf history v2")
00231 
00232         # check if the preserved data is returned correctly
00233         preserved_rvs = retrieved_data.preserved_data['review_state']
00234         self.assertEqual(preserved_rvs, "fake rev state v1")
00235         preserved_wfh = retrieved_data.preserved_data['workflow_history'][0]
00236         self.assertEqual(preserved_wfh, "fake wf history v1")
00237 
00238         # ----- revert
00239         # check that the working copies workflow info is unchanged after
00240         portal_repo.revert(doc, 0)
00241         self.assertEqual(doc.review_state, "fake rev state v2")
00242         self.assertEqual(doc.workflow_history[0], "fake wf history v2")
00243 
00244     def test10_versionAStandardFolder(self):
00245         portal_repo = self.portal.portal_repository
00246         fol = self.portal.fol
00247         doc1 = fol.doc1
00248         doc2 = fol.doc2
00249 
00250         # save change no 1
00251         fol.setTitle('v1 of fol')
00252         doc1.setTitle("v1 of doc1")
00253         doc2.setTitle("v1 of doc2")
00254 
00255         portal_repo.applyVersionControl(fol, comment='first save')
00256 
00257         # save change no 2
00258         fol.setTitle('v2 of fol')
00259         doc1.setTitle("v2 of doc1")
00260         doc2.setTitle("v2 of doc2")
00261         portal_repo.save(fol, comment='second save')
00262 
00263         # change no 3 (without saving)
00264         fol.setTitle('v3 of fol')
00265         doc1.setTitle("v3 of doc1")
00266         doc2.setTitle("v3 of doc2")
00267 
00268         # revert to change no 2
00269         portal_repo.revert(fol)
00270 
00271         # check if revertion worked correctly
00272         fol = self.portal.fol
00273         doc1 = fol.doc1
00274         doc2 = fol.doc2
00275         self.assertEqual(fol.Title(), "v2 of fol")
00276         self.assertEqual(doc1.Title(), "v3 of doc1")
00277         self.assertEqual(doc2.Title(), "v3 of doc2")
00278 
00279     def test11_versionAFolderishObjectThatTreatsChildrensAsInsideRefs(self):
00280         portal_repo = self.portal.portal_repository
00281         portal_historyidhandler = self.portal.portal_historyidhandler
00282         fol = self.portal.fol
00283         doc1 = fol.doc1
00284         doc2 = fol.doc2
00285 
00286         # just configure the standard folder to treat the childrens as
00287         # inside refrences. For this we reconfigure the standard modifiers.
00288         portal_modifier = self.portal.portal_modifier
00289         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00290                              condition="python: False")
00291         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00292                              condition="python: portal_type=='Folder'")
00293 
00294         # save change no 1
00295         fol.setTitle('v1 of fol')
00296         doc1.setTitle("v1 of doc1")
00297         doc2.setTitle("v1 of doc2")
00298         portal_repo.applyVersionControl(fol, comment='first save')
00299         orig_uid1 = portal_historyidhandler.queryUid(doc1)
00300         orig_uid2 = portal_historyidhandler.queryUid(doc2)
00301 
00302         # save change no 2
00303         fol.setTitle('v2 of fol')
00304         doc1.setTitle("v2 of doc1")
00305         doc2.setTitle("v2 of doc2")
00306         portal_repo.save(fol, comment='second save after we deleted doc2')
00307 
00308         # save change no 3
00309         fol.setTitle('v3 of fol')
00310         doc1.setTitle("v3 of doc1")
00311         fol.manage_delObjects(ids=['doc2'])
00312         fol.invokeFactory('Document', 'doc3')
00313         doc3 = fol.doc3
00314         doc3.setTitle("v1 of doc3")
00315         portal_repo.save(fol, comment='second save with new doc3')
00316 
00317         # revert to change no 1 (version idexes start with index 0)
00318         portal_repo.revert(fol, selector=1)
00319 
00320         # check if revertion worked correctly
00321         fol = self.portal.fol
00322         doc1 = fol.doc1
00323         self.failUnless('doc2' in fol.objectIds())
00324         self.failIf('doc3' in fol.objectIds())
00325         doc2 = fol.doc2
00326         self.assertEqual(fol.Title(), "v2 of fol")
00327         self.assertEqual(doc1.Title(), "v2 of doc1")
00328         self.assertEqual(doc2.Title(), "v2 of doc2")
00329         self.assertEqual(portal_historyidhandler.queryUid(doc1), orig_uid1)
00330         self.assertEqual(portal_historyidhandler.queryUid(doc2), orig_uid2)
00331 
00332 
00333     def test12_retrieveAndRevertRetainWorkingCopiesPermissions(self):
00334         portal_repo = self.portal.portal_repository
00335         doc = self.portal.doc
00336         perm = 'Access contents information'
00337         roles = list(doc.valid_roles())
00338         member_role = 'p0r%s' % roles.index('Member')
00339         manager_role = 'p0r%s' % roles.index('Manager')
00340 
00341         doc.manage_permission(perm, ('Manager',), 0)
00342 
00343         portal_repo.applyVersionControl(doc)
00344 
00345         doc.manage_permission(perm, ('Manager', 'Member'), 1)
00346         portal_repo.save(doc)
00347 
00348         # just check the original is unchanged
00349         settings = doc.permission_settings(perm)[0]
00350         self.failUnless(settings['acquire'])
00351         role_enabled = [r for r in settings['roles']
00352                                         if r['name'] == member_role][0]
00353         self.failUnless(role_enabled['checked'])
00354 
00355         # ----- retrieve
00356         # check if retrieved object carries the working copy's permissions
00357         retrieved_data = portal_repo.retrieve(doc, 0,
00358                         preserve=['_Access_contents_information_Permission'])
00359         settings = retrieved_data.object.permission_settings(perm)[0]
00360         self.failUnless(settings['acquire'])
00361         role_enabled = [r for r in settings['roles']
00362                                         if r['name'] == member_role][0]
00363         self.failUnless(role_enabled['checked'])
00364 
00365         # check that the working copy's permissions are unchanged
00366         settings = doc.permission_settings(perm)[0]
00367         self.failUnless(settings['acquire'])
00368         role_enabled = [r for r in settings['roles']
00369                                         if r['name'] == member_role][0]
00370         self.failUnless(role_enabled['checked'])
00371 
00372         # check if the preserved data is returned correctly
00373         preserved = retrieved_data.preserved_data['_Access_contents_information_Permission']
00374         self.assertEqual(preserved, ('Manager',))
00375 
00376         # ----- revert
00377         # check that the working copies permissions are unchanged after revert
00378         portal_repo.revert(doc, 0)
00379         settings = doc.permission_settings(perm)[0]
00380         self.failUnless(settings['acquire'])
00381         role_enabled = [r for r in settings['roles']
00382                                         if r['name'] == member_role][0]
00383         self.failUnless(role_enabled['checked'])
00384 
00385     def test13_revertUpdatesCatalog(self):
00386         portal_repo = self.portal.portal_repository
00387         cat = self.portal.portal_catalog
00388         doc = self.portal.doc
00389 
00390         doc.edit(text='Plain text')
00391         portal_repo.applyVersionControl(doc)
00392         doc.edit(text='blahblah')
00393         portal_repo.save(doc)
00394         # Test that catalog has current value
00395         results = cat(SearchableText='Plain Text')
00396         self.assertEqual(len(results), 0)
00397         results = cat(SearchableText='blahblah')
00398         self.assertEqual(len(results), 1)
00399         self.assertEqual(results[0].getObject(), doc)
00400 
00401         retrieved_data = portal_repo.retrieve(doc, 0,
00402                         preserve=['_Access_contents_information_Permission'])
00403         retrieved_doc = retrieved_data.object
00404         self.failUnless('Plain text' in retrieved_doc.getText())
00405         # Test that basic retrieval did not alter the catalog
00406         results = cat(SearchableText='Plain Text')
00407         self.assertEqual(len(results), 0)
00408         results = cat(SearchableText='blahblah')
00409         self.assertEqual(len(results), 1)
00410         self.assertEqual(results[0].getObject(), doc)
00411 
00412         portal_repo.revert(doc, 0)
00413         # Test that the catalog is updated on revert
00414         results = cat(SearchableText='blahblah')
00415         self.assertEqual(len(results), 0)
00416         results = cat(SearchableText='Plain Text')
00417         self.assertEqual(len(results), 1)
00418         self.assertEqual(results[0].getObject().getRawText(), 'Plain text')
00419 
00420     def test14_retrieveFolderWithAddedOrDeletedObjects(self):
00421         portal_repo = self.portal.portal_repository
00422         fol = self.portal.fol
00423         doc1 = fol.doc1
00424         doc2 = fol.doc2
00425 
00426         # save change no 1
00427         fol.setTitle('v1 of fol')
00428         doc1.setTitle("v1 of doc1")
00429         doc2.setTitle("v1 of doc2")
00430 
00431         portal_repo.applyVersionControl(fol, comment='first save')
00432 
00433         retrieved_data = portal_repo.retrieve(fol, 0)
00434         ret_folder = retrieved_data.object
00435         self.assertEqual(ret_folder.objectIds(), fol.objectIds())
00436         self.assertEqual(ret_folder.objectValues(), fol.objectValues())
00437 
00438         # remove an item
00439         fol.manage_delObjects('doc2')
00440 
00441         # retrieve should update sub-objects
00442         retrieved_data = portal_repo.retrieve(fol, 0)
00443         ret_folder = retrieved_data.object
00444         self.assertEqual(ret_folder.objectIds(), fol.objectIds())
00445         self.assertEqual(ret_folder.objectValues(), fol.objectValues())
00446 
00447         # add it back
00448         fol.invokeFactory('Document', 'doc2')
00449         doc2 = fol.doc2
00450         doc2.setTitle('v2 of doc2')
00451 
00452         # retrieve should update sub-objects
00453         retrieved_data = portal_repo.retrieve(fol, 0)
00454         ret_folder = retrieved_data.object
00455         self.assertEqual(ret_folder.objectIds(), fol.objectIds())
00456         self.assertEqual(ret_folder.objectValues(), fol.objectValues())
00457         self.assertEqual(ret_folder.doc2.Title(), 'v2 of doc2')
00458 
00459         # add new item
00460         fol.invokeFactory('Document', 'doc3')
00461         doc3 = fol.doc3
00462         doc3.setTitle('v1 of doc3')
00463 
00464         # retrieve should copy new sub-objects
00465         retrieved_data = portal_repo.retrieve(fol, 0)
00466         ret_folder = retrieved_data.object
00467         self.assertEqual(ret_folder.objectIds(), fol.objectIds())
00468         self.assertEqual(ret_folder.objectValues(), fol.objectValues())
00469         self.assertEqual(ret_folder.doc3.Title(), 'v1 of doc3')
00470 
00471         orig_ids = fol.objectIds()
00472         orig_values = fol.objectValues()
00473         # revert to original state, ensure that subobject changes are
00474         # preserved
00475         portal_repo.revert(fol, 0)
00476 
00477         # check if reversion worked correctly
00478         self.assertEqual(fol.objectIds(), orig_ids)
00479         self.assertEqual(fol.objectValues(), orig_values)
00480 
00481         # XXX we should be preserving order as well
00482 
00483     def test15_retrieveInsideRefsFolderWithAddedOrDeletedObjects(self):
00484         portal_repo = self.portal.portal_repository
00485         fol = self.portal.fol
00486         doc1 = fol.doc1
00487         doc2 = fol.doc2
00488 
00489         # just configure the standard folder to treat the childrens as
00490         # inside refrences. For this we reconfigure the standard modifiers.
00491         portal_modifier = self.portal.portal_modifier
00492         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00493                              condition="python: False")
00494         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00495                              condition="python: portal_type=='Folder'")
00496 
00497         # save change no 1
00498         fol.setTitle('v1 of fol')
00499         doc1.setTitle("v1 of doc1")
00500         doc2.setTitle("v1 of doc2")
00501 
00502         orig_ids = fol.objectIds()
00503         orig_values = fol.objectValues()
00504 
00505         portal_repo.applyVersionControl(fol, comment='first save')
00506 
00507         retrieved_data = portal_repo.retrieve(fol, 0)
00508         ret_folder = retrieved_data.object
00509         self.assertEqual(ret_folder.objectIds(), orig_ids)
00510         ret_values = ret_folder.objectValues()
00511         # The values are not identical to the stored values because they are
00512         # retrieved from the repository.
00513         for i in range(len(ret_values)):
00514             self.assertEqual(ret_values[i].getId(), orig_values[i].getId())
00515             self.assertEqual(ret_values[i].Title(), orig_values[i].Title())
00516 
00517         # remove an item
00518         fol.manage_delObjects('doc2')
00519 
00520         cur_ids = fol.objectIds()
00521         self.assertEqual(len(cur_ids), 1)
00522 
00523         # retrieve should retrieve missing sub-objects
00524         retrieved_data = portal_repo.retrieve(fol, 0)
00525         ret_folder = retrieved_data.object
00526         self.assertEqual(ret_folder.objectIds(), orig_ids)
00527         ret_values = ret_folder.objectValues()
00528         for i in range(len(ret_values)):
00529             self.assertEqual(ret_values[i].getId(), orig_values[i].getId())
00530             self.assertEqual(ret_values[i].Title(), orig_values[i].Title())
00531         # We should not have altered the folder itself on retrieve
00532         self.assertEqual(fol.objectIds(), cur_ids)
00533 
00534         # add new item
00535         fol.invokeFactory('Document', 'doc3')
00536         doc3 = fol.doc3
00537         doc3.setTitle('v1 of doc3')
00538 
00539         cur_ids = fol.objectIds()
00540         self.assertEqual(len(cur_ids), 2)
00541 
00542         # retrieve should not add new sub-objects
00543         retrieved_data = portal_repo.retrieve(fol, 0)
00544         ret_folder = retrieved_data.object
00545         self.assertEqual(ret_folder.objectIds(), orig_ids)
00546         ret_values = ret_folder.objectValues()
00547         for i in range(len(ret_values)):
00548             self.assertEqual(ret_values[i].getId(), orig_values[i].getId())
00549             self.assertEqual(ret_values[i].Title(), orig_values[i].Title())
00550         # We should not have altered the folder itself on retrieve
00551         self.assertEqual(fol.objectIds(), cur_ids)
00552 
00553         # revert to original state, ensure that subobject changes are
00554         # reverted
00555         portal_repo.revert(fol, 0)
00556         fol = self.portal.fol
00557 
00558         # check if reversion worked correctly
00559         self.assertEqual(fol.objectIds(), orig_ids)
00560         rev_values = fol.objectValues()
00561         for i in range(len(ret_values)):
00562             self.assertEqual(ret_values[i].getId(), orig_values[i].getId())
00563             self.assertEqual(ret_values[i].Title(), orig_values[i].Title())
00564 
00565     def test16_revertInsideRefsUpdatesCatalog(self):
00566         portal_repo = self.portal.portal_repository
00567         cat = self.portal.portal_catalog
00568         fol = self.portal.fol
00569         doc = fol.doc1
00570 
00571         # just configure the standard folder to treat the childrens as
00572         # inside refrences. For this we reconfigure the standard modifiers.
00573         portal_modifier = self.portal.portal_modifier
00574         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00575                              condition="python: False")
00576         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00577                              condition="python: portal_type=='Folder'")
00578 
00579         # save change no 1
00580         fol.setTitle('v1 of fol')
00581         doc.setTitle("v1 of doc1")
00582         fol.reindexObject()
00583         doc.reindexObject()
00584         portal_repo.applyVersionControl(fol, comment='first save')
00585 
00586         # save change no 2
00587         fol.setTitle('v2 of fol')
00588         doc.setTitle("v2 of doc1")
00589         fol.reindexObject()
00590         doc.reindexObject()
00591         portal_repo.save(fol, comment='second save')
00592 
00593         # Test that catalog has current value
00594         results = cat(SearchableText='v1')
00595         self.assertEqual(len(results), 0)
00596         results = cat(SearchableText='v2', portal_type='Document')
00597         self.assertEqual(len(results), 1)
00598         self.assertEqual(results[0].getObject(), doc)
00599 
00600         retrieved_data = portal_repo.retrieve(fol, 0,
00601                         preserve=['_Access_contents_information_Permission'])
00602         retrieved_doc = retrieved_data.object.doc1
00603         self.assertEqual(retrieved_doc.Title(), 'v1 of doc1')
00604         # Test that basic retrieval did not alter the catalog
00605         results = cat(SearchableText='v1', )
00606         self.assertEqual(len(results), 0)
00607         results = cat(SearchableText='v2',  portal_type='Document')
00608         self.assertEqual(len(results), 1)
00609         self.assertEqual(results[0].getObject(), doc)
00610 
00611         portal_repo.revert(fol, 0)
00612         reverted_doc = self.portal.fol.doc1
00613         self.assertEqual(reverted_doc.Title(), 'v1 of doc1')
00614         # Test that the catalog is updated on revert
00615         results = cat(SearchableText='v2')
00616         self.assertEqual(len(results), 0)
00617         results = cat(SearchableText='v1', portal_type='Document')
00618         self.assertEqual(len(results), 1)
00619         self.assertEqual(results[0].getObject().Title(), 'v1 of doc1')
00620 
00621     def test17_moveInsideRefThenRevertChangesUid(self):
00622         # When an object is contained in an 'Inside references folder' and has been moved
00623         # into another location, it should maintain its CMF Uid, if the folder is then
00624         # reverted to a state where it contained the object (which now exists with the same
00625         # uid in a different location), the uid of the reverted object should be changed.
00626         portal_repo = self.portal.portal_repository
00627         portal_historyidhandler = self.portal.portal_historyidhandler
00628         fol = self.portal.fol
00629         doc1 = fol.doc1
00630 
00631         # just configure the standard folder to treat the childrens as
00632         # inside refrences. For this we reconfigure the standard modifiers.
00633         portal_modifier = self.portal.portal_modifier
00634         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00635                              condition="python: False")
00636         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00637                              condition="python: portal_type=='Folder'")
00638 
00639         # save change no 1
00640         fol.setTitle('v1 of fol')
00641         doc1.setTitle("v1 of doc1")
00642 
00643         portal_repo.applyVersionControl(fol, comment='first save')
00644         orig_uid = portal_historyidhandler.queryUid(doc1)
00645 
00646         transaction.savepoint(optimistic=True)
00647         self.portal.manage_pasteObjects(fol.manage_cutObjects(ids=['doc1']))
00648         moved_doc = self.portal.doc1
00649         self.assertEqual(portal_historyidhandler.queryUid(moved_doc), orig_uid)
00650         transaction.savepoint(optimistic=True)
00651 
00652         # retrieve should change the uid if it already exists
00653         retrieved_data = portal_repo.retrieve(fol, 0)
00654         ret_folder = retrieved_data.object
00655         ret_doc = ret_folder.doc1
00656         self.failIf(portal_historyidhandler.queryUid(ret_doc) == orig_uid,
00657                          "UIDs should not be equal, current value: %s"%orig_uid)
00658 
00659         # revert to original state, ensure that subobject changes are
00660         # reverted and that uid is changed
00661         portal_repo.revert(fol, 0)
00662         fol = self.portal.fol
00663         reverted_doc = fol.doc1
00664 
00665         # check if reversion worked correctly
00666         self.failIf(portal_historyidhandler.queryUid(reverted_doc) == orig_uid,
00667                          "UIDs should not be equal, current value: %s"%orig_uid)
00668 
00669     def test18_retrieveObjectWhichHasBeenReplaced(self):
00670         portal_repo = self.portal.portal_repository
00671         fol = self.portal.fol
00672         doc1 = fol.doc1
00673         doc2 = fol.doc2
00674 
00675         # save change no 1
00676         fol.setTitle('v1 of fol')
00677         doc1.setTitle("v1 of doc1")
00678         doc2.setTitle("v1 of doc2")
00679 
00680         portal_repo.applyVersionControl(doc1, comment='first save')
00681         portal_repo.applyVersionControl(doc2, comment='first save')
00682 
00683         transaction.savepoint(optimistic=True)
00684         fol.manage_renameObjects(['doc1','doc2'],['doc1_renamed', 'doc1'])
00685 
00686         doc1 = fol.doc1_renamed
00687         doc2 = fol.doc1
00688 
00689         doc1.setTitle('v2 of doc1_renamed')
00690         doc2.setTitle('v2 of doc1 (was doc2)')
00691 
00692         portal_repo.save(doc1, comment='second save')
00693         portal_repo.save(doc2, comment='second save')
00694 
00695         retrieved_data = portal_repo.retrieve(doc1, 0)
00696         ret_doc = retrieved_data.object
00697         self.assertEqual(ret_doc.getId(), 'doc1')
00698         self.assertEqual(ret_doc.Title(), 'v1 of doc1')
00699 
00700         portal_repo.revert(doc1, 0)
00701         rev_doc = fol.doc1_renamed
00702         self.assertEqual(rev_doc.getId(), 'doc1_renamed')
00703         self.assertEqual(rev_doc.Title(), 'v1 of doc1')
00704 
00705     def disabled_test19_retrieveDeletedObjectWhichHasBeenReplacedInAnInsideRefsFolder(self):
00706         # disabled by gregweb/21-10-2006
00707         # reason: Needs concentrated and deeper look. 
00708         # --> Ideas exist, pleas contact us on the list if you like to work on that.
00709         # I know one should not do that! But solving this would bring more risks
00710         # into the 1.0final than leaving the bug to be solved afterwards.
00711         portal_repo = self.portal.portal_repository
00712         fol = self.portal.fol
00713         doc1 = fol.doc1
00714         doc2 = fol.doc2
00715 
00716         portal_modifier = self.portal.portal_modifier
00717         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00718                              condition="python: False")
00719         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00720                              condition="python: portal_type=='Folder'")
00721 
00722         # save change no 1
00723         fol.setTitle('v1 of fol')
00724         doc1.setTitle("v1 of doc1")
00725         doc2.setTitle("v1 of doc2")
00726 
00727         portal_repo.applyVersionControl(fol, comment='first save')
00728 
00729         fol.manage_delObjects(['doc1'])
00730         transaction.savepoint(optimistic=True)
00731         fol.manage_renameObjects(['doc2'],['doc1'])
00732 
00733         doc2 = fol.doc1
00734 
00735         doc1.setTitle('v2 of doc1_renamed')
00736         doc2.setTitle('v2 of doc1 (was doc2)')
00737 
00738         portal_repo.save(fol, comment='second save')
00739 
00740         retrieved_data = portal_repo.retrieve(fol, 0)
00741         ret_fol = retrieved_data.object
00742         self.assertEqual(ret_fol.objectIds(), ['doc1', 'doc2'])
00743         ret_doc1 = ret_fol.doc1
00744         ret_doc2 = ret_fol.doc2
00745         self.assertEqual(ret_doc1.getId(), 'doc1')
00746         self.assertEqual(ret_doc1.Title(), 'v1 of doc1')
00747         self.assertEqual(ret_doc2.getId(), 'doc2')
00748         self.assertEqual(ret_doc2.Title(), 'v1 of doc2')
00749 
00750         portal_repo.revert(fol, 0)
00751         rev_fol = self.portal.fol
00752         self.assertEqual(rev_fol.objectIds(), ['doc1', 'doc2'])
00753         rev_doc1 = rev_fol.doc1
00754         rev_doc2 = rev_fol.doc2
00755         self.assertEqual(rev_doc1.getId(), 'doc1')
00756         self.assertEqual(rev_doc1.Title(), 'v1 of doc1')
00757         self.assertEqual(rev_doc2.getId(), 'doc2')
00758         self.assertEqual(rev_doc2.Title(), 'v1 of doc2')
00759 
00760     def disabled_test20_retrieveMovedObjectWhichHasBeenReplacedInAnInsideRefsFolder(self):
00761         # disabled by gregweb/21-10-2006
00762         # reason: Needs concentrated and deeper look. 
00763         # --> Ideas exist, pleas contact us on the list if you like to work on that.
00764         # I know one should not do that! But solving this would bring more risks
00765         # into the 1.0final than leaving the bug to be solved afterwards.
00766         portal_repo = self.portal.portal_repository
00767         fol = self.portal.fol
00768         doc1 = fol.doc1
00769         doc2 = fol.doc2
00770 
00771         portal_modifier = self.portal.portal_modifier
00772         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00773                              condition="python: False")
00774         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00775                              condition="python: portal_type=='Folder'")
00776 
00777         # save change no 1
00778         fol.setTitle('v1 of fol')
00779         doc1.setTitle("v1 of doc1")
00780         doc2.setTitle("v1 of doc2")
00781 
00782         portal_repo.applyVersionControl(fol, comment='first save')
00783 
00784         transaction.savepoint(optimistic=True)
00785         self.portal.manage_pasteObjects(fol.manage_cutObjects(['doc1']))
00786         fol.manage_renameObjects(['doc2'],['doc1'])
00787 
00788         doc2 = fol.doc1
00789         doc1 = self.portal.doc1
00790 
00791         doc1.setTitle('v2 of doc1 (now in portal root)')
00792         doc2.setTitle('v2 of doc1 (was doc2)')
00793 
00794         portal_repo.save(fol, comment='second save')
00795 
00796         retrieved_data = portal_repo.retrieve(fol, 0)
00797         ret_fol = retrieved_data.object
00798         self.assertEqual(ret_fol.objectIds(), ['doc1', 'doc2'])
00799         ret_doc1 = ret_fol.doc1
00800         ret_doc2 = ret_fol.doc2
00801         self.assertEqual(ret_doc1.getId(), 'doc1')
00802         self.assertEqual(ret_doc1.Title(), 'v1 of doc1')
00803         self.assertEqual(ret_doc2.getId(), 'doc2')
00804         self.assertEqual(ret_doc2.Title(), 'v1 of doc2')
00805 
00806         retrieved_data = portal_repo.revert(fol, 0)
00807         rev_fol = self.portal.fol
00808         self.assertEqual(rev_fol.objectIds(), ['doc1', 'doc2'])
00809         rev_doc1 = rev_fol.doc1
00810         rev_doc2 = rev_fol.doc2
00811         self.assertEqual(rev_doc1.getId(), 'doc1')
00812         self.assertEqual(rev_doc1.Title(), 'v1 of doc1')
00813         self.assertEqual(rev_doc2.getId(), 'doc2')
00814         self.assertEqual(rev_doc2.Title(), 'v1 of doc2')
00815 
00816     def test21_DontLeaveDanglingCatalogEntriesWhenInvokingFactory(self):
00817         portal_repo = self.portal.portal_repository
00818         catalog = self.portal.portal_catalog
00819         fol = self.portal.fol
00820         doc1 = fol.doc1
00821         doc2 = fol.doc2
00822 
00823         portal_modifier = self.portal.portal_modifier
00824         portal_modifier.edit("OMOutsideChildrensModifier", enabled=False,
00825                              condition="python: False")
00826         portal_modifier.edit("OMInsideChildrensModifier", enabled=True,
00827                              condition="python: portal_type=='Folder'")
00828 
00829         # save change no 1
00830         fol.setTitle('v1 of fol')
00831         doc1.setTitle("v1 of doc1")
00832         doc2.setTitle("v1 of doc2")
00833 
00834         portal_repo.applyVersionControl(fol, comment='first save')
00835 
00836         self.assertEqual(len(catalog(getId='doc1')), 1)
00837 
00838         fol.manage_delObjects(['doc2', 'doc1'])
00839 
00840         self.assertEqual(len(catalog(getId='doc1')), 0)
00841 
00842         portal_repo.save(fol, comment='second save')
00843 
00844 
00845         retrieved_data = portal_repo.retrieve(fol, 0)
00846         ret_fol = retrieved_data.object
00847         self.assertEqual(ret_fol.objectIds(), ['doc1', 'doc2'])
00848         self.assertEqual(len(catalog(getId='doc1')), 0)
00849 
00850         portal_repo.revert(fol, 0)
00851         rev_fol = self.portal.fol
00852         self.assertEqual(rev_fol.objectIds(), ['doc1', 'doc2'])
00853         self.assertEqual(len(catalog(getId='doc1')), 1)
00854 
00855     def test21_RevertObjectWithChangedIdMaintainsConsistentCatalog(self):
00856         portal_repo = self.portal.portal_repository
00857         catalog = self.portal.portal_catalog
00858         fol = self.portal.fol
00859         doc1 = fol.doc1
00860 
00861         # save change no 1
00862         doc1.setTitle("v1 of doc1")
00863 
00864         portal_repo.applyVersionControl(doc1, comment='first save')
00865 
00866         self.assertEqual(len(catalog(getId='doc1')), 1)
00867 
00868         doc1.setTitle("v2 of doc1")
00869         transaction.savepoint()
00870         fol.manage_renameObject('doc1', 'doc1_changed')
00871         doc1 = fol.doc1_changed
00872         doc1.reindexObject()
00873 
00874         self.assertEqual(len(catalog(getId='doc1')), 0)
00875         self.assertEqual(len(catalog(getId='doc1_changed')), 1)
00876 
00877         portal_repo.save(doc1, comment='second save')
00878 
00879         portal_repo.revert(doc1, 0)
00880         rev_doc = fol.doc1_changed
00881         self.assertEqual(rev_doc.Title(), "v1 of doc1")
00882         self.assertEqual(len(catalog(getId='doc1')), 0)
00883         self.assertEqual(len(catalog(getId='doc1_changed')), 1)
00884         self.assertEqual(len(catalog(Title='v1 of doc1')), 1)
00885 
00886     def test21_RestoreMovedObject(self):
00887         portal_repo = self.portal.portal_repository
00888         catalog = self.portal.portal_catalog
00889         portal_hidhandler = self.portal.portal_historyidhandler
00890         fol = self.portal.fol
00891         doc1 = fol.doc1
00892 
00893         # save change no 1
00894         doc1.setTitle("v1 of doc1")
00895 
00896         portal_repo.applyVersionControl(doc1, comment='first save')
00897         # save the ``history_id`` to be able to retrieve the object after
00898         # it's deletion
00899         history_id = portal_hidhandler.queryUid(doc1)
00900 
00901         doc1.setTitle("v2 of doc1")
00902         transaction.savepoint()
00903         fol.manage_renameObject('doc1', 'doc1_changed')
00904         doc1 = fol.doc1_changed
00905         doc1.reindexObject()
00906 
00907         self.assertEqual(len(catalog(getId='doc1')), 0)
00908         self.assertEqual(len(catalog(getId='doc1_changed')), 1)
00909 
00910         portal_repo.save(doc1, comment='second save')
00911         portal_repo.restore(history_id, selector=0, container=fol)
00912         # Both documents should now be in place
00913         res_doc = fol.doc1
00914         self.assertEqual(res_doc.Title(), "v1 of doc1")
00915         self.assertEqual(len(catalog(getId='doc1')), 1)
00916         self.assertEqual(len(catalog(getId='doc1_changed')), 1)
00917         self.assertEqual(len(catalog(Title='v1 of doc1')), 1)
00918         self.assertEqual(len(catalog(Title='v2 of doc1')), 1)
00919         # The reverted document should have a new uid, because an object with
00920         # the original uid exists
00921         self.failIf(portal_hidhandler.queryUid(res_doc) == history_id)
00922 
00923 from unittest import TestSuite, makeSuite
00924 def test_suite():
00925     suite = TestSuite()
00926     suite.addTest(makeSuite(TestIntegration))
00927     return suite