Back to index

plone3  3.1.7
testVersionControl.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 """ Test the ZVC machinery
00014 
00015 $Id: testVersionControl.py 72373 2007-02-05 16:18:41Z tseaver $
00016 """
00017 import unittest
00018 
00019 from common import get_transaction
00020 from common import common_setUp
00021 from common import common_tearDown
00022 from common import common_commit
00023 
00024 class VersionControlTests(unittest.TestCase):
00025  
00026     setUp = common_setUp
00027     tearDown = common_tearDown
00028     commit = common_commit
00029 
00030     do_commits = 0
00031 
00032     def testIsVersionableResource(self):
00033         # Test checking whether an object is a versionable resource.
00034         repository = self.repository
00035         document = self.document1
00036         nonversionable = self.document_nonversion
00037         self.failUnless(repository.isAVersionableResource(document))
00038         self.failIf(repository.isAVersionableResource(nonversionable))
00039         self.failIf(repository.isAVersionableResource('foobar'))
00040         self.failIf(repository.isAVersionableResource(self))
00041 
00042 
00043     def testIsUnderVersionControl(self):
00044         # Test checking whether an object is under version control.
00045         repository = self.repository
00046         document = self.document1
00047         self.failIf(repository.isUnderVersionControl(document))
00048         repository.applyVersionControl(document)
00049         self.commit()
00050         self.failUnless(repository.isUnderVersionControl(document))
00051 
00052 
00053     def testIsResourceUpToDate(self):
00054         # Test checking whether a versioned resource is up to date.
00055         repository = self.repository
00056         document = repository.applyVersionControl(self.document1)
00057         self.commit()
00058         self.failUnless(repository.isResourceUpToDate(document))
00059 
00060         info = repository.getVersionInfo(document)
00061         first_version = info.version_id
00062 
00063         document = repository.checkoutResource(document)
00064         self.commit()
00065         document = repository.checkinResource(document, '')
00066         self.commit()
00067 
00068         document = repository.updateResource(document, first_version)
00069         self.commit()
00070         self.failIf(repository.isResourceUpToDate(document))
00071 
00072         document = repository.updateResource(document, None)
00073         self.commit()
00074         self.failUnless(repository.isResourceUpToDate(document))
00075 
00076 
00077     def testIsResourceChanged(self):
00078         # Test checking whether a versioned resource has changed.
00079         repository = self.repository
00080         document = repository.applyVersionControl(self.document1)
00081         self.commit()
00082         if self.do_commits:
00083             self.failIf(repository.isResourceChanged(document))
00084 
00085         document = repository.checkoutResource(document)
00086         self.commit()
00087         if self.do_commits:
00088             self.failIf(repository.isResourceChanged(document))
00089 
00090         document.manage_edit('change 1', '')
00091         self.commit()
00092         if self.do_commits:
00093             self.failUnless(repository.isResourceChanged(document))
00094 
00095         document = repository.checkinResource(document, '')
00096         self.commit()
00097         if self.do_commits:
00098             self.failIf(repository.isResourceChanged(document))
00099 
00100 
00101     def testVersionBookkeeping(self):
00102         # Check the consistency of the version bookkeeping info.
00103         repository = self.repository
00104 
00105         document = repository.applyVersionControl(self.document1)
00106         self.commit()
00107 
00108         info = repository.getVersionInfo(document)
00109         self.failUnless(info.user_id == 'UnitTester')
00110         self.failUnless(info.status == info.CHECKED_IN)
00111         self.failUnless(info.sticky == None)
00112         first_version = info.version_id
00113 
00114         document = repository.checkoutResource(document)
00115         self.commit()
00116         info = repository.getVersionInfo(document)
00117         self.failUnless(info.status == info.CHECKED_OUT)
00118 
00119         document = repository.checkinResource(document, '')
00120         self.commit()
00121         info = repository.getVersionInfo(document)
00122         self.failUnless(info.status == info.CHECKED_IN)
00123 
00124         document = repository.updateResource(document, first_version)
00125         self.commit()
00126         info = repository.getVersionInfo(document)
00127         self.failUnless(info.status == info.CHECKED_IN)
00128         self.failUnless(info.version_id == first_version)
00129 
00130         branch_name = 'Bug Fix Branch'
00131         repository.makeActivity(document, branch_name)
00132         self.commit()
00133         document = repository.updateResource(document, branch_name)
00134         self.commit()
00135         info = repository.getVersionInfo(document)
00136         self.failUnless(info.sticky == ('B', branch_name))
00137 
00138         document = repository.updateResource(document, 'mainline')
00139         self.commit()
00140         info = repository.getVersionInfo(document)
00141         self.failUnless(info.sticky == None)
00142 
00143         document = repository.checkoutResource(document)
00144         self.commit()
00145         info = repository.getVersionInfo(document)
00146         self.failUnless(info.status == info.CHECKED_OUT)
00147 
00148         document.manage_edit('change 1', '')
00149         self.commit()
00150 
00151         document = repository.uncheckoutResource(document)
00152         self.commit()
00153         info = repository.getVersionInfo(document)
00154         self.failUnless(info.status == info.CHECKED_IN)
00155 
00156 
00157     def testApplyVersionControl(self):
00158         # Test checking whether a versioned resource is up to date.
00159         from Products.ZopeVersionControl.Utility import VersionControlError
00160         repository = self.repository
00161 
00162         document = repository.applyVersionControl(self.document1)
00163         self.commit()
00164         self.failUnless(repository.isUnderVersionControl(document))
00165 
00166         # Make sure we can't do it a second time.
00167         self.failUnlessRaises(VersionControlError,
00168                               repository.applyVersionControl,
00169                               document
00170                               )
00171 
00172         info = repository.getVersionInfo(document)
00173     
00174         # Check that the last log entry record is what we expect.
00175         record = repository.getLogEntries(document)[0]
00176         self.failUnless(record.version_id == info.version_id)
00177         self.failUnless(record.user_id == 'UnitTester')
00178         self.failUnless(record.action == record.ACTION_CHECKIN)
00179         self.failUnless(record.path == '/folder1/folder2/document1')
00180 
00181 
00182     def testCheckoutResource(self):
00183         # Test checking out a version controlled resource.
00184         from Products.ZopeVersionControl.Utility import VersionControlError
00185         repository = self.repository
00186 
00187         document = repository.applyVersionControl(self.document1)
00188         self.commit()
00189 
00190         info = repository.getVersionInfo(document)
00191         first_version = info.version_id
00192 
00193         repository.checkoutResource(document)
00194         self.commit()
00195 
00196         # Make sure you can't checkout a checked-out resource.
00197         self.failUnlessRaises(VersionControlError,
00198                               repository.checkoutResource,
00199                               document
00200                               )
00201 
00202         # Check that the last log entry record is what we expect.
00203         record = repository.getLogEntries(document)[0]
00204         self.failUnless(record.version_id == first_version)
00205         self.failUnless(record.user_id == 'UnitTester')
00206         self.failUnless(record.action == record.ACTION_CHECKOUT)
00207         self.failUnless(record.path == '/folder1/folder2/document1')
00208 
00209         document = repository.checkinResource(document, '')
00210         self.commit()
00211         document = repository.updateResource(document, first_version)
00212         self.commit()
00213 
00214         # Make sure you can't checkout a non-up-to-date resource.
00215         self.failUnlessRaises(VersionControlError,
00216                               repository.checkoutResource,
00217                               document
00218                               )
00219 
00220         # Check that the last log entry record is what we expect.
00221         record = repository.getLogEntries(document)[0]
00222         self.failUnless(record.version_id == first_version)
00223         self.failUnless(record.user_id == 'UnitTester')
00224         self.failUnless(record.action == record.ACTION_UPDATE)
00225         self.failUnless(record.path == '/folder1/folder2/document1')
00226 
00227 
00228     def testCheckinResource(self):
00229         # Test checking in a version controlled resource.
00230         from Products.ZopeVersionControl.Utility import VersionControlError
00231         repository = self.repository
00232 
00233         document = repository.applyVersionControl(self.document1)
00234         self.commit()
00235 
00236         # Make sure you can't checkin a checked-in resource.
00237         self.failUnlessRaises(VersionControlError,
00238                               repository.checkinResource,
00239                               document, ''
00240                               )
00241 
00242         info = repository.getVersionInfo(document)
00243         first_version = info.version_id
00244 
00245         repository.checkoutResource(document)
00246         self.commit()
00247 
00248         document = repository.checkinResource(document, '')
00249         self.commit()
00250 
00251         # Check that the last log entry record is what we expect.
00252         record = repository.getLogEntries(document)[0]
00253         info = repository.getVersionInfo(document)
00254         self.failUnless(record.version_id == info.version_id)
00255         self.failUnless(record.user_id == 'UnitTester')
00256         self.failUnless(record.action == record.ACTION_CHECKIN)
00257         self.failUnless(record.path == '/folder1/folder2/document1')
00258 
00259         self.failUnlessRaises(VersionControlError,
00260                               repository.checkinResource,
00261                               document, ''
00262                               )
00263 
00264         document = repository.updateResource(document, first_version)
00265         self.commit()
00266 
00267         self.failUnlessRaises(VersionControlError,
00268                               repository.checkinResource,
00269                               document, ''
00270                               )
00271 
00272 
00273     def testUncheckoutResource(self):
00274         # Test uncheckout of a version controlled resource.
00275         from Products.ZopeVersionControl.Utility import VersionControlError
00276         repository = self.repository
00277 
00278         document = repository.applyVersionControl(self.document1)
00279         self.commit()
00280 
00281         info = repository.getVersionInfo(document)
00282         first_version = info.version_id
00283 
00284         repository.checkoutResource(document)
00285         self.commit()
00286 
00287         document.manage_edit('change 1', '')
00288 
00289         document = repository.uncheckoutResource(document)
00290         self.commit()
00291 
00292         info = repository.getVersionInfo(document)
00293         self.failUnless(info.status == info.CHECKED_IN)
00294 
00295         # Check that the last log entry record is what we expect.
00296         record = repository.getLogEntries(document)[0]
00297         self.failUnless(record.version_id == first_version)
00298         self.failUnless(record.user_id == 'UnitTester')
00299         self.failUnless(record.action == record.ACTION_UNCHECKOUT)
00300         self.failUnless(record.path == '/folder1/folder2/document1')
00301 
00302 
00303     def testUpdateResource(self):
00304         # Test updating a version controlled resource.
00305         from Products.ZopeVersionControl.Utility import VersionControlError
00306         repository = self.repository
00307 
00308         document = repository.applyVersionControl(self.document1)
00309         self.commit()
00310 
00311         info = repository.getVersionInfo(document)
00312         first_version = info.version_id
00313 
00314         repository.labelResource(document, 'First Version', 1)
00315 
00316         repository.checkoutResource(document)
00317         self.commit()
00318 
00319         document = repository.checkinResource(document, '')
00320         self.commit()
00321 
00322         document = repository.updateResource(document, first_version)
00323         self.commit()
00324         info = repository.getVersionInfo(document)
00325         self.failUnless(info.version_id == first_version)
00326 
00327         document = repository.updateResource(document, None)
00328         self.commit()
00329 
00330         document = repository.updateResource(document, 'First Version')
00331         self.commit()
00332         info = repository.getVersionInfo(document)
00333         self.failUnless(info.version_id == first_version)
00334 
00335         # Check that the last log entry record is what we expect.
00336         record = repository.getLogEntries(document)[0]
00337         self.failUnless(record.version_id == first_version)
00338         self.failUnless(record.user_id == 'UnitTester')
00339         self.failUnless(record.action == record.ACTION_UPDATE)
00340         self.failUnless(record.path == '/folder1/folder2/document1')
00341 
00342 
00343     def testLabelResource(self):
00344         # Test labeling a version controlled resource.
00345         from Products.ZopeVersionControl.Utility import VersionControlError
00346         repository = self.repository
00347 
00348         document = repository.applyVersionControl(self.document1)
00349         self.commit()
00350 
00351         info = repository.getVersionInfo(document)
00352         first_version = info.version_id
00353 
00354         repository.labelResource(document, 'First Version', 1)
00355 
00356         document = repository.checkoutResource(document)
00357         self.commit()
00358 
00359         self.failUnlessRaises(VersionControlError,
00360                               repository.labelResource,
00361                               document, 'First Version', 1
00362                               )
00363 
00364         document = repository.uncheckoutResource(document)
00365         self.commit()
00366 
00367         repository.makeActivity(document, 'Activity 1')
00368 
00369         self.failUnlessRaises(VersionControlError,
00370                               repository.labelResource,
00371                               document, 'mainline', 1
00372                               )
00373 
00374         self.failUnlessRaises(VersionControlError,
00375                               repository.labelResource,
00376                               document, 'Activity 1', 1
00377                               )
00378 
00379         document = repository.checkoutResource(document)
00380         self.commit()
00381 
00382         document = repository.checkinResource(document, '')
00383         self.commit()
00384 
00385         self.failUnlessRaises(VersionControlError,
00386                               repository.labelResource,
00387                               document, 'First Version', 0
00388                               )
00389 
00390         document = repository.updateResource(document, 'First Version')
00391         self.commit()
00392         info = repository.getVersionInfo(document)
00393         self.failUnless(info.version_id == first_version)
00394 
00395 
00396     def testActivityAPI(self):
00397         from Products.ZopeVersionControl.Utility import VersionControlError
00398 
00399         repository = self.repository
00400         document = self.document1
00401 
00402         repository.applyVersionControl(document)
00403         self.commit()
00404 
00405         self.failUnless(repository.isUnderVersionControl(document))
00406         self.failUnless(repository.isResourceUpToDate(document))
00407         if self.do_commits:
00408             self.failIf(repository.isResourceChanged(document))
00409 
00410         info = repository.getVersionInfo(document)
00411         self.failUnless(info.sticky == None)
00412         first_version = info.version_id
00413 
00414         activity_name = 'My Big Project'
00415 
00416         repository.makeActivity(document, activity_name)
00417         self.commit()
00418 
00419         # Make sure we can't do it again for the same activity id.
00420         self.failUnlessRaises(VersionControlError,
00421                               repository.makeActivity,
00422                               document, activity_name
00423                               )
00424 
00425         document = repository.updateResource(document, activity_name)
00426         self.commit()
00427 
00428         self.failUnless(repository.isResourceUpToDate(document))
00429         if self.do_commits:
00430             self.failIf(repository.isResourceChanged(document))
00431 
00432         info = repository.getVersionInfo(document)
00433         self.failUnless(info.version_id == first_version)
00434         self.failUnless(info.sticky == ('B', activity_name))
00435 
00436         repository.checkoutResource(document)
00437         self.commit()
00438 
00439         document.manage_edit('activity change 1', '')
00440         self.commit()
00441 
00442         document = repository.checkinResource(document, 'activity change 1')
00443         self.commit()
00444 
00445         info = repository.getVersionInfo(document)
00446         self.failUnless(info.sticky == ('B', activity_name))
00447 
00448         for n in range(10):
00449             activity_name = 'Activity %d' % n
00450 
00451             repository.makeActivity(document, activity_name)
00452             self.commit()
00453 
00454             info = repository.getVersionInfo(document)
00455             root_version = info.version_id
00456 
00457             document = repository.updateResource(document, activity_name)
00458             self.commit()
00459 
00460             self.failUnless(repository.isResourceUpToDate(document))
00461 
00462             info = repository.getVersionInfo(document)
00463             self.failUnless(info.sticky == ('B', activity_name))
00464             self.failUnless(info.version_id == root_version)
00465 
00466             repository.checkoutResource(document)
00467             self.commit()
00468                 
00469             document.manage_edit('activity change %d' % n, '')
00470             self.commit()
00471 
00472             document = repository.checkinResource(
00473                 document, 'activity change %d' % n
00474                 )
00475             self.commit()
00476 
00477             info = repository.getVersionInfo(document)
00478             self.failUnless(info.sticky == ('B', activity_name))
00479             self.failIf(info.version_id == root_version)
00480 
00481         document = repository.updateResource(document, root_version)
00482         self.commit()
00483 
00484         self.failIf(repository.isResourceUpToDate(document))
00485 
00486         document = repository.updateResource(document, first_version)
00487         self.commit()
00488 
00489 #        self.failUnless(repository.isResourceUpToDate(document))
00490 
00491 
00492 
00493 
00494     def testSelectionByDate(self):
00495         # Test selection of versions by date.
00496         from Products.ZopeVersionControl.Utility import VersionControlError
00497         from DateTime.DateTime import DateTime
00498         import time
00499 
00500         repository = self.repository
00501         document = repository.applyVersionControl(self.document1)
00502         self.commit()
00503 
00504         document = repository.checkoutResource(document)
00505         self.commit()
00506 
00507         document.manage_edit('change 1', '')
00508         self.commit()
00509 
00510         document = repository.checkinResource(document, 'change 1')
00511         self.commit()
00512 
00513         repository.labelResource(document, 'change 1')
00514         self.commit()
00515 
00516         info = repository.getVersionInfo(document)
00517         first_version = info.version_id
00518 
00519         # Trickery: we'll hack the timestamp of the first version so
00520         # that we can act like it was created yesterday :)
00521         history = repository.getVersionHistory(info.history_id)
00522         version = history.getVersionById(info.version_id)
00523         orig_time = version.date_created
00524         new_time = orig_time - 86400.0
00525         timestamp = int(orig_time / 60.0)
00526         new_stamp = int(new_time / 60.0)
00527         version.date_created = new_time
00528         branch = history._branches['mainline']
00529         key, val = branch.m_order.items()[0]
00530         del branch.m_date[timestamp]
00531         branch.m_date[new_stamp] = key
00532         self.commit()
00533 
00534         for n in range(10):
00535             document = repository.checkoutResource(document)
00536             self.commit()
00537             change_no = 'change %d' % (n + 2)
00538             document.manage_edit(change_no, '')
00539             self.commit()
00540             document = repository.checkinResource(document, change_no)
00541             self.commit()
00542             repository.labelResource(document, change_no)
00543             self.commit()
00544 
00545         target_time = time.time() - 14400.0
00546         document = repository.updateResource(document, target_time)
00547         self.commit()
00548         info = repository.getVersionInfo(document)
00549         self.failUnless(info.version_id == first_version)
00550 
00551         # Now do some branching and make sure we backtrack correctly
00552         # through the branch lineage when doing date selection.
00553         document = repository.updateResource(document, 'change 5')
00554         self.commit()
00555 
00556         for n in range(10):
00557             activity_name = 'Activity %d' % n
00558             repository.makeActivity(document, activity_name)
00559             self.commit()
00560             document = repository.updateResource(document, activity_name)
00561             self.commit()
00562             for i in range(10):
00563                 repository.checkoutResource(document)
00564                 self.commit()
00565                 document.manage_edit('activity change %d' % i, '')
00566                 self.commit()
00567                 document = repository.checkinResource(document, '')
00568                 self.commit()
00569 
00570         document = repository.updateResource(document, target_time)
00571         self.commit()
00572         info = repository.getVersionInfo(document)
00573         self.failUnless(info.version_id == first_version)
00574 
00575 
00576     def testSelectionByLabel(self):
00577         # Test labeling and selection of versions using labels.
00578         from Products.ZopeVersionControl.Utility import VersionControlError
00579 
00580         repository = self.repository
00581         document = repository.applyVersionControl(self.document1)
00582 
00583         # Ensure that labeling and lookup by label works as expected.
00584         label_set = []
00585         for n in range(10):
00586             change_no = 'change %d' % n
00587             document = repository.checkoutResource(document)
00588             document.manage_edit(change_no, '')
00589             document = repository.checkinResource(document, change_no)
00590             repository.labelResource(document, change_no)
00591             info = repository.getVersionInfo(document)
00592             label_set.append((change_no, info.version_id))
00593 
00594         for label, version_id in label_set:
00595             document = repository.updateResource(document, label)
00596             info = repository.getVersionInfo(document)
00597             self.failUnless(info.version_id == version_id)
00598             self.failUnless(info.sticky == ('L', label))
00599 
00600         # Ensure that label moving works as expected and that we get an
00601         # error if we try to reuse a label without forcing a label move.
00602         document = repository.updateResource(document, 'change 0')
00603         repository.labelResource(document, 'change 1', force=1)
00604         document = repository.updateResource(document, 'change 1')
00605         info = repository.getVersionInfo(document)
00606         self.failUnless(info.version_id == label_set[0][1])
00607 
00608         self.failUnlessRaises(VersionControlError,
00609                               repository.labelResource,
00610                               document, 'change 3'
00611                               )
00612 
00613 
00614     def testGetVersionOfResource(self):
00615         # Test retrieving specific versions of resources.
00616         from Products.ZopeVersionControl.Utility import VersionControlError
00617         repository = self.repository
00618 
00619         document = repository.applyVersionControl(self.document1)
00620         self.commit()
00621 
00622         info = repository.getVersionInfo(document)
00623         history_id = info.history_id
00624         first_version = info.version_id
00625 
00626         repository.labelResource(document, 'First Version')
00627 
00628         for n in range(10):
00629             repository.checkoutResource(document)
00630             self.commit()
00631             document = repository.checkinResource(document, '')
00632             self.commit()
00633 
00634         # Make sure the "get version of resource" api is working.
00635         doc_copy = repository.getVersionOfResource(
00636             info.history_id, first_version
00637             )
00638         info = repository.getVersionInfo(doc_copy)
00639         self.failUnless(info.version_id == first_version)
00640         self.failUnless(info.sticky == ('V', first_version))
00641         self.failUnless(document._p_oid != doc_copy._p_oid)
00642         self.failUnless(document is not doc_copy)
00643 
00644         doc_copy = repository.getVersionOfResource(
00645             info.history_id, "First Version"
00646             )
00647         info = repository.getVersionInfo(doc_copy)
00648         self.failUnless(info.version_id == first_version)
00649         self.failUnless(info.sticky == ('L', 'First Version'))
00650         self.failUnless(document._p_oid != doc_copy._p_oid)
00651         self.failUnless(document is not doc_copy)
00652 
00653 
00654     def testDetectPersistentSubObjectChange(self):
00655         # Test detection of changes to persistent sub-objects.
00656         repository = self.repository
00657         folder2 = self.folder2
00658         document = self.document1
00659 
00660         # Place a resource w/ persistent subobjects under version control.
00661         repository.applyVersionControl(folder2)
00662         get_transaction().commit()
00663 
00664         document1 = getattr(folder2, 'document1')
00665         document1.manage_edit('spam spam', '')
00666         get_transaction().commit()
00667 
00668         self.failUnless(repository.isResourceChanged(folder2))
00669 
00670 
00671     def testContainerVersioning(self):
00672         from OFS.DTMLDocument import addDTMLDocument
00673         # Verify that containers and items are versioned independently.
00674         repository = self.repository
00675         folder1 = self.app.folder1
00676         folder2 = folder1.folder2
00677         folder1.testattr = 'container_v1'
00678         folder2.testattr = 'item_v1'
00679 
00680         self.assert_(not repository.isUnderVersionControl(folder1))
00681         repository.applyVersionControl(folder1)
00682         folder1 = self.app.folder1
00683         self.assert_(repository.isUnderVersionControl(folder1))
00684         self.assert_(not repository.isUnderVersionControl(folder2))
00685         repository.applyVersionControl(folder2)
00686         folder2 = folder1.folder2
00687         self.assert_(repository.isUnderVersionControl(folder2))
00688         self.assert_(not repository.isUnderVersionControl(folder2.document1))
00689 
00690         # Make the first version of folder1 and check it in.
00691         repository.checkoutResource(folder1)
00692         folder1 = self.app.folder1
00693         repository.checkinResource(folder1)
00694         folder1 = self.app.folder1
00695         folder2 = folder1.folder2
00696         info = repository.getVersionInfo(folder1)
00697         first_version = info.version_id
00698 
00699         # Change folder1 and check it in again
00700         repository.checkoutResource(folder1)
00701         folder1 = self.app.folder1
00702         folder1.testattr = 'container_v2'
00703         addDTMLDocument(folder1, 'document3', file='some more text')
00704         repository.checkinResource(folder1)
00705         folder1 = self.app.folder1
00706         folder2 = folder1.folder2
00707 
00708         # Change folder2
00709         repository.checkoutResource(folder2)
00710         folder2 = folder1.folder2
00711         folder2.testattr = 'item_v2'
00712 
00713         # Now revert folder1 and verify that folder2 was not reverted.
00714         repository.updateResource(folder1, first_version)
00715         folder1 = self.app.folder1
00716         folder2 = folder1.folder2
00717         self.assertEqual(folder1.testattr, 'container_v1')
00718         self.assertEqual(folder2.testattr, 'item_v2')
00719 
00720         # Verify that document3 remains an item of the reverted folder1.
00721         self.assert_(hasattr(folder1, 'document3'))
00722         self.assert_(str(folder1.document3) == 'some more text')
00723 
00724         # Remove document3 and verify that it doesn't reappear upon revert.
00725         folder1._delObject('document3')
00726         repository.updateResource(folder1, '')
00727         folder1 = self.app.folder1
00728         self.assertEqual(folder1.testattr, 'container_v2')
00729         self.assertEqual(folder1.folder2.testattr, 'item_v2')
00730         self.assert_(not hasattr(folder1, 'document3'))
00731 
00732 
00733     def testNonVersionedAttribute(self):
00734         # Test a non-version-controlled attribute mixed with
00735         # a version-controlled attribute.
00736         self.document1.extra_attr = 'v1'
00737         self.document1.__vc_ignore__ = ('__ac_local_roles__',)
00738         self.document1.__ac_local_roles__ = {'sam': ['Manager',]}
00739         repository = self.repository
00740         document = repository.applyVersionControl(self.document1)
00741         info = repository.getVersionInfo(document)
00742         first_version = info.version_id
00743         repository.checkoutResource(document)
00744         self.document1.extra_attr = 'v2'
00745         self.document1.__ac_local_roles__ = {}
00746         repository.checkinResource(document)
00747         repository.updateResource(document, first_version)
00748         self.assertEqual(document.extra_attr, 'v1')
00749         self.assertEqual(document.__ac_local_roles__, {})
00750 
00751     def testNonVersionedAttributeWithAcquisition(self):
00752         # Test a non-version-controlled attribute 
00753         # that is acquired does not cause an error
00754         self.document1.__vc_ignore__ = ('dummy_attr',)
00755         self.folder1.dummy_attr = 'dummy_attr'
00756         self.assertEqual( self.folder1.dummy_attr, self.document1.dummy_attr )
00757 
00758         repository = self.repository
00759         document = repository.applyVersionControl(self.document1)
00760         info = repository.getVersionInfo(document)
00761         first_version = info.version_id
00762         repository.checkoutResource(document)
00763         self.document1.extra_attr = 'new'
00764         repository.checkinResource(document)
00765         repository.updateResource(document, first_version)
00766 
00767 class VersionControlTestsWithCommits(VersionControlTests):
00768     """Version control test suite with transaction commits that mimic
00769        the transaction commits that you would get with Web based usage."""
00770     do_commits = 1
00771 
00772 def test_suite():
00773     suite = unittest.TestSuite()
00774     suite.addTest(unittest.makeSuite(VersionControlTests))
00775     suite.addTest(unittest.makeSuite(VersionControlTestsWithCommits))
00776     return suite
00777 
00778 if __name__ == '__main__':
00779     unittest.main(defaultTest='test_suite')
00780