You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/14 19:07:02 UTC
git commit: [#6393] Load macros from external packages
Updated Branches:
refs/heads/tv/6393 [created] e24da582f
[#6393] Load macros from external packages
* Moved download_button macro out of allura
* Fixed/cleaned up tests that rely on pylons globals
Signed-off-by: Tim Van Steenburgh <tv...@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/e24da582
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/e24da582
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/e24da582
Branch: refs/heads/tv/6393
Commit: e24da582f01505f53286f3f02a132a2cd68dbd11
Parents: f824160
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Jan 14 18:06:46 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Jan 14 18:06:46 2014 +0000
----------------------------------------------------------------------
Allura/allura/lib/app_globals.py | 1 +
Allura/allura/lib/macro.py | 20 ------------
Allura/allura/lib/widgets/macros.py | 11 -------
.../templates/widgets/download_button.html | 19 ------------
Allura/allura/tests/model/test_openid.py | 9 ++----
Allura/allura/tests/test_app.py | 7 ++---
Allura/allura/tests/test_globals.py | 32 +++++++++-----------
Allura/allura/tests/test_utils.py | 1 -
AlluraTest/alluratest/controller.py | 5 +--
9 files changed, 24 insertions(+), 81 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 8bc929e..9917dd4 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -254,6 +254,7 @@ class Globals(object):
stats=_cache_eps('allura.stats'),
site_stats=_cache_eps('allura.site_stats'),
admin=_cache_eps('allura.admin'),
+ macros=_cache_eps('allura.macros'),
)
# Zarkov logger
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index d22b431..957fcb8 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -318,26 +318,6 @@ def gittip_button(username):
response = button.display(username=username)
return response
-# FIXME: this is SourceForge specific - need to provide a way for macros
-# to come from other packages
-
-
-@macro()
-def download_button():
- from allura.lib.widgets.macros import DownloadButton
- button = DownloadButton(project=c.project)
- try:
- res_mgr = g.resource_manager
- except TypeError:
- # e.g. "TypeError: No object (name: widget_context) has been registered for this thread"
- # this is an ugly way to check to see if we're outside of a web request
- # and avoid errors
- return '[[download_button]]'
- else:
- res_mgr.register(button)
- response = button.display(project=c.project)
- return response
-
@macro()
def include(ref=None, **kw):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/lib/widgets/macros.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/macros.py b/Allura/allura/lib/widgets/macros.py
index 18268cb..77c329a 100644
--- a/Allura/allura/lib/widgets/macros.py
+++ b/Allura/allura/lib/widgets/macros.py
@@ -33,17 +33,6 @@ class GittipButton(ew.Widget):
project = None
-class DownloadButton(ew.Widget):
- template = 'jinja:allura:templates/widgets/download_button.html'
- params = ['project']
- project = None
-
- def resources(self):
- yield ew.jinja2_ew.JSScript('''
- $(function(){$(".download-button-%s").load("%s");
- });''' % (self.project._id, self.project.best_download_url()))
-
-
class NeighborhoodFeeds(ew.Widget):
template = 'jinja:allura:templates/macro/neighborhood_feeds.html'
params = ['feeds']
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/templates/widgets/download_button.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/download_button.html b/Allura/allura/templates/widgets/download_button.html
deleted file mode 100644
index 44e3b36..0000000
--- a/Allura/allura/templates/widgets/download_button.html
+++ /dev/null
@@ -1,19 +0,0 @@
-{#-
- 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.
--#}
-<p><span class="download-button-{{project._id}}" style="margin-bottom: 1em; display: block;"></span></p>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/tests/model/test_openid.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_openid.py b/Allura/allura/tests/model/test_openid.py
index 056f030..30dcdb4 100644
--- a/Allura/allura/tests/model/test_openid.py
+++ b/Allura/allura/tests/model/test_openid.py
@@ -23,22 +23,17 @@ Model tests for openid_model
import time
import mock
-from pylons import tmpl_context as c, app_globals as g
-from pylons import request
-from webob import Request
from openid.association import Association
from ming.orm.ormsession import ThreadLocalORMSession
-from allura.lib.app_globals import Globals
+from alluratest.controller import setup_unit_test
from allura import model as M
from allura.lib import helpers as h
def setUp():
- g._push_object(Globals())
- c._push_object(mock.Mock())
- request._push_object(Request.blank('/'))
+ setup_unit_test()
ThreadLocalORMSession.close_all()
M.EmailAddress.query.remove({})
M.OpenIdNonce.query.remove({})
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/tests/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index f5f5ac4..a31f112 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -15,17 +15,16 @@
# specific language governing permissions and limitations
# under the License.
-from pylons import tmpl_context as c, app_globals as g
+from pylons import tmpl_context as c
import mock
from ming.base import Object
+from alluratest.controller import setup_unit_test
from allura import app
-from allura.lib.app_globals import Globals
def setUp():
- g._push_object(Globals())
- c._push_object(mock.Mock())
+ setup_unit_test()
c.user._id = None
c.project = mock.Mock()
c.project.name = 'Test Project'
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index ea7313d..f3adc87 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -26,12 +26,15 @@ import hashlib
from mock import patch
from bson import ObjectId
-
from nose.tools import with_setup, assert_equal, assert_in
from pylons import tmpl_context as c, app_globals as g
from ming.orm import ThreadLocalORMSession
-from alluratest.controller import setup_basic_test, setup_global_objects
+from alluratest.controller import (
+ setup_basic_test,
+ setup_global_objects,
+ setup_unit_test,
+ )
from allura import model as M
from allura.lib import helpers as h
@@ -45,9 +48,14 @@ from forgeblog import model as BM
def setUp():
"""Method called by nose once before running the package. Some functions need it run again to reset data"""
setup_basic_test()
+ setup_unit_test()
setup_with_tools()
+def tearDown():
+ setUp()
+
+
@td.with_wiki
def setup_with_tools():
setup_global_objects()
@@ -65,7 +73,7 @@ def test_app_globals():
assert g.url('/foo') == 'http://localhost/foo', g.url('/foo')
-@with_setup(teardown=setUp) # reset everything we changed
+@with_setup(setUp)
def test_macro_projects():
file_name = 'neo-icon-set-454545-256x350.png'
file_path = os.path.join(
@@ -152,16 +160,6 @@ def test_macro_projects():
assert '<img alt="Test Project Logo"' not in r
-def test_macro_download_button():
- p_nbhd = M.Neighborhood.query.get(name='Projects')
- p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
- with h.push_config(c, project=p_test):
- r = g.markdown_wiki.convert('[[download_button]]')
- assert_equal(
- r, '<div class="markdown_content"><p><span class="download-button-%s" style="margin-bottom: 1em; display: block;"></span></p>\n</div>' %
- p_test._id)
-
-
def test_macro_gittip_button():
p_nbhd = M.Neighborhood.query.get(name='Projects')
p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
@@ -203,7 +201,7 @@ def test_macro_neighborhood_feeds():
assert 'test content' in r
-@with_setup(setUp, setUp) # start clean and reset everything we change
+@with_setup(setUp)
def test_macro_members():
p_nbhd = M.Neighborhood.query.get(name='Projects')
p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
@@ -219,7 +217,7 @@ def test_macro_members():
'</div>')
-@with_setup(teardown=setUp) # reset everything we changed
+@with_setup(setUp)
def test_macro_members_escaping():
user = M.User.by_username('test-admin')
user.display_name = u'Test Admin <script>'
@@ -230,7 +228,7 @@ def test_macro_members_escaping():
u'</ul>\n</div>')
-@with_setup(teardown=setUp) # reset everything we changed
+@with_setup(setUp)
def test_macro_project_admins():
user = M.User.by_username('test-admin')
user.display_name = u'Test Ã…dmin <script>'
@@ -240,7 +238,7 @@ def test_macro_project_admins():
r, u'<div class="markdown_content"><h6>Project Admins:</h6>\n<ul class="md-users-list">\n<li><a href="/u/test-admin/">Test \xc5dmin <script></a></li>\n</ul>\n</div>')
-@with_setup(teardown=setUp) # reset everything we changed
+@with_setup(setUp)
def test_macro_project_admins_one_br():
p_nbhd = M.Neighborhood.query.get(name='Projects')
p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 232763a..92f1e28 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -96,7 +96,6 @@ class TestAntispam(unittest.TestCase):
def setUp(self):
setup_unit_test()
- pylons.request._push_object(Request.blank('/'))
pylons.request.remote_addr = '127.0.0.1'
self.a = utils.AntiSpam()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e24da582/AlluraTest/alluratest/controller.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/controller.py b/AlluraTest/alluratest/controller.py
index 8386d0b..dcd7c53 100644
--- a/AlluraTest/alluratest/controller.py
+++ b/AlluraTest/alluratest/controller.py
@@ -26,9 +26,9 @@ from paste.deploy import loadapp
from paste.deploy.converters import asbool
from paste.script.appinstall import SetupCommand
from pylons import tmpl_context as c, app_globals as g
-from pylons import url, response, session
+from pylons import url, request, response, session
import tg
-from webob import Response
+from webob import Response, Request
import ew
from ming.orm import ThreadLocalORMSession
import ming.orm
@@ -101,6 +101,7 @@ def setup_unit_test():
REGISTRY.register(g, Globals())
REGISTRY.register(c, mock.Mock())
REGISTRY.register(url, lambda: None)
+ REGISTRY.register(request, Request.blank('/'))
REGISTRY.register(response, Response())
REGISTRY.register(session, beaker.session.SessionObject({}))
REGISTRY.register(allura.credentials, allura.lib.security.Credentials())