From a0e7699a45582d475d293350bcd2ba10ec5a8c43 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 19 Apr 2013 16:28:41 -0500 Subject: [PATCH] Added new tests to test hook_transform() --- mediagoblin/tests/test_pluginapi.py | 21 +++++++++++++++++++ .../tests/testplugins/callables1/__init__.py | 8 ++++--- .../tests/testplugins/callables2/__init__.py | 3 +++ .../tests/testplugins/callables3/__init__.py | 3 +++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index dbc4b7c8..4bbb9de4 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -284,3 +284,24 @@ def test_hook_runall(): "Hi, I'm the third"] +@with_cleanup() +def test_hook_transform(): + """ + Test the hook_transform method + """ + cfg = build_config([ + ('mediagoblin', {}, []), + ('plugins', {}, [ + ('mediagoblin.tests.testplugins.callables1', {}, []), + ('mediagoblin.tests.testplugins.callables2', {}, []), + ('mediagoblin.tests.testplugins.callables3', {}, []), + ]) + ]) + + mg_globals.app_config = cfg['mediagoblin'] + mg_globals.global_config = cfg + + setup_plugins() + + assert pluginapi.hook_transform( + "expand_tuple", (-1, 0)) == (-1, 0, 1, 2, 3) diff --git a/mediagoblin/tests/testplugins/callables1/__init__.py b/mediagoblin/tests/testplugins/callables1/__init__.py index 9c278b49..260a2078 100644 --- a/mediagoblin/tests/testplugins/callables1/__init__.py +++ b/mediagoblin/tests/testplugins/callables1/__init__.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from mediagoblin.tools.pluginapi import CantHandleIt - def setup_plugin(): pass @@ -30,12 +28,16 @@ def multi_handle(call_log): return "the first returns" def multi_handle_with_canthandle(call_log): - raise CantHandleIt("I just can't accept this stupid method") + return None + +def expand_tuple(tuple): + return tuple + (1,) hooks = { 'setup': setup_plugin, 'just_one': just_one, 'multi_handle': multi_handle, 'multi_handle_with_canthandle': multi_handle_with_canthandle, + 'expand_tuple': expand_tuple, } diff --git a/mediagoblin/tests/testplugins/callables2/__init__.py b/mediagoblin/tests/testplugins/callables2/__init__.py index aaab5b21..9d5cf950 100644 --- a/mediagoblin/tests/testplugins/callables2/__init__.py +++ b/mediagoblin/tests/testplugins/callables2/__init__.py @@ -29,10 +29,13 @@ def multi_handle_with_canthandle(call_log): call_log.append("Hi, I'm the second") return "the second returns" +def expand_tuple(this_tuple): + return this_tuple + (2,) hooks = { 'setup': setup_plugin, 'just_one': just_one, 'multi_handle': multi_handle, 'multi_handle_with_canthandle': multi_handle_with_canthandle, + 'expand_tuple': expand_tuple, } diff --git a/mediagoblin/tests/testplugins/callables3/__init__.py b/mediagoblin/tests/testplugins/callables3/__init__.py index 8d0c9c25..04efc8fc 100644 --- a/mediagoblin/tests/testplugins/callables3/__init__.py +++ b/mediagoblin/tests/testplugins/callables3/__init__.py @@ -29,10 +29,13 @@ def multi_handle_with_canthandle(call_log): call_log.append("Hi, I'm the third") return "the third returns" +def expand_tuple(this_tuple): + return this_tuple + (3,) hooks = { 'setup': setup_plugin, 'just_one': just_one, 'multi_handle': multi_handle, 'multi_handle_with_canthandle': multi_handle_with_canthandle, + 'expand_tuple': expand_tuple, } -- 2.25.1