You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2019/11/18 21:46:18 UTC

[allura] 03/11: [#8340] repo: remove dead code, add some test coverage

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit ba5f00c1c031aaa47fc96e89d0946329e104c729
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Nov 12 13:29:45 2019 -0500

    [#8340] repo: remove dead code, add some test coverage
---
 Allura/allura/model/repository.py                  | 85 ----------------------
 Allura/allura/tests/model/test_repo.py             | 27 +++++++
 .../forgegit/tests/functional/test_controllers.py  | 27 +++++++
 3 files changed, 54 insertions(+), 85 deletions(-)

diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 98200fa..203e3ef 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -528,15 +528,6 @@ class Repository(Artifact, ActivityObject):
     def paged_diffs(self, commit_id, start=0, end=None,  onlyChangedFiles=False):
         return self._impl.paged_diffs(commit_id, start, end, onlyChangedFiles)
 
-    def _log(self, rev, skip, limit):
-        head = self.commit(rev)
-        if head is None:
-            return
-        for _id in self.commitlog([head._id], skip, limit):
-            ci = head.query.get(_id=_id)
-            ci.set_context(self)
-            yield ci
-
     def init_as_clone(self, source_path, source_name, source_url):
         self.upstream_repo.name = source_name
         self.upstream_repo.url = source_url
@@ -1158,33 +1149,6 @@ class Commit(RepoObject, ActivityObject):
     def symbolic_ids(self):
         return self.repo.symbolics_for_commit(self)
 
-    def get_parent(self, index=0):
-        '''Get the parent of this commit.
-
-        If there is no parent commit, or if an invalid index is given,
-        returns None.
-        '''
-        try:
-            cache = getattr(c, 'model_cache', '') or ModelCache()
-            ci = cache.get(Commit, dict(_id=self.parent_ids[index]))
-            if not ci:
-                return None
-            ci.set_context(self.repo)
-            return ci
-        except IndexError:
-            return None
-
-    def climb_commit_tree(self, predicate=None):
-        '''
-        Returns a generator that walks up the commit tree along
-        the first-parent ancestory, starting with this commit,
-        optionally filtering by a predicate.'''
-        ancestor = self
-        while ancestor:
-            if predicate is None or predicate(ancestor):
-                yield ancestor
-            ancestor = ancestor.get_parent()
-
     def url(self):
         if self.repo is None:
             self.repo = self.guess_repo()
@@ -1253,13 +1217,6 @@ class Commit(RepoObject, ActivityObject):
                     cur = cur[part]
         return cur
 
-    def has_path(self, path):
-        try:
-            self.get_path(path)
-            return True
-        except KeyError:
-            return False
-
     @LazyProperty
     def changed_paths(self):
         '''
@@ -1352,19 +1309,6 @@ class Tree(RepoObject):
     parent = None
     name = None
 
-    def compute_hash(self):
-        '''Compute a hash based on the contents of the tree.  Note that this
-        hash does not necessarily correspond to any actual DVCS hash.
-        '''
-        lines = (
-            ['tree' + x.name + x.id for x in self.tree_ids]
-            + ['blob' + x.name + x.id for x in self.blob_ids]
-            + [x.type + x.name + x.id for x in self.other_ids])
-        sha_obj = sha1()
-        for line in sorted(lines):
-            sha_obj.update(line)
-        return sha_obj.hexdigest()
-
     def __getitem__(self, name):
         cache = getattr(c, 'model_cache', '') or ModelCache()
         obj = self.by_name[name]
@@ -1578,11 +1522,6 @@ class Blob(object):
     def text(self):
         return self.open().read()
 
-    @classmethod
-    def diff(cls, v0, v1):
-        differ = SequenceMatcher(v0, v1)
-        return differ.get_opcodes()
-
 
 class LastCommit(RepoObject):
 
@@ -1720,8 +1659,6 @@ class ModelCache(object):
         # keyed by query, holds _id
         self._query_cache = defaultdict(OrderedDict)
         self._instance_cache = defaultdict(OrderedDict)  # keyed by _id
-        self._synthetic_ids = defaultdict(set)
-        self._synthetic_id_queries = defaultdict(set)
 
     def _normalize_query(self, query):
         _query = query
@@ -1763,9 +1700,6 @@ class ModelCache(object):
                                                              None)))
             if _id is None:
                 _id = val._model_cache_id = bson.ObjectId()
-                self._synthetic_ids[cls].add(_id)
-            if _id in self._synthetic_ids:
-                self._synthetic_id_queries[cls].add(_query)
             self._query_cache[cls][_query] = _id
             self._instance_cache[cls][_id] = val
         else:
@@ -1815,25 +1749,6 @@ class ModelCache(object):
         key, val = cache.popitem(last=False)
         return val
 
-    def expire_new_instances(self, cls):
-        '''
-        Expire any instances that were "new" or had no _id value.
-
-        If a lot of new instances of a class are being created, it's possible
-        for a query to pull a copy from mongo when a copy keyed by the synthetic
-        ID is still in the cache, potentially causing de-sync between the copies
-        leading to one with missing data overwriting the other.  Clear new
-        instances out of the cache relatively frequently (depending on the query
-        and instance cache sizes) to avoid this.
-        '''
-        for _query in self._synthetic_id_queries[cls]:
-            self._query_cache[cls].pop(_query)
-        self._synthetic_id_queries[cls] = set()
-        for _id in self._synthetic_ids[cls]:
-            instance = self._instance_cache[cls].pop(_id)
-            self._try_flush(instance, expunge=True)
-        self._synthetic_ids[cls] = set()
-
     def num_queries(self, cls=None):
         if cls is None:
             return sum([len(c) for c in self._query_cache.values()])
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 7a4410a..5007d28 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -94,6 +94,33 @@ class RepoTestBase(unittest.TestCase):
             with mock.patch.dict(config, values, clear=True):
                 self.assertEqual(result, repo.refresh_url())
 
+    def test_clone_command_categories(self):
+        c.app = mock.Mock(**{'config._id': 'deadbeef'})
+        repo = M.repository.Repository(tool='git')
+        cmd_cats = repo.clone_command_categories(anon=False)
+        assert_equal(cmd_cats, [
+            {'key': 'file', 'name': 'File', 'title': u'Filesystem'}
+        ])
+
+        cmd_cats = repo.clone_command_categories(anon=True)
+        assert_equal(cmd_cats, [
+            {'key': 'file', 'name': 'File', 'title': u'Filesystem'}
+        ])
+
+        repo = M.repository.Repository(tool='something-else')  # no "something-else" in config so will use defaults
+        cmd_cats = repo.clone_command_categories(anon=False)
+        assert_equal(cmd_cats, [
+            {'key': 'rw', 'name': 'RW', 'title': 'Read/Write'},
+            {'key': 'ro', 'name': 'RO', 'title': 'Read Only'},
+            {'key': 'https', 'name': 'HTTPS', 'title': 'HTTPS'}
+        ])
+
+        cmd_cats = repo.clone_command_categories(anon=True)
+        assert_equal(cmd_cats, [
+            {'key': 'ro', 'name': 'RO', 'title': 'Read Only'},
+            {'key': 'https_anon', 'name': 'HTTPS', 'title': 'HTTPS'}
+        ])
+
 
 class TestLastCommit(unittest.TestCase):
     def setUp(self):
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 1f2aa0c..4b0c079 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -156,6 +156,11 @@ class TestRootController(_TestCase):
              u'parents': [u'6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
              u'message': u'Add README', u'row': 2})
 
+    def test_commit_browser_basic_view(self):
+        resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/basic')
+        resp.mustcontain('Rick')
+        resp.mustcontain('Change README')
+
     def test_log(self):
         resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/')
         assert 'Initial commit' in resp
@@ -457,6 +462,15 @@ class TestRootController(_TestCase):
         r = self.app.get('/p/test/src-git/markdown_syntax_dialog')
         assert_in('<h1>Markdown Syntax Guide</h1>', r)
 
+    def test_refresh(self):
+        r = self.app.get('/p/test/src-git/refresh')
+        assert_in('refresh queued', r)
+        assert_equal(1, M.MonQTask.query.find(dict(task_name='allura.tasks.repo_tasks.refresh')).count())
+
+        r = self.app.get('/p/test/src-git/refresh', extra_environ={'HTTP_REFERER': '/p/test/src-git/'}, status=302)
+        assert_in('is being refreshed', self.webflash(r))
+        assert_equal(2, M.MonQTask.query.find(dict(task_name='allura.tasks.repo_tasks.refresh')).count())
+
 
 class TestRestController(_TestCase):
     def test_index(self):
@@ -660,6 +674,13 @@ class TestFork(_TestCase):
         r = self.app.get('/p/test/src-git/merge-requests/1/', status=200)
         assert_commit_details(r)
 
+        r = self.app.get('/p/test/src-git/merge-requests/1/can_merge_task_status')
+        assert_equal(r.json, {'status': 'ready'})
+        r = self.app.get('/p/test/src-git/merge-requests/1/can_merge_result')
+        assert_equal(r.json, {'can_merge': None})
+        r = self.app.get('/p/test/src-git/merge-requests/1/merge_task_status')
+        assert_equal(r.json, {'status': None})
+
     def test_merge_request_detail_noslash(self):
         self._request_merge()
         r = self.app.get('/p/test/src-git/merge-requests/1', status=301)
@@ -686,6 +707,12 @@ class TestFork(_TestCase):
         assert_regexp_matches(r.html.findAll('span')[-2].getText(), r'[0-9]+ seconds? ago')
         assert_regexp_matches(r.html.findAll('span')[-1].getText(), r'[0-9]+ seconds? ago')
 
+        r = self.app.get('/p/test/src-git/merge-requests/?status=rejected')
+        assert 'href="%s/"' % mr_num not in r, r
+
+        r = self.app.get('/p/test/src-git/merge-requests/?status=all')
+        assert 'href="%s/"' % mr_num in r, r
+
     def test_merge_request_update_status(self):
         r, mr_num = self._request_merge()
         r = self.app.post('/p/test/src-git/merge-requests/%s/save' % mr_num,