allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [13/50] git commit: [#4718] remove unused /downloads/nav.json (which called sitemap())
Date Wed, 19 Sep 2012 18:43:27 GMT
[#4718] remove unused /downloads/nav.json (which called sitemap())


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

Branch: refs/heads/master
Commit: 8745481d741cdb2e27cd1c289b3967767410a455
Parents: 6cdc0f3
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Tue Sep 11 13:14:14 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Fri Sep 14 20:58:18 2012 +0000

----------------------------------------------------------------------
 ForgeDownloads/forgedownloads/dl_main.py           |   37 +++++++--------
 .../forgedownloads/tests/functional/test_root.py   |   24 ++++++----
 2 files changed, 33 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8745481d/ForgeDownloads/forgedownloads/dl_main.py
----------------------------------------------------------------------
diff --git a/ForgeDownloads/forgedownloads/dl_main.py b/ForgeDownloads/forgedownloads/dl_main.py
index 87b0f04..0219216 100644
--- a/ForgeDownloads/forgedownloads/dl_main.py
+++ b/ForgeDownloads/forgedownloads/dl_main.py
@@ -6,6 +6,7 @@ import pkg_resources
 from tg import expose, validate, response, config, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from pylons import g, c, request
+from webob import exc
 
 # Pyforge-specific imports
 from allura.app import Application, ConfigOption, SitemapEntry, DefaultAdminController
@@ -22,6 +23,14 @@ from forgedownloads import version
 log = logging.getLogger(__name__)
 
 
+def files_url(project):
+    unix_group_name = project.get_tool_data('sfx', 'unix_group_name')
+    if unix_group_name:
+        return '/projects/%s/files/' % unix_group_name
+    else:
+        return None
+
+
 class ForgeDownloadsApp(Application):
     __version__ = version.__version__
     permissions = [ 'configure', 'read' ]
@@ -47,8 +56,11 @@ class ForgeDownloadsApp(Application):
         :return: a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
         '''
         menu_id = self.config.options.mount_label.title()
-        url = '/projects/' + c.project.get_tool_data('sfx', 'unix_group_name') + '/files/'
-        return [SitemapEntry(menu_id, url)]
+        url = files_url(c.project)
+        if url:
+            return [SitemapEntry(menu_id, url)]
+        else:
+            return []
 
     @property
     @h.exceptionless([], log)
@@ -75,24 +87,11 @@ class ForgeDownloadsApp(Application):
 
 class RootController(BaseController):
 
-    def __init__(self):
-        setattr(self, 'nav.json', self.nav)
-
     @expose()
     @with_trailing_slash
     def index(self, **kw):
-        url='/projects/' + c.project.get_tool_data('sfx', 'unix_group_name') + '/files/'
-        permanent_redirect(url)
-
-    @expose('json:')
-    def nav(self):
-        if c.app.sitemap:
-            my_entry = c.app.sitemap[0]
+        url = files_url(c.project)
+        if url:
+            permanent_redirect(url)
         else:
-            my_entry = None
-        def _entry(s):
-            d = dict(name=s.label, url=s.url, icon=s.ui_icon)
-            if my_entry and s.url == my_entry.url:
-                d['selected'] = True
-            return d
-        return dict(menu=[ _entry(s) for s in c.project.sitemap() ] )
+            raise exc.HTTPNotFound

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8745481d/ForgeDownloads/forgedownloads/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeDownloads/forgedownloads/tests/functional/test_root.py b/ForgeDownloads/forgedownloads/tests/functional/test_root.py
index cb3d074..260913d 100644
--- a/ForgeDownloads/forgedownloads/tests/functional/test_root.py
+++ b/ForgeDownloads/forgedownloads/tests/functional/test_root.py
@@ -1,14 +1,20 @@
+from nose.tools import assert_equals
+from ming.orm import ThreadLocalORMSession
+
+from allura import model as M
 from alluratest.controller import TestController
-from allura.tests import decorators as td
+
 
 class TestRootController(TestController):
-    @td.with_wiki
-    def test_root(self):
-        response = self.app.get('/downloads/nav.json')
-        root = self.app.get('/p/test/wiki/').follow()
-        nav_links = root.html.find('div', dict(id='top_nav')).findAll('a')
-        assert len(nav_links) ==  len(response.json['menu'])
-        for nl, entry in zip(nav_links, response.json['menu']):
-            assert nl['href'] == entry['url']
 
+    def test_root_redirect(self):
+        p_nbhd = M.Neighborhood.query.get(name='Projects')
+        project = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+        project.set_tool_data('sfx', unix_group_name='foobar')
+        ThreadLocalORMSession.flush_all()
 
+        response = self.app.get('/downloads/', status=301)
+        assert_equals(response.location, 'http://localhost/projects/foobar/files/')
+
+    def test_root(self):
+        self.app.get('/downloads/', status=404)


Mime
View raw message