You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2021/07/20 10:35:07 UTC

[allura] branch dw/8392 created (now c3ab440)

This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a change to branch dw/8392
in repository https://gitbox.apache.org/repos/asf/allura.git.


      at c3ab440  [#8392] added 'subrender' jinja filter to render text snippets with current jinja context

This branch includes the following new commits:

     new 8f4340f  [#8392] TestThemeProvider_notifications's target ThemeProvider can be overridden by child classes
     new c3ab440  [#8392] added 'subrender' jinja filter to render text snippets with current jinja context

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[allura] 01/02: [#8392] TestThemeProvider_notifications's target ThemeProvider can be overridden by child classes

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch dw/8392
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 8f4340f7ffa7bea25e2d14fdbf27c08a2a6cd3cb
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Fri Jul 16 13:21:53 2021 +0000

    [#8392] TestThemeProvider_notifications's target ThemeProvider can be overridden by child classes
---
 Allura/allura/tests/test_plugin.py | 60 ++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 08a2a76..51f4345 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -311,13 +311,15 @@ class TestThemeProvider(object):
 
 class TestThemeProvider_notifications(object):
 
+    Provider = ThemeProvider
+
     @patch('allura.lib.plugin.c', MagicMock())
     @patch('allura.model.notification.SiteNotification')
     @patch('tg.response')
     @patch('tg.request')
     def test_get_site_notification_no_note(self, request, response, SiteNotification):
         SiteNotification.actives.return_value = []
-        assert_is_none(ThemeProvider().get_site_notification())
+        assert_is_none(self.Provider().get_site_notification())
         assert not response.set_cookie.called
 
     @patch('allura.lib.plugin.c', MagicMock())
@@ -332,7 +334,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         SiteNotification.actives.return_value = [note]
         request.cookies = {'site-notification': 'deadbeef-1-true'}
-        assert_is_none(ThemeProvider().get_site_notification())
+        assert_is_none(self.Provider().get_site_notification())
         assert not response.set_cookie.called
 
     @patch('allura.lib.plugin.c', MagicMock())
@@ -348,7 +350,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         SiteNotification.actives.return_value = [note]
         request.cookies = {'site-notification': 'deadbeef-3-false'}
-        assert_is_none(ThemeProvider().get_site_notification())
+        assert_is_none(self.Provider().get_site_notification())
         assert not response.set_cookie.called
 
     @patch('allura.lib.plugin.c', MagicMock())
@@ -366,7 +368,7 @@ class TestThemeProvider_notifications(object):
         request.cookies = {'site-notification': 'deadbeef-1-false'}
         request.environ['beaker.session'].secure = False
 
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
             'site-notification', 'deadbeef-2-False', max_age=dt.timedelta(days=365), secure=False)
 
@@ -383,7 +385,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         SiteNotification.actives.return_value = [note]
         request.cookies = {'site-notification': 'deadbeef-1000-false'}
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
     @patch('allura.lib.plugin.c', MagicMock())
     @patch('allura.model.notification.SiteNotification')
@@ -400,7 +402,7 @@ class TestThemeProvider_notifications(object):
         request.cookies = {'site-notification': '0ddba11-1000-true'}
         request.environ['beaker.session'].secure = False
 
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
             'site-notification', 'deadbeef-1-False', max_age=dt.timedelta(days=365), secure=False)
 
@@ -418,7 +420,7 @@ class TestThemeProvider_notifications(object):
         SiteNotification.actives.return_value = [note]
         request.cookies = {}
         request.environ['beaker.session'].secure = False
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
             'site-notification', 'deadbeef-1-False', max_age=dt.timedelta(days=365), secure=False)
 
@@ -437,7 +439,7 @@ class TestThemeProvider_notifications(object):
         request.cookies = {'site-notification': 'deadbeef-1000-true-bad'}
         request.environ['beaker.session'].secure = False
 
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
         response.set_cookie.assert_called_once_with(
             'site-notification', 'deadbeef-1-False', max_age=dt.timedelta(days=365), secure=False)
 
@@ -455,21 +457,21 @@ class TestThemeProvider_notifications(object):
         projects = c.user.my_projects_by_role_name
 
         c.user.is_anonymous.return_value = True
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         c.user.is_anonymous.return_value = False
         projects.return_value = []
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         projects.return_value = [Mock()]
         projects.return_value[0].is_user_project = True
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         projects.return_value[0].is_user_project = False
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
         projects.projects.return_value = [Mock(), Mock()]
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
     @patch('allura.lib.plugin.c', MagicMock())
     @patch('allura.model.notification.SiteNotification')
@@ -482,7 +484,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         note.impressions = 10
         SiteNotification.actives.return_value = [note]
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
     @patch('allura.lib.plugin.c', MagicMock())
     @patch('re.search')
@@ -498,10 +500,10 @@ class TestThemeProvider_notifications(object):
         SiteNotification.actives.return_value = [note]
 
         search.return_value = True
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
         search.return_value = None
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
     @patch('allura.lib.plugin.c')
     @patch('allura.model.notification.SiteNotification')
@@ -516,13 +518,13 @@ class TestThemeProvider_notifications(object):
         SiteNotification.actives.return_value = [note]
         c.app = Mock()
         c.app.config.tool_name.lower.return_value = 'test1'
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
         c.app.config.tool_name.lower.return_value = 'test2'
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         c.app = None
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
     @patch('allura.lib.plugin.c')
     @patch('tg.request')
@@ -539,23 +541,23 @@ class TestThemeProvider_notifications(object):
 
         request.path_qs = 'ttt'
         c.app.config.tool_name.lower.return_value = 'test2'
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         request.path_qs = 'test'
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         request.path_qs = 'ttt'
         c.app.config.tool_name.lower.return_value = 'test1'
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         request.path_qs = 'test'
-        assert_is(ThemeProvider().get_site_notification(), note)
+        assert_is(self.Provider().get_site_notification(), note)
 
         c.app = None
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
         request.path_qs = 'ttt'
-        assert_is(ThemeProvider().get_site_notification(), None)
+        assert_is(self.Provider().get_site_notification(), None)
 
     @patch('allura.model.notification.SiteNotification')
     def test_get__site_notification(self, SiteNotification):
@@ -566,7 +568,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         note.impressions = 10
         SiteNotification.actives.return_value = [note]
-        get_note = ThemeProvider()._get_site_notification()
+        get_note = self.Provider()._get_site_notification()
 
         assert isinstance(get_note, tuple)
         assert len(get_note) == 2
@@ -594,7 +596,7 @@ class TestThemeProvider_notifications(object):
         note3.page_tool_type = None
         note3.impressions = 10
         SiteNotification.actives.return_value = [note1, note2, note3]
-        get_note = ThemeProvider()._get_site_notification()
+        get_note = self.Provider()._get_site_notification()
 
         assert isinstance(get_note, tuple)
         assert len(get_note) == 2
@@ -602,7 +604,7 @@ class TestThemeProvider_notifications(object):
         assert_equal(get_note[1], 'test2-1-False')
 
         # and with a cookie set
-        get_note = ThemeProvider()._get_site_notification(
+        get_note = self.Provider()._get_site_notification(
             site_notification_cookie_value='test2-3-True_test3-0-False'
         )
 
@@ -620,7 +622,7 @@ class TestThemeProvider_notifications(object):
         note.page_tool_type = None
         note.impressions = 10
         SiteNotification.actives.return_value = [note]
-        get_note = ThemeProvider()._get_site_notification(
+        get_note = self.Provider()._get_site_notification(
             site_notification_cookie_value='testid-1-False'
         )
 

[allura] 02/02: [#8392] added 'subrender' jinja filter to render text snippets with current jinja context

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch dw/8392
in repository https://gitbox.apache.org/repos/asf/allura.git

commit c3ab440f95b54f8e488b27f40027caee4f9337a5
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Tue Jul 20 10:34:46 2021 +0000

    [#8392] added 'subrender' jinja filter to render text snippets with current jinja context
---
 Allura/allura/config/app_cfg.py                        | 1 +
 Allura/allura/lib/helpers.py                           | 6 ++++++
 Allura/allura/templates/jinja_master/theme_macros.html | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index 58f3a75..1df14fe 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -115,6 +115,7 @@ class AlluraJinjaRenderer(JinjaRenderer):
         jinja2_env.filters['datetimeformat'] = helpers.datetimeformat
         jinja2_env.filters['filter'] = lambda s, t=None: list(filter(t and jinja2_env.tests[t], s))
         jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter
+        jinja2_env.filters['subrender'] = helpers.subrender_jinja_filter
         jinja2_env.globals.update({'hasattr': hasattr})
         config['tg.app_globals'].jinja2_env = jinja2_env  # TG doesn't need this, but we use g.jinja2_env a lot
         return {'jinja': cls(jinja2_env)}
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index d70f83a..3e6f15d 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -23,6 +23,7 @@ import sys
 import os
 import os.path
 import difflib
+import jinja2
 
 import six.moves.urllib.request
 import six.moves.urllib.parse
@@ -797,6 +798,11 @@ def render_any_markup(name, txt, code_mode=False, linenumbers_style=TABLE):
                 txt = '<pre>%s</pre>' % txt
     return Markup(txt)
 
+@contextfilter
+def subrender_jinja_filter(context, value):
+    _template = context.eval_ctx.environment.from_string(value)
+    result = _template.render(**context)
+    return result
 
 def nl2br_jinja_filter(value):
     result = '<br>\n'.join(escape(line) for line in value.split('\n'))
diff --git a/Allura/allura/templates/jinja_master/theme_macros.html b/Allura/allura/templates/jinja_master/theme_macros.html
index 47b632d..a79f09e 100644
--- a/Allura/allura/templates/jinja_master/theme_macros.html
+++ b/Allura/allura/templates/jinja_master/theme_macros.html
@@ -174,7 +174,7 @@ http://stackoverflow.com/questions/26582731/redefining-imported-jinja-macros
     {% if note %}
         <div id="site-notification">
             <section class="site-message info" data-notification-id="{{note._id}}">
-                {{note.content|safe}}
+                {{ note.content|subrender|safe }}
                 <a href="" class="btn btn-close">Close</a>
             </section>
         </div>