Added new tests to test hook_transform()

This commit is contained in:
Christopher Allan Webber 2013-04-19 16:28:41 -05:00
parent 234ddad607
commit a0e7699a45
4 changed files with 32 additions and 3 deletions

View File

@ -284,3 +284,24 @@ def test_hook_runall():
"Hi, I'm the third"] "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)

View File

@ -14,8 +14,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin.tools.pluginapi import CantHandleIt
def setup_plugin(): def setup_plugin():
pass pass
@ -30,12 +28,16 @@ def multi_handle(call_log):
return "the first returns" return "the first returns"
def multi_handle_with_canthandle(call_log): 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 = { hooks = {
'setup': setup_plugin, 'setup': setup_plugin,
'just_one': just_one, 'just_one': just_one,
'multi_handle': multi_handle, 'multi_handle': multi_handle,
'multi_handle_with_canthandle': multi_handle_with_canthandle, 'multi_handle_with_canthandle': multi_handle_with_canthandle,
'expand_tuple': expand_tuple,
} }

View File

@ -29,10 +29,13 @@ def multi_handle_with_canthandle(call_log):
call_log.append("Hi, I'm the second") call_log.append("Hi, I'm the second")
return "the second returns" return "the second returns"
def expand_tuple(this_tuple):
return this_tuple + (2,)
hooks = { hooks = {
'setup': setup_plugin, 'setup': setup_plugin,
'just_one': just_one, 'just_one': just_one,
'multi_handle': multi_handle, 'multi_handle': multi_handle,
'multi_handle_with_canthandle': multi_handle_with_canthandle, 'multi_handle_with_canthandle': multi_handle_with_canthandle,
'expand_tuple': expand_tuple,
} }

View File

@ -29,10 +29,13 @@ def multi_handle_with_canthandle(call_log):
call_log.append("Hi, I'm the third") call_log.append("Hi, I'm the third")
return "the third returns" return "the third returns"
def expand_tuple(this_tuple):
return this_tuple + (3,)
hooks = { hooks = {
'setup': setup_plugin, 'setup': setup_plugin,
'just_one': just_one, 'just_one': just_one,
'multi_handle': multi_handle, 'multi_handle': multi_handle,
'multi_handle_with_canthandle': multi_handle_with_canthandle, 'multi_handle_with_canthandle': multi_handle_with_canthandle,
'expand_tuple': expand_tuple,
} }