Instantly share code, notes, and snippets.
Created
April 27, 2016 20:15
-
Save phraniiac/19d385bda4570668a3b1bdb95feff882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit da6ee3b541166af46c039d88dd401578f562b774 | |
Author: dastanforever <pranav.sharma.nits@gmail.com> | |
Date: Wed Jan 3 18:00:31 2016 +0530 | |
[#7949] File listing in commites changed. Tests added. | |
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py | |
index 3fc26dd..2f67783 100644 | |
--- a/Allura/allura/controllers/repository.py | |
+++ b/Allura/allura/controllers/repository.py | |
@@ -563,7 +563,7 @@ def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw): | |
tree = self._commit.tree | |
limit, page, start = g.handle_paging(limit, page, | |
default=self.DEFAULT_PAGE_LIMIT) | |
- diffs = self._commit.paged_diffs(start=start, end=start + limit) | |
+ diffs = self._commit.paged_diffs(start=start, end=start + limit, onlyChangedFiles=True) | |
result['artifacts'] = [] | |
for t in ('added', 'removed', 'changed', 'copied', 'renamed'): | |
for f in diffs[t]: | |
@@ -577,6 +577,14 @@ def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw): | |
) | |
count = diffs['total'] | |
result.update(dict(page=page, limit=limit, count=count)) | |
+ # Sort the result['artifacts'] which is in format as below - | |
+ # [('added', u'aaa.txt', 'blob', True), | |
+ # ('added', u'eee.txt', 'blob', True), | |
+ # ('added', u'ggg.txt', 'blob', True), | |
+ # ('removed', u'bbb.txt', 'tree', None), | |
+ # ('removed', u'ddd.txt', 'tree', None), | |
+ # ('changed', u'ccc.txt', 'blob', True)] | |
# FOR SOCIALCOPS---- | |
# THE BELOW LINE WAS THE RESULT OF THE DISCUSSION WITH MY MENTOR. BELOW THAT LINE SHOWS THE PREVIOUS CODE. | |
# ALTHOUGH THE FUNCTIONALITY IS NOT ONLY THE SORTING BUT ALSO RETURNING FORMATTED INPUT OF THE PREVIOUS CODE, | |
# BUT THE IDEA WAS SIMILAR. | |
+ result['artifacts'].sort(key=lambda x: x[1]['old'] if(type(x[1]) == dict) else x[1]) | |
# PREVIOUS CODE. | |
+ dr = {} | |
+ test_out = [] | |
+ x = 0 | |
+ while x < len(cmd_output): | |
+ print x | |
+ status = cmd_output[x][0] | |
+ l = [] | |
+ l.append(cmd_output[x][0]) | |
+ l.append(cmd_output[x+1]) | |
+ x += 2 | |
+ if status in ('R', 'C'): | |
+ l.append(cmd_output[x+2]) | |
+ x += 1 | |
+ test_out.append(l) | |
+ | |
+ test_out.sort(key=lambda x: x[-1][x[-1].rfind('/')+1], reverse = True) | |
+ print test_out | |
+ x = 0 | |
+ files = [] | |
+ while x < len(test_out): | |
+ status = test_out[x][0] | |
+ if status in ('R', 'C'): | |
+ ratio = float(test_out[x][0][1:4]) / 100.0 | |
+ files.append((status, { | |
+ 'new': h.really_unicode(test_out[x][2]), | |
+ 'old': h.really_unicode(test_out[x][1]), | |
+ 'ratio': ratio, | |
+ })) | |
+ else: | |
+ files.append((status, h.really_unicode(test_out[x][1]))) | |
+ x += 1 | |
+ print files | |
+ for status, name in files[start:end]: | |
+ change_list = { | |
+ 'R': result['renamed'], | |
+ 'C': result['copied'], | |
+ 'A': result['added'], | |
+ 'D': result['removed'], | |
+ 'M': result['changed'] | |
+ }[status] | |
+ change_list.append(name) | |
+ | |
+ result['total'] = len(files) | |
return result | |
@expose('jinja:allura:templates/repo/commit_basic.html') | |
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py | |
index b39532b..9edbd58 100644 | |
--- a/Allura/allura/model/repository.py | |
+++ b/Allura/allura/model/repository.py | |
@@ -326,7 +326,7 @@ def get_changes(self, commit_id): | |
""" | |
raise NotImplementedError('get_changes') | |
- def paged_diffs(self, commit_id, start=0, end=None): | |
+ def paged_diffs(self, commit_id, start=0, end=None, onlyChangedFiles=False): | |
""" | |
Returns files touched by the commit, grouped by status (added, removed, | |
and changed) and the total number of such files. Paginates according | |
@@ -512,8 +512,8 @@ def head(self): | |
def set_default_branch(self, name): | |
return self._impl.set_default_branch(name) | |
- def paged_diffs(self, commit_id, start=0, end=None): | |
- return self._impl.paged_diffs(commit_id, start, end) | |
+ 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) | |
@@ -1168,8 +1168,8 @@ def context(self): | |
def diffs(self): | |
return self.paged_diffs() | |
- def paged_diffs(self, start=0, end=None): | |
- diffs = self.repo.paged_diffs(self._id, start, end) | |
+ def paged_diffs(self, start=0, end=None, onlyChangedFiles=False): | |
+ diffs = self.repo.paged_diffs(self._id, start, end, onlyChangedFiles) | |
return Object( | |
added=sorted(diffs['added']), | |
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py | |
index f74854a..82fa508 100644 | |
--- a/ForgeGit/forgegit/model/git_repo.py | |
+++ b/ForgeGit/forgegit/model/git_repo.py | |
@@ -650,7 +650,7 @@ def get_changes(self, commit_id): | |
pretty='format:', | |
max_count=1).splitlines()[1:] | |
- def paged_diffs(self, commit_id, start=0, end=None): | |
+ def paged_diffs(self, commit_id, start=0, end=None, onlyChangedFiles=False): | |
result = {'added': [], 'removed': [], 'changed': [], 'copied': [], 'renamed': []} | |
cmd_args = ['--no-commit-id', | |
'--name-status', | |
@@ -660,6 +660,8 @@ def paged_diffs(self, commit_id, start=0, end=None): | |
'-t', | |
'-z' # don't escape filenames and use \x00 as fields delimiter | |
] | |
+ if onlyChangedFiles: | |
+ cmd_args[4] = '-r' | |
if asbool(tg.config.get('scm.commit.git.detect_copies', True)): | |
cmd_args += ['-M', '-C'] | |
+e0d7765883017040d53f9ca9c528940a4dd311c6 | |
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py | |
index 6d05094..8e09047 100644 | |
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py | |
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py | |
@@ -75,6 +75,35 @@ def setup_testgit_index_repo(self): | |
ThreadLocalORMSession.flush_all() | |
+class TestUIController(TestController): | |
+ def setUp(self): | |
+ super(TestUIController, self).setUp() | |
+ self.setup_with_tools() | |
+ | |
+ @with_git | |
+ def setup_with_tools(self): | |
+ h.set_context('test', 'src-git', neighborhood='Projects') | |
+ repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') | |
+ c.app.repo.fs_path = repo_dir | |
+ c.app.repo.name = 'testui2.git' | |
+ c.app.repo.status = 'ready' | |
+ self.repo = c.app.repo | |
+ self.repo.refresh() | |
+ self.rev = self.repo.commit('HEAD') | |
+ ThreadLocalORMSession.flush_all() | |
+ ThreadLocalORMSession.close_all() | |
+ | |
+ def test_repo_loading(self): | |
+ resp = self.app.get('/src-git/').follow().follow() | |
+ assert '<a href="/p/test/src-git/ci/e0d7765883017040d53f9ca9c528940a4dd311c6/">' in resp | |
+ | |
+ def test_status_html(self): | |
+ resp = self.app.get('/src-git/ci/e0d7765883017040d53f9ca9c528940a4dd311c6/') | |
+ sortedCommits = resp.html.findAll('td') | |
+ actualCommit = ['added', 'aaa.txt', 'removed', 'bbb.txt', 'changed', 'ccc.txt', 'removed', 'ddd.txt', 'added', 'eee.txt', 'added', 'ggg.txt'] | |
+ for i, item in enumerate(sortedCommits): | |
+ assert_equal(actualCommit[i], ''.join(item.findAll(text=True)).strip()) | |
+ | |
class TestRootController(_TestCase): | |
@with_tool('test', 'Git', 'weird-chars', 'WeirdChars', type='git') | |
def _setup_weird_chars_repo(self): | |
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py | |
index 7c15bae..c281603 100644 | |
--- a/ForgeGit/forgegit/tests/model/test_repository.py | |
+++ b/ForgeGit/forgegit/tests/model/test_repository.py | |
@@ -681,11 +681,11 @@ def test_paged_diffs(self): | |
# spaces and unicode filenames | |
diffs = repo.paged_diffs('407950e8fba4dbc108ffbce0128ed1085c52cfd7') | |
expected = { | |
- 'added': [u'with space.txt', u'привіт.txt'], | |
'removed': [], | |
'changed': [], | |
- 'copied': [], | |
'renamed': [], | |
+ 'added': [u'with space.txt', u'привіт.txt'], | |
+ 'copied': [], | |
'total': 2, | |
} | |
assert_equals(diffs, expected) | |
##################################################################################################### | |
Some more code submitted by me - This file was completely for a new test module. | |
+ # Licensed to the Apache Software Foundation (ASF) under one | |
+ # or more contributor license agreements. See the NOTICE file | |
+ # distributed with this work for additional information | |
+ # regarding copyright ownership. The ASF licenses this file | |
+ # to you under the Apache License, Version 2.0 (the | |
+ # "License"); you may not use this file except in compliance | |
+ # with the License. You may obtain a copy of the License at | |
+ # | |
+ # http://www.apache.org/licenses/LICENSE-2.0 | |
+ # | |
+ # Unless required by applicable law or agreed to in writing, | |
+ # software distributed under the License is distributed on an | |
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
+ # KIND, either express or implied. See the License for the | |
+ # specific language governing permissions and limitations | |
+ # under the License. | |
+ | |
+ | |
+ import datetime | |
+ | |
+ from nose.tools import assert_equal, assert_in | |
+ from ming.orm.ormsession import ThreadLocalORMSession | |
+ from alluratest.controller import TestController | |
+ from allura import model as M | |
+ | |
+ | |
+ class TestFeeds(TestController): | |
+ | |
+ def _post(self, slug='', **kw): | |
+ d = { | |
+ 'title': 'My Post', | |
+ 'text': 'Nothing to see here', | |
+ 'labels': '', | |
+ 'state': 'published'} | |
+ d.update(kw) | |
+ r = self.app.post('/blog%s/save' % slug, params=d) | |
+ return r | |
+ | |
+ def _update(self, url='', delete=False, **kw): | |
+ if delete: | |
+ d = { | |
+ 'delete':'Delete' | |
+ } | |
+ else: | |
+ d = { | |
+ 'title': 'My Post', | |
+ 'text': 'Nothing to see here', | |
+ 'labels': '', | |
+ 'state': 'published'} | |
+ d.update(kw) | |
+ r = self.app.post('/blog/' + str(self._blog_date()) + "/" + url + "/save", params = d) | |
+ return r | |
+ | |
+ def _blog_date(self): | |
+ return datetime.datetime.utcnow().strftime('%Y/%m') | |
+ | |
+ def test_feeds(self): | |
+ self.app.get('/blog/feed.rss') | |
+ self.app.get('/blog/feed.atom') | |
+ | |
+ def test_rss_feed_contains_self_link(self): | |
+ r = self.app.get('/blog/feed.rss') | |
+ # atom namespace included | |
+ assert_in('<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">', r) | |
+ # ...and atom:link points to feed url | |
+ assert_in('<atom:link href="http://localhost/blog/feed.rss" ' | |
+ 'type="application/rss+xml" rel="self"></atom:link>', r) | |
+ | |
+ def test_post_feeds(self): | |
+ self._post() | |
+ d = self._blog_date() | |
+ response = self.app.get('/blog/%s/my-post/feed.rss' % d) | |
+ assert 'Nothing to see' in response | |
+ response = self.app.get('/blog/%s/my-post/feed.atom' % d) | |
+ assert 'Nothing to see' in response | |
+ self._post(title='test', text='*sometext*') | |
+ response = self.app.get('/blog/feed') | |
+ assert '<div class="markdown_content"><p><em>sometext</em></p></div>' in response | |
+ | |
+ def test_related_artifacts(self): | |
+ self._post(title='one') | |
+ M.MonQTask.run_ready() | |
+ d = self._blog_date() | |
+ self._post(title='two', text='[blog:%s/one]' % d) | |
+ M.MonQTask.run_ready() | |
+ ThreadLocalORMSession.flush_all() | |
+ r = self.app.get('/blog/%s/one/' % d) | |
+ assert 'Related' in r | |
+ assert 'Blog: %s/two' % d in r | |
+ | |
+ def test_feed_update(self): | |
+ # Post a feed. | |
+ d = self._blog_date() | |
+ self._post(title="Hello World") | |
+ response = self.app.get('/blog/%s/hello-world/feed.rss' % d) | |
+ assert "Nothing to see here" in response | |
+ # Update it with different data. | |
+ r = self._update(url='hello-world', text="Everything is here") | |
+ # Check if the feed changed. | |
+ response = self.app.get('/blog/%s/hello-world/feed.rss' % d) | |
+ assert "Everything is here" in response | |
+ assert not "Nothing to see here" in response | |
+ # Change the status to draft. | |
+ response = self.app.get('/blog/') | |
+ assert "Everything is here" in response | |
+ r = self._update(url='hello-world', status="draft") | |
+ response = self.app.get('/blog/') | |
+ assert not "Everything is here" in response | |
+ | |
+ def test_post_delete_feed_delete(self): | |
+ # Post a blogpost. | |
+ self._post(title="Deletion Post") | |
+ d = self._blog_date() | |
+ url = '/blog/' + self._blog_date() + "/deletion-post/" | |
+ # Check that post exists. | |
+ response = self.app.get("/blog/") | |
+ assert '/blog/%s/deletion-post/edit' % d in response | |
+ response = self.app.get("/blog/feed.rss") | |
+ assert url in response | |
+ # Delete the post. | |
+ self._update(url="deletion-post", delete=True) | |
+ # Check feed is deleted. | |
+ response = self.app.get("/blog/") | |
+ assert not '/blog/%s/deletion-post/edit' % d in response | |
+ response = self.app.get("/blog/feed.rss") | |
+ assert not url in response | |
############################################################################################## | |
One more test file - | |
+ def test_toolaccess_before_subproject(self): | |
+ self.app.extra_environ = {'username': 'test-admin'} | |
+ # Add the subproject with a wiki. | |
+ self.app.post('/p/test/admin/update_mounts', params={ | |
+ 'new.install': 'install', | |
+ 'new.ep_name': '', | |
+ 'new.ordinal': '1', | |
+ 'new.mount_point': 'test-mount', | |
+ 'new.mount_label': 'Test Mount'}) | |
+ r = self.app.get('/p/test/test-mount/') | |
+ assert r.location.endswith('admin/'), r.location | |
+ | |
+ pr = M.Project.query.get(shortname='test/test-mount') | |
+ assert pr != None | |
+ c.user = M.User.query.get(username='test-admin') | |
+ | |
+ # Install and Verify a Tool in the subproject. | |
+ pr.install_app(ep_name='Wiki', mount_point='test-sub', mount_label='Test Sub', ordinal='1') | |
+ r = self.app.get('/p/test/test-mount/test-sub/').follow() | |
+ active_link = r.html.findAll('li', {'class': 'selected'}) | |
+ assert_equal(len(active_link), 1) | |
+ assert active_link[0].contents[1]['href'] == '/p/test/test-mount/test-sub/' | |
+ assert 'Welcome to your wiki!' in r | |
+ | |
+ # Delete the Subproject. | |
+ self.app.post('/p/test/admin/update_mounts', params={ | |
+ 'subproject-0.delete': 'on', | |
+ 'subproject-0.shortname': 'test/test-mount', | |
+ 'new.ep_name': '', | |
+ }) | |
+ | |
+ # Try to access the installed tool as anon. | |
+ r = self.app.get('/p/test/test-mount/test-sub/', | |
+ extra_environ = dict(username='*anonymous'), | |
+ status=404) | |
+ assert (r.status_int == 403 or r.status_int == 404) | |
+ | |
+ # Try to access the installed tool as Admin. | |
+ r = self.app.get('/p/test/test-mount/test-sub/').follow() | |
+ assert 'Wiki' in r | |
+ | |
+ # Install a new tool with same mount point in parent project. Here a Wiki is installed. | |
+ p = M.Project.query.get(shortname='test') | |
+ p.install_app(ep_name='Wiki', mount_point='test-mount', mount_label='Test Sub', ordinal='1') | |
+ | |
+ # Check if the tool is accessed and not the subproject. | |
+ r = self.app.get('/p/test/test-mount/').follow() | |
+ active_link = r.html.findAll('li', {'class': 'selected'}) | |
+ assert_equal(len(active_link), 1) | |
+ assert active_link[0].contents[1]['href'] == '/p/test/test-mount/' | |
+ assert 'Welcome to your wiki!' in r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment