Back to index

plone3  3.1.7
testReferenceVersioning.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 # 
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 # 
00012 ##############################################################################
00013 """Tests of combining ZopeVersionControl with the References product.
00014 
00015 $Id: testReferenceVersioning.py 72373 2007-02-05 16:18:41Z tseaver $
00016 """
00017 import unittest
00018 
00019 from common import common_setUp
00020 from common import common_tearDown
00021 
00022 has_refs = 1
00023 try:
00024     from Products.References.PathReference import PathReference
00025 except ImportError:
00026     has_refs = 0
00027 
00028 class ReferenceVCTests(unittest.TestCase):
00029 
00030     setUp = common_setUp
00031     tearDown = common_tearDown
00032 
00033     def testContainerVersioning(self):
00034         # Verify that containers and items are versioned independently,
00035         # except in the case of references.
00036         from OFS.DTMLDocument import addDTMLDocument
00037 
00038         repository = self.repository
00039         folder1 = self.app.folder1
00040         folder2 = folder1.folder2
00041         folder1.testattr = 'container_v1'
00042         folder2.testattr = 'item_v1'
00043         folder1._setOb("ref", PathReference("ref", folder1.folder2))
00044         folder2._true_id = "folder2"
00045         self.assertEqual(folder1.ref._true_id, "folder2")
00046 
00047         self.assert_(not repository.isUnderVersionControl(folder1))
00048         repository.applyVersionControl(folder1)
00049         folder1 = self.app.folder1
00050         self.assert_(repository.isUnderVersionControl(folder1))
00051         self.assert_(not repository.isUnderVersionControl(folder2))
00052         self.assert_(not repository.isUnderVersionControl(folder1.ref))
00053         repository.applyVersionControl(folder2)
00054         folder2 = folder1.folder2
00055         self.assert_(repository.isUnderVersionControl(folder2))
00056         self.assert_(not repository.isUnderVersionControl(folder2.document1))
00057 
00058         # Make the first version of folder1 and check it in.
00059         repository.checkoutResource(folder1)
00060         folder1 = self.app.folder1
00061         repository.checkinResource(folder1)
00062         folder1 = self.app.folder1
00063         folder2 = folder1.folder2
00064         info = repository.getVersionInfo(folder1)
00065         first_version = info.version_id
00066 
00067         # Change folder1 and check it in again
00068         repository.checkoutResource(folder1)
00069         folder1 = self.app.folder1
00070         folder1.testattr = 'container_v2'
00071         addDTMLDocument(folder1, 'document3', file='some more text')
00072         folder1.document3._true_id = "document3"
00073         repository.checkinResource(folder1)
00074         folder1 = self.app.folder1
00075         folder2 = folder1.folder2
00076 
00077         # Change ref to point to document3.
00078         folder1._delObject("ref")
00079         folder1._setOb("ref", PathReference("ref", folder1.document3))
00080         self.assertEqual(folder1.ref._true_id, "document3")
00081 
00082         # Change folder2
00083         repository.checkoutResource(folder2)
00084         folder2 = folder1.folder2
00085         folder2.testattr = 'item_v2'
00086 
00087         # Now revert folder1 and verify that folder2 was not reverted.
00088         # Also verify that ref now points back to folder2.
00089         repository.updateResource(folder1, first_version)
00090         folder1 = self.app.folder1
00091         folder2 = folder1.folder2
00092         self.assertEqual(folder1.testattr, 'container_v1')
00093         self.assertEqual(folder2.testattr, 'item_v2')
00094         self.assertEqual(folder1.ref._true_id, "folder2")
00095 
00096         # Verify that document3 remains an item of the reverted folder1.
00097         self.assert_(hasattr(folder1, 'document3'))
00098         self.assert_(str(folder1.document3) == 'some more text')
00099 
00100         # Remove document3 and verify that it doesn't reappear upon revert.
00101         folder1._delObject('document3')
00102         repository.updateResource(folder1, '')
00103         folder1 = self.app.folder1
00104         self.assertEqual(folder1.testattr, 'container_v2')
00105         self.assertEqual(folder1.folder2.testattr, 'item_v2')
00106         self.assert_(not hasattr(folder1, 'document3'))
00107 
00108 
00109 def test_suite():
00110     suite = unittest.TestSuite()
00111     if has_refs:
00112         suite.addTest(unittest.makeSuite(ReferenceVCTests))
00113     return suite
00114 
00115 if __name__ == "__main__":
00116     unittest.main(defaultTest='test_suite')
00117