allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [08/12] allura git commit: [#8023] ticket:879 change get_site_notification, fix tests
Date Tue, 15 Dec 2015 14:24:40 GMT
[#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/697dccfc
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/697dccfc
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/697dccfc

Branch: refs/heads/ib/8023b
Commit: 697dccfc92a4095387243e9c2be9e1d5ce499b5a
Parents: 2149cfa
Author: Denis Kotov <deniskkotov@gmail.com>
Authored: Fri Dec 11 16:57:34 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Tue Dec 15 13:43:03 2015 +0200

----------------------------------------------------------------------
 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/697dccfc/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/697dccfc/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)
 
 


Mime
View raw message