Skip to content

Commit

Permalink
Made sure the VersionHistory.BranchInfo class fulfill the API, provid…
Browse files Browse the repository at this point in the history
…ing a getId method. Added missing security declarations.
  • Loading branch information
dorneles committed Sep 10, 2010
1 parent 1ea6688 commit 4f862cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ Changelog
1.1.3 - unreleased
------------------

- Made sure the VersionHistory.BranchInfo class fulfill the API,
providing a getId method. Added missing security declarations.

1.1.2 - 2010-08-05
------------------

- Make sure we cast MAX32 to an int, as ``2**31`` would be automatically
- Made sure we cast MAX32 to an int, as ``2**31`` would be automatically
overflow to a long on 32bit Python's.

1.1.1 - 2010-08-04
Expand Down
18 changes: 15 additions & 3 deletions Products/ZopeVersionControl/VersionHistory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################

__version__='$Revision: 1.4 $'[11:-2]
Expand Down Expand Up @@ -204,7 +204,7 @@ def getVersionByDate(self, branch_id, timestamp):
# up to the caller to decide what to do in this situation.
if branch.root is None:
return None

# If the branch has a root (a version in another branch), then
# we check the root and do it again with the ancestor branch.
rootver = self._versions[branch.root]
Expand All @@ -222,6 +222,7 @@ def getVersionIds(self, branch_id=None):
return self._branches[branch_id].versionIds()
return self._versions.keys()


InitializeClass(VersionHistory)


Expand All @@ -230,6 +231,8 @@ class BranchInfo(Implicit, Persistent):
maintains the name of the branch, the version id of the root of
the branch and indices to allow for efficient lookups."""

security = ClassSecurityInfo()

def __init__(self, name, root):
# m_order maintains a newest-first mapping of int -> version id.
# m_date maintains a mapping of a packed date (int # of minutes
Expand All @@ -242,6 +245,12 @@ def __init__(self, name, root):
self.name = name
self.root = root

security.declarePublic('getId')
def getId(self):
"""Return the name of the object as string."""
return self.name

security.declarePrivate('append')
def append(self, version):
"""Append a version to the branch information. Note that this
does not store the actual version, but metadata about the
Expand All @@ -254,10 +263,12 @@ def append(self, version):
timestamp = int(version.date_created / 60.0)
self.m_date[timestamp] = key

security.declarePrivate('versionIds')
def versionIds(self):
"""Return a newest-first sequence of version ids in the branch."""
return self.m_order.values()

security.declarePrivate('latest')
def latest(self):
"""Return the version id of the latest version in the branch."""
mapping = self.m_order
Expand All @@ -268,4 +279,5 @@ def latest(self):
def __len__(self):
return len(self.m_order)


InitializeClass(BranchInfo)
42 changes: 42 additions & 0 deletions Products/ZopeVersionControl/tests/testVersionHistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Test the VersionHistory internals.
$Id$
"""
import unittest

from common import common_setUp
from common import common_tearDown


class VersionHistoryTests(unittest.TestCase):

setUp = common_setUp
tearDown = common_tearDown

def testBranchHaveName(self):
self.repository.applyVersionControl(self.document1)
info = self.repository.getVersionInfo(self.document1)
history = self.repository.getVersionHistory(info.history_id)
branch = history.createBranch('foo', None)
self.assertEqual(branch.getId(), 'foo')


def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(VersionHistoryTests))
return suite

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

0 comments on commit 4f862cb

Please sign in to comment.