You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/12/15 16:49:03 UTC
[10/12] allura git commit: [#8023] ticket:879 change
get_site_notification, fix tests
[#8023] ticket:879 change get_site_notification, fix tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/88e79c54
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/88e79c54
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/88e79c54
Branch: refs/heads/master
Commit: 88e79c5419514f83296071642cc53df938bc7277
Parents: 8bad4ee
Author: Denis Kotov <de...@gmail.com>
Authored: Fri Dec 11 16:57:34 2015 +0200
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Dec 15 10:05:57 2015 -0500
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 18 ++++++++----------
Allura/allura/tests/test_plugin.py | 26 +++++++++++++-------------
2 files changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/88e79c54/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 7768e2b..9247577 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -1316,18 +1316,16 @@ class ThemeProvider(object):
note = SiteNotification.current()
if note is None:
return None
- if note.user_role is not None and c.user.is_anonymous():
+ if note.user_role and c.user.is_anonymous():
return None
- if note.user_role is not None:
- projects = c.user.my_projects_by_role_name(note.user_role)
- if projects is not None:
- only_user_project = projects.count() == 1 and projects.first().is_user_project
- if projects.count() == 0 or only_user_project:
- return None
-
- if note.page_regex is not None and re.search(note.page_regex, request.url) is None:
+ if note.user_role:
+ projects = c.user.my_projects_by_role_name(note.user_role).all()
+ if len(projects) == 0 or len(projects) == 1 and projects[0].is_user_project:
+ return None
+
+ if note.page_regex and re.search(note.page_regex, request.path_qs) is None:
return None
- if note.page_tool_type is not None and (c.app is None or c.app.config.tool_name.lower() != note.page_tool_type.lower()):
+ if note.page_tool_type and (c.app is None or c.app.config.tool_name.lower() != note.page_tool_type.lower()):
return None
cookie = request.cookies.get('site-notification', '').split('-')
http://git-wip-us.apache.org/repos/asf/allura/blob/88e79c54/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 2e7baae..827ef73 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -400,23 +400,23 @@ class TestThemeProvider(object):
note.user_role = 'Test'
note.page_regex = None
note.page_tool_type = None
- projects = User.my_projects_by_role_name.return_value
+ projects = User.my_projects_by_role_name.return_value.all
User.is_anonymous.return_value = True
assert_is(ThemeProvider().get_site_notification(), None)
User.is_anonymous.return_value = False
- projects.count.return_value = 0
+ projects.return_value = []
assert_is(ThemeProvider().get_site_notification(), None)
- projects.count.return_value = 1
- projects.first.return_value.is_user_project = True
+ projects.return_value = [Mock()]
+ projects.return_value[0].is_user_project = True
assert_is(ThemeProvider().get_site_notification(), None)
- projects.first.return_value.is_user_project = False
+ projects.return_value[0].is_user_project = False
assert_is(ThemeProvider().get_site_notification(), note)
- projects.count.return_value = 2
+ projects.projects.return_value = [Mock(), Mock()]
assert_is(ThemeProvider().get_site_notification(), note)
@patch('allura.model.notification.SiteNotification')
@@ -458,33 +458,33 @@ class TestThemeProvider(object):
c.app = None
assert_is(ThemeProvider().get_site_notification(), None)
- @patch('re.search')
+ @patch('pylons.request')
@patch('allura.model.notification.SiteNotification')
- def test_get_site_notification_with_page_tool_type_page_regex(self, SiteNotification, search):
+ def test_get_site_notification_with_page_tool_type_page_regex(self, SiteNotification, request):
note = SiteNotification.current.return_value
note.user_role = None
note.page_regex = 'test'
c.app = Mock()
note.page_tool_type.lower.return_value = 'test1'
- search.return_value = None
+ request.path_qs = 'ttt'
c.app.config.tool_name.lower.return_value = 'test2'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = True
+ request.path_qs = 'test'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = None
+ request.path_qs = 'ttt'
c.app.config.tool_name.lower.return_value = 'test1'
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = True
+ request.path_qs = 'test'
assert_is(ThemeProvider().get_site_notification(), note)
c.app = None
assert_is(ThemeProvider().get_site_notification(), None)
- search.return_value = None
+ request.path_qs = 'ttt'
assert_is(ThemeProvider().get_site_notification(), None)