incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#7029] Fixed test interaction issue on auth page extensions test
Date Fri, 28 Feb 2014 19:05:04 GMT
Repository: incubator-allura
Updated Branches:
  refs/heads/cj/7029 [created] 44751e6c3


[#7029] Fixed test interaction issue on auth page extensions test

Had to move the lookup to runtime, because the AuthController was being
instantiated in another test and stored on a BasetestProjectRootController
instance that was difficult to get at to modify for the test.

Also refactored the additional_urls method to return a mapping, because
that makes more sense.  The order wasn't being preserved, anyway.

Signed-off-by: Cory Johns <cjohns@slashdotmedia.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/44751e6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/44751e6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/44751e6c

Branch: refs/heads/cj/7029
Commit: 44751e6c3c13e066346031f0bfd6a9bc532e7514
Parents: 3901f4f
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Feb 28 19:01:34 2014 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Feb 28 19:01:36 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py                  |  7 +++++--
 Allura/allura/controllers/basetest_project_root.py |  5 ++++-
 Allura/allura/lib/plugin.py                        | 12 +++++++-----
 Allura/allura/tests/functional/test_auth.py        |  2 +-
 Allura/allura/tests/unit/controllers/test_auth.py  |  4 ++--
 5 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44751e6c/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 24a989a..47857f4 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -76,9 +76,12 @@ class AuthController(BaseController):
         self.user_info = UserInfoController()
         self.subscriptions = SubscriptionsController()
         self.oauth = OAuthController()
+
+    def __getattr__(self, name):
         urls = plugin.UserPreferencesProvider.get().additional_urls()
-        for u, method in urls:
-            setattr(self, u, method)
+        if name not in urls:
+            raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__,
name))
+        return urls[name]
 
     @expose()
     def prefs(self, *args, **kwargs):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44751e6c/Allura/allura/controllers/basetest_project_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index d1ca3f7..3edb34f 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -109,7 +109,10 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
             ep_name = name
             if name.startswith('test-app-'):
                 ep_name = name[len(prefix):]
-            c.project.install_app(ep_name, name)
+            try:
+                c.project.install_app(ep_name, name)
+            except KeyError:
+                raise exc.HTTPNotFound, name
             app = c.project.app_instance(name)
             if app is None:
                 raise exc.HTTPNotFound, name

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44751e6c/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index d61f35f..7aea613 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -985,7 +985,7 @@ class UserPreferencesProvider(object):
 
     def additional_urls(self):
         '''
-        Returns list of additional routes for AuthProvider.
+        Returns a mapping of additional routes for AuthProvider.
 
         By default, scans the provider for @expose()ed methods, which are
         added as pages with the same name as the method.  Note that if you
@@ -994,22 +994,24 @@ class UserPreferencesProvider(object):
         `AuthenticationProvider.account_navigation`.
 
         If you want to override this behavior, you can override this method
-        and manually return a list of (page_name, handler) tuple pairs.  Note,
+        and manually return a mapping of `{page_name: handler, ...}`.  Note,
         however, that this could break future subclasses of your providers'
         ability to extend the list.
 
-        For example: `[('newroute', newroute_handler)]` will add 'newroute'
+        For example: `{'newroute', newroute_handler}` will add 'newroute'
         attribute to the auth controller, which will be set to `newroute_handler`.
+        `newroute_handler` can either be an @expose()ed method, or a controller
+        that can dispatch further sub-pages.
 
         `newroute_handler` must be decorated with @expose(), but does not have
         to live on the provider.
         '''
-        urls = []
+        urls = {}
         for attr_name in dir(self):
             attr_value = getattr(self, attr_name)
             decoration = getattr(attr_value, 'decoration', None)
             if getattr(decoration, 'exposed', False):
-                urls.append((attr_name, attr_value))
+                urls[attr_name] = attr_value
         return urls
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44751e6c/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 8e36f5e..3c0197a 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -604,12 +604,12 @@ class TestPreferences(TestController):
         assert not M.User.query.get(
             username='test-admin').get_pref('disable_user_messages')
 
-
     @td.with_user_project('test-admin')
     def test_additional_page(self):
         class MyPP(plugin.UserPreferencesProvider):
             def not_page(self):
                 return 'not page'
+
             @expose()
             def new_page(self):
                 return 'new page'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44751e6c/Allura/allura/tests/unit/controllers/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/controllers/test_auth.py b/Allura/allura/tests/unit/controllers/test_auth.py
index c35c708..8fb8e46 100644
--- a/Allura/allura/tests/unit/controllers/test_auth.py
+++ b/Allura/allura/tests/unit/controllers/test_auth.py
@@ -26,6 +26,6 @@ def test_auth_additional(additional_urls):
     def test_function():
         return 'test'
 
-    additional_urls.return_value = [['test', test_function], ]
+    additional_urls.return_value = {'test': test_function}
     auth = AuthController()
-    assert auth.test()== 'test'
\ No newline at end of file
+    assert auth.test() == 'test'


Mime
View raw message