You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/02/05 21:23:34 UTC
[40/42] git commit: [#4691] Fixed failing tests due to LCD changes
[#4691] Fixed failing tests due to LCD changes
Signed-off-by: Cory Johns <jo...@geek.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/c97950a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c97950a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c97950a6
Branch: refs/heads/master
Commit: c97950a67c5c571e1563cf0dc7bfbf22910d51d7
Parents: ddb3a5a
Author: Cory Johns <jo...@geek.net>
Authored: Tue Jan 22 22:49:42 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Feb 5 20:22:52 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/repository.py | 2 +-
Allura/allura/model/repo.py | 7 +-
Allura/allura/model/repo_refresh.py | 3 +-
Allura/allura/tests/unit/test_repo.py | 100 -----------------
ForgeGit/forgegit/model/git_repo.py | 12 +--
ForgeGit/forgegit/tests/model/test_repository.py | 26 +++--
ForgeSVN/forgesvn/tests/model/test_repository.py | 20 ----
7 files changed, 25 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 6aeca01..40a9bc3 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -433,7 +433,7 @@ class CommitBrowser(BaseController):
if path:
path = path.lstrip('/')
params = dict(path=path, rev=self._commit._id)
- commits = c.app.repo.commits(skip=start, limit=limit, **params)
+ commits = list(c.app.repo.commits(skip=start, limit=limit, **params))
count = c.app.repo.commits_count(**params)
revisions = M.repo.Commit.query.find({'_id': {'$in': commits}}).sort('committed.date', -1)
c.log_widget = self.log_widget
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 81ea0b5..2c5b7e9 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -464,7 +464,9 @@ class Tree(RepoObject):
# look for existing new format first
last_commit = LastCommit.get(self, create=True)
if last_commit:
- session(last_commit).flush(last_commit)
+ s = session(last_commit)
+ if s:
+ s.flush(last_commit)
return self._lcd_map(last_commit)
# otherwise, try old format
old_style_results = self.ls_old()
@@ -611,8 +613,7 @@ class Blob(object):
def prev_commit(self):
lc = LastCommit.get(self.tree)
if lc:
- entry = lc.by_name[self.name]
- last_commit = self.repo.commit(entry.commit_id)
+ last_commit = self.repo.commit(lc.by_name[self.name])
prev_commit = last_commit.get_parent()
try:
tree = prev_commit and prev_commit.get_path(self.tree.path().rstrip('/'))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index d80b981..48a64e7 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -58,7 +58,7 @@ def refresh_repo(repo, all_commits=False, notify=True):
if (i+1) % 100 == 0:
log.info('Refresh child info %d for parents of %s', (i+1), ci._id)
- if repo.tool.lower() != 'svn':
+ if repo._refresh_precompute:
# Refresh commit runs
commit_run_ids = commit_ids
# Check if the CommitRuns for the repo are in a good state by checking for
@@ -103,6 +103,7 @@ def refresh_repo(repo, all_commits=False, notify=True):
cache = ModelCache()
for i, oid in enumerate(reversed(commit_ids)):
ci = cache.get(Commit, dict(_id=oid))
+ ci.set_context(repo)
compute_lcds(ci, cache)
ThreadLocalORMSession.flush_all()
if (i+1) % 100 == 0:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/Allura/allura/tests/unit/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py
index f892875..837d56d 100644
--- a/Allura/allura/tests/unit/test_repo.py
+++ b/Allura/allura/tests/unit/test_repo.py
@@ -103,106 +103,6 @@ def blob(name, id):
return b
-class TestRefreshLastCommit(unittest.TestCase):
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_no_changes(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1')
- rhs_tree = tree('rhs_tree', 'tid1')
- parent_tree = Mock()
- commit_info = {}
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- self.assertEqual(set_last_commit.call_count, 0)
- self.assertEqual(get.call_count, 0)
-
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_unchanged_blob(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('unchanged_blob', 'bid1')])
- rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('unchanged_blob', 'bid1')])
- parent_tree = Mock()
- commit_info = {}
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- self.assertEqual(set_last_commit.call_count, 0)
- self.assertEqual(get.call_count, 0)
-
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_changed_blob(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('changed_blob', 'bid1')])
- rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('changed_blob', 'bid2')])
- parent_tree = Mock()
- commit_info = {'author': 'Testy'}
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- set_last_commit.assert_called_once_with(repo_id, path, 'changed_blob', 'bid2', commit_info)
- self.assertEqual(get.call_count, 0)
-
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_new_blob(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('old_blob', 'bid1')])
- rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('new_blob', 'bid2')])
- parent_tree = Mock()
- commit_info = {'author': 'Testy'}
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- set_last_commit.assert_called_once_with(repo_id, path, 'new_blob', 'bid2', commit_info)
- self.assertEqual(get.call_count, 0)
-
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_unchanged_subtree(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1', trees=[tree('unchanged_tree', 'tid3')])
- rhs_tree = tree('rhs_tree', 'tid2', trees=[tree('unchanged_tree', 'tid3', blobs=[blob('new_blob', 'bid1')])])
- parent_tree = Mock()
- commit_info = {'author': 'Testy'}
- get.side_effect = [rhs_tree.tree_ids[0], lhs_tree.tree_ids[0]]
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- self.assertEqual(set_last_commit.call_count, 0)
- self.assertEqual(get.call_count, 2)
- self.assertEqual(get.call_args_list, [[{'_id': 'tid3'}], [{'_id': 'tid3'}]])
-
- @patch('allura.model.repo_refresh.TreeDoc.m.get')
- @patch('allura.model.repo_refresh.set_last_commit')
- def test_changed_subtree(self, set_last_commit, get):
- repo_id = 'repo_1'
- path = '/'
- lhs_tree = tree('lhs_tree', 'tid1', trees=[tree('changed_tree', 'tid3')])
- rhs_tree = tree('rhs_tree', 'tid2', trees=[tree('changed_tree', 'tid4', blobs=[blob('new_blob', 'bid1')])])
- parent_tree = Mock()
- commit_info = {'author': 'Testy'}
- get.side_effect = [rhs_tree.tree_ids[0], lhs_tree.tree_ids[0]]
-
- M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
-
- self.assertEqual(set_last_commit.call_count, 2)
- self.assertEqual(set_last_commit.call_args_list, [
- [(repo_id, '/', 'changed_tree', 'tid4', commit_info)],
- [(repo_id, '/changed_tree/', 'new_blob', 'bid1', commit_info)],
- ])
- self.assertEqual(get.call_count, 2)
- self.assertEqual(get.call_args_list, [[{'_id': 'tid4'}], [{'_id': 'tid3'}]])
-
-
class TestTree(unittest.TestCase):
@patch('allura.model.repo.Tree.__getitem__')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index d7409d5..111c863 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -237,18 +237,12 @@ class GitImplementation(M.RepositoryImplementation):
return doc
def commits(self, path=None, rev=None, skip=None, limit=None):
- #params = dict(paths=path)
- #if rev is not None:
- # params['rev'] = rev
- #if skip is not None:
- # params['skip'] = skip
- #if limit is not None:
- # params['max_count'] = limit
- #return [c.hexsha for c in self._git.iter_commits(**params)]
if rev is None:
rev = 'HEAD'
if skip is None:
skip = 0
+ if path is not None:
+ path = path.strip('/')
max = skip + limit if limit is not None else None
commit = self.commit(rev)
i = 0
@@ -257,7 +251,7 @@ class GitImplementation(M.RepositoryImplementation):
if i >= skip:
yield commit._id
i += 1
- if max is not None and i > max:
+ if max is not None and i >= max:
break
commit = commit.get_parent()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index fac154e..1c5045b 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -44,6 +44,8 @@ class TestNewGit(unittest.TestCase):
# tool = 'git',
# status = 'creating')
self.repo.refresh()
+ # refresh sets c.model_cache, which can cause persistence between tests
+ c.model_cache = None
self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
self.rev.repo = self.repo
ThreadLocalORMSession.flush_all()
@@ -113,6 +115,8 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
tool = 'git',
status = 'creating')
self.repo.refresh()
+ # refresh sets c.model_cache, which can cause persistence between tests
+ c.model_cache = None
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
@@ -256,32 +260,32 @@ class TestGitCommit(unittest.TestCase):
def test_commits(self):
# path only
- commits = self.repo.commits()
+ commits = list(self.repo.commits())
assert len(commits) == 4, 'Returned %s commits' % len(commits)
assert "9a7df788cf800241e3bb5a849c8870f2f8259d98" in commits, commits
- commits = self.repo.commits('README')
+ commits = list(self.repo.commits('README'))
assert len(commits) == 2, 'Returned %s README commits' % len(commits)
assert "1e146e67985dcd71c74de79613719bef7bddca4a" in commits, commits
assert "df30427c488aeab84b2352bdf88a3b19223f9d7a" in commits, commits
- assert self.repo.commits('does/not/exist') == []
+ assert list(self.repo.commits('does/not/exist')) == []
# with path and start rev
- commits = self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a')
+ commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'))
assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a'], commits
# skip and limit
- commits = self.repo.commits(None, rev=None, skip=1, limit=2)
+ commits = list(self.repo.commits(None, rev=None, skip=1, limit=2))
assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a', '6a45885ae7347f1cac5103b0050cc1be6a1496c8']
- commits = self.repo.commits(None, '6a45885ae7347f1cac5103b0050cc1be6a1496c8', skip=1)
+ commits = list(self.repo.commits(None, '6a45885ae7347f1cac5103b0050cc1be6a1496c8', skip=1))
assert commits == ['9a7df788cf800241e3bb5a849c8870f2f8259d98']
- commits = self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a', skip=1)
+ commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a', skip=1))
assert commits == []
# path to dir
- commits = self.repo.commits('a/b/c/')
+ commits = list(self.repo.commits('a/b/c/'))
assert commits == ['6a45885ae7347f1cac5103b0050cc1be6a1496c8', '9a7df788cf800241e3bb5a849c8870f2f8259d98']
- commits = self.repo.commits('a/b/c/', skip=1)
+ commits = list(self.repo.commits('a/b/c/', skip=1))
assert commits == ['9a7df788cf800241e3bb5a849c8870f2f8259d98']
- commits = self.repo.commits('a/b/c/', limit=1)
+ commits = list(self.repo.commits('a/b/c/', limit=1))
assert commits == ['6a45885ae7347f1cac5103b0050cc1be6a1496c8']
- commits = self.repo.commits('not/exist/')
+ commits = list(self.repo.commits('not/exist/'))
assert commits == []
def test_commits_count(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c97950a6/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index b683fd0..af29b49 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -619,26 +619,6 @@ class TestRepoObject(_TestWithRepoAndCommit):
assert obj0 is obj1
assert isnew0 and not isnew1
- def test_set_last_commit(self):
- obj, isnew = M.repo.Tree.upsert('foo1')
- M.repo_refresh.set_last_commit(
- self.repo._id, '/', 'fakefile', obj._id,
- M.repo_refresh.get_commit_info(self.ci))
-
- def test_get_last_commit(self):
- obj, isnew = M.repo.Tree.upsert('foo1')
- lc0 = M.repo_refresh.set_last_commit(
- self.repo._id, '/', 'fakefile', obj._id,
- M.repo_refresh.get_commit_info(self.ci))
-
- lc1 = M.repo.LastCommitDoc.m.get(object_id=obj._id)
- assert lc0 == lc1
-
- def test_get_last_commit_missing(self):
- obj, isnew = M.repo.Tree.upsert('foo1')
- lc1 = M.repo.LastCommitDoc.m.get(object_id=obj._id)
- assert lc1 is None
-
def test_artifact_methods(self):
assert self.ci.index_id() == 'allura/model/repo/Commit#foo', self.ci.index_id()
assert self.ci.primary() is self.ci, self.ci.primary()