Adjusting tests to use hook_handle and hook_runall
This commit is contained in:
parent
eff722ef15
commit
d1146101bb
@ -178,9 +178,9 @@ def test_disabled_plugin():
|
|||||||
|
|
||||||
|
|
||||||
@with_cleanup()
|
@with_cleanup()
|
||||||
def test_callable_runone():
|
def test_hook_handle():
|
||||||
"""
|
"""
|
||||||
Test the callable_runone method
|
Test the hook_handle method
|
||||||
"""
|
"""
|
||||||
cfg = build_config([
|
cfg = build_config([
|
||||||
('mediagoblin', {}, []),
|
('mediagoblin', {}, []),
|
||||||
@ -198,41 +198,40 @@ def test_callable_runone():
|
|||||||
|
|
||||||
# Just one hook provided
|
# Just one hook provided
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runone(
|
assert pluginapi.hook_handle(
|
||||||
"just_one", call_log) == "Called just once"
|
"just_one", call_log) == "Called just once"
|
||||||
assert call_log == ["expect this one call"]
|
assert call_log == ["expect this one call"]
|
||||||
|
|
||||||
# Nothing provided and unhandled not okay
|
# Nothing provided and unhandled not okay
|
||||||
call_log = []
|
call_log = []
|
||||||
with pytest.raises(pluginapi.UnhandledCallable):
|
pluginapi.hook_handle(
|
||||||
pluginapi.callable_runone(
|
"nothing_handling", call_log) == None
|
||||||
"nothing_handling", call_log)
|
|
||||||
assert call_log == []
|
assert call_log == []
|
||||||
|
|
||||||
# Nothing provided and unhandled okay
|
# Nothing provided and unhandled okay
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runone(
|
assert pluginapi.hook_handle(
|
||||||
"nothing_handling", call_log, unhandled_okay=True) is None
|
"nothing_handling", call_log, unhandled_okay=True) is None
|
||||||
assert call_log == []
|
assert call_log == []
|
||||||
|
|
||||||
# Multiple provided, go with the first!
|
# Multiple provided, go with the first!
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runone(
|
assert pluginapi.hook_handle(
|
||||||
"multi_handle", call_log) == "the first returns"
|
"multi_handle", call_log) == "the first returns"
|
||||||
assert call_log == ["Hi, I'm the first"]
|
assert call_log == ["Hi, I'm the first"]
|
||||||
|
|
||||||
# Multiple provided, one has CantHandleIt
|
# Multiple provided, one has CantHandleIt
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runone(
|
assert pluginapi.hook_handle(
|
||||||
"multi_handle_with_canthandle",
|
"multi_handle_with_canthandle",
|
||||||
call_log) == "the second returns"
|
call_log) == "the second returns"
|
||||||
assert call_log == ["Hi, I'm the second"]
|
assert call_log == ["Hi, I'm the second"]
|
||||||
|
|
||||||
|
|
||||||
@with_cleanup()
|
@with_cleanup()
|
||||||
def test_callable_runall():
|
def test_hook_runall():
|
||||||
"""
|
"""
|
||||||
Test the callable_runall method
|
Test the hook_runall method
|
||||||
"""
|
"""
|
||||||
cfg = build_config([
|
cfg = build_config([
|
||||||
('mediagoblin', {}, []),
|
('mediagoblin', {}, []),
|
||||||
@ -250,19 +249,19 @@ def test_callable_runall():
|
|||||||
|
|
||||||
# Just one hook, check results
|
# Just one hook, check results
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runall(
|
assert pluginapi.hook_runall(
|
||||||
"just_one", call_log) == ["Called just once", None, None]
|
"just_one", call_log) == ["Called just once"]
|
||||||
assert call_log == ["expect this one call"]
|
assert call_log == ["expect this one call"]
|
||||||
|
|
||||||
# None provided, check results
|
# None provided, check results
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runall(
|
assert pluginapi.hook_runall(
|
||||||
"nothing_handling", call_log) == []
|
"nothing_handling", call_log) == []
|
||||||
assert call_log == []
|
assert call_log == []
|
||||||
|
|
||||||
# Multiple provided, check results
|
# Multiple provided, check results
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runall(
|
assert pluginapi.hook_runall(
|
||||||
"multi_handle", call_log) == [
|
"multi_handle", call_log) == [
|
||||||
"the first returns",
|
"the first returns",
|
||||||
"the second returns",
|
"the second returns",
|
||||||
@ -275,7 +274,7 @@ def test_callable_runall():
|
|||||||
|
|
||||||
# Multiple provided, one has CantHandleIt, check results
|
# Multiple provided, one has CantHandleIt, check results
|
||||||
call_log = []
|
call_log = []
|
||||||
assert pluginapi.callable_runall(
|
assert pluginapi.hook_runall(
|
||||||
"multi_handle_with_canthandle", call_log) == [
|
"multi_handle_with_canthandle", call_log) == [
|
||||||
"the second returns",
|
"the second returns",
|
||||||
"the third returns",
|
"the third returns",
|
||||||
@ -283,3 +282,5 @@ def test_callable_runall():
|
|||||||
assert call_log == [
|
assert call_log == [
|
||||||
"Hi, I'm the second",
|
"Hi, I'm the second",
|
||||||
"Hi, I'm the third"]
|
"Hi, I'm the third"]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user