allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/6] git commit: [#7168] ticket:561 Tests and small amendments
Date Fri, 04 Apr 2014 19:57:30 GMT
Repository: allura
Updated Branches:
  refs/heads/master 323c00dab -> b227c3f36


[#7168] ticket:561 Tests and small amendments


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/cda6608a
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/cda6608a
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/cda6608a

Branch: refs/heads/master
Commit: cda6608a3d45a4a275e38569258e5c171cc3ecee
Parents: cd345b0
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Mar 25 15:01:05 2014 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Apr 4 19:51:23 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/macro.py                      |  6 ++-
 .../tests/functional/test_controllers.py        | 47 +++++++++++++++++++-
 2 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/cda6608a/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index ba9a04d..575be89 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -322,12 +322,14 @@ def gittip_button(username):
 
 
 def parse_repo(repo):
+    if not repo:
+        return None
     from allura import model as M
     parts = repo.split(':')
-    project, app = c.project, c.app
+    project, app = c.project, None
     if len(parts) == 2:
         project = M.Project.query.get(shortname=parts[0])
-        app = project.app_instance(parts[1])
+        app = project.app_instance(parts[1]) if project else None
     elif len(parts) == 1:
         app = project.app_instance(parts[0]) if project else None
     return app

http://git-wip-us.apache.org/repos/asf/allura/blob/cda6608a/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index aaae6f3..7c61687 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -22,14 +22,17 @@ import shutil
 import tempfile
 
 from datadiff.tools import assert_equal as dd_assert_equal
-from nose.tools import assert_equal, assert_in, assert_not_in
+from nose.tools import assert_equal, assert_in, assert_not_in, assert_not_equal
 import tg
 import pkg_resources
 from pylons import tmpl_context as c
 from ming.orm import ThreadLocalORMSession
+from mock import patch, PropertyMock
 
+from alluratest.controller import setup_global_objects
 from allura import model as M
 from allura.lib import helpers as h
+from allura.lib import macro
 from alluratest.controller import TestController
 from allura.tests.decorators import with_tool
 from forgegit.tests import with_git
@@ -748,4 +751,44 @@ class TestGitBranch(TestController):
     def test_exotic_default_branch(self):
         r = self.app.get('/src-git/').follow().follow()
         assert '<span>README</span>' in r
-        assert_equal(c.app.repo.get_default_branch('master'), 'test')
\ No newline at end of file
+        assert_equal(c.app.repo.get_default_branch('master'), 'test')
+
+
+class TestIncludeMacro(_TestCase):
+
+    def setUp(self):
+        super(TestIncludeMacro, self).setUp()
+        setup_global_objects()
+
+    def test_parse_repo(self):
+        assert_equal(macro.parse_repo('app'), None)
+        assert_equal(macro.parse_repo('proj:app'), None)
+        assert_equal(macro.parse_repo('a:b:c:d:e:f'), None)
+        assert_not_equal(macro.parse_repo('src-git'), None)
+        assert_not_equal(macro.parse_repo('test:src-git'), None)
+
+    def test_include_file_no_repo(self):
+        expected = '[[include repo %s (not found)]]'
+        assert_equal(macro.include_file(None), expected % None)
+        assert_equal(macro.include_file('a:b'), expected % 'a:b')
+        assert_equal(macro.include_file('repo'), expected % 'repo')
+
+    def test_include_file_cant_find_file(self):
+        expected = "[[include can't find file %s in revision %s]]"
+        assert_equal(macro.include_file('src-git', 'a.txt'),
+                     expected % ('a.txt', '1e146e67985dcd71c74de79613719bef7bddca4a'))
+        assert_equal(macro.include_file('src-git', 'a.txt', '6a45885ae7347f1cac5103b0050cc1be6a1496c8'),
+                     expected % ('a.txt', '6a45885ae7347f1cac5103b0050cc1be6a1496c8'))
+
+    @patch('allura.model.repo.Blob.has_pypeline_view', new_callable=PropertyMock)
+    @patch('allura.model.repo.Blob.has_html_view', new_callable=PropertyMock)
+    def test_include_file_cant_display(self, has_html_view, has_pypeline_view):
+        has_html_view.return_value = False
+        has_pypeline_view.return_value = False
+        expected = "[[include can't display file README in revision 1e146e67985dcd71c74de79613719bef7bddca4a]]"
+        assert_equal(macro.include_file('src-git', 'README'), expected)
+
+    def test_include_file_display(self):
+        result = macro.include_file('src-git', 'README')
+        assert_in('This is readme', result)
+        assert_in('Another Line', result)


Mime
View raw message