incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/2] git commit: Fix bugs related to subclassed Apps
Date Thu, 23 Jan 2014 17:36:34 GMT
Fix bugs related to subclassed Apps

* Ensure an App's artifact class can be found even if it's in a different package
* Make static App assets 'inheritable'

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/master
Commit: 4030679bd1d1869c0d075e610e57f4c866292478
Parents: e276acf
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Jan 23 16:01:32 2014 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Jan 23 17:36:06 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py |  7 ++++---
 Allura/allura/lib/custom_middleware.py  | 14 +++++++-------
 Allura/allura/lib/helpers.py            |  8 ++++++--
 Allura/allura/tests/test_globals.py     |  2 ++
 Allura/allura/tests/test_helpers.py     |  8 ++++----
 5 files changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4030679b/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index e6e374c..e2680dd 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -144,11 +144,12 @@ class SiteAdminController(object):
                 project_id=project._id)
             return True
 
-        tool_package = h.get_tool_package(appconf.tool_name)
+        tool_packages = h.get_tool_packages(appconf.tool_name)
         classes = set()
         for depth, cls in dfs(M.Artifact, build_model_inheritance_graph()):
-            if cls.__module__.startswith(tool_package + '.'):
-                classes.add(cls)
+            for pkg in tool_packages:
+                if cls.__module__.startswith(pkg + '.'):
+                    classes.add(cls)
         for cls in classes:
             for artifact in cls.query.find({"app_config_id": appconf._id}):
                 if artifact.url() == urlparse(url).path:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4030679b/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 3f65e6c..2a07e58 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -69,13 +69,13 @@ class StaticFilesMiddleware(object):
         for prefix, ep in self.directories:
             if environ['PATH_INFO'].startswith(prefix):
                 filename = environ['PATH_INFO'][len(prefix):]
-                file_path = pkg_resources.resource_filename(
-                    ep.module_name, os.path.join(
-                        'nf',
-                        ep.name.lower(),
-                        filename))
-                return fileapp.FileApp(file_path, [
-                    ('Access-Control-Allow-Origin', '*')])
+                resource_path = os.path.join('nf', ep.name.lower(), filename)
+                resource_cls = ep.load().has_resource(resource_path)
+                if resource_cls:
+                    file_path = pkg_resources.resource_filename(
+                        resource_cls.__module__, resource_path)
+                    return fileapp.FileApp(file_path, [
+                        ('Access-Control-Allow-Origin', '*')])
         filename = environ['PATH_INFO'][len(self.script_name):]
         file_path = pkg_resources.resource_filename(
             'allura', os.path.join(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4030679b/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 18cdc53..72c8695 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -788,10 +788,14 @@ def log_if_changed(artifact, attr, new_val, message):
         setattr(artifact, attr, new_val)
 
 
-def get_tool_package(tool_name):
+def get_tool_packages(tool_name):
     "Return package for given tool (e.g. 'forgetracker' for 'tickets')"
+    from allura.app import Application
     app = g.entry_points['tool'].get(tool_name.lower())
-    return app.__module__.split('.')[0] if app else ''
+    if not app:
+        return []
+    classes = set(app.mro()) - {Application, object}
+    return [cls.__module__.split('.')[0] for cls in classes]
 
 
 def get_first(d, key):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4030679b/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index c8553a1..a546054 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -35,6 +35,7 @@ from alluratest.controller import (
         setup_basic_test,
         setup_global_objects,
         setup_unit_test,
+        setup_functional_test,
         )
 
 from allura import model as M
@@ -467,6 +468,7 @@ def test_sort_updated():
         assert updated_at == sorted(updated_at, reverse=True)
 
 
+@with_setup(setup_functional_test)
 def test_filtering():
     # set up for test
     from random import choice

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4030679b/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index d89df75..69f5a09 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -271,10 +271,10 @@ def test_log_if_changed():
     assert AuditLogMock.logs[0] == 'updated value'
 
 
-def test_get_tool_package():
-    assert h.get_tool_package('tickets') == 'forgetracker'
-    assert h.get_tool_package('Tickets') == 'forgetracker'
-    assert h.get_tool_package('wrong_tool') == ''
+def test_get_tool_packages():
+    assert h.get_tool_packages('tickets') == ['forgetracker']
+    assert h.get_tool_packages('Tickets') == ['forgetracker']
+    assert h.get_tool_packages('wrong_tool') == []
 
 
 def test_get_first():


Mime
View raw message