Skip to content

Commit

Permalink
test_event: include test cases for new "replace" kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
masenf committed May 15, 2024
1 parent cbd1d6b commit b2bfec8
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,29 @@ def test_fn_with_args(_, arg1, arg2):
@pytest.mark.parametrize(
"input,output",
[
(("/path", None), 'Event("_redirect", {path:`/path`,external:false})'),
(("/path", True), 'Event("_redirect", {path:`/path`,external:true})'),
(("/path", False), 'Event("_redirect", {path:`/path`,external:false})'),
(
(Var.create_safe("path"), None),
'Event("_redirect", {path:path,external:false})',
("/path", None, None),
'Event("_redirect", {path:`/path`,external:false,replace:false})',
),
(
("/path", True, None),
'Event("_redirect", {path:`/path`,external:true,replace:false})',
),
(
("/path", False, None),
'Event("_redirect", {path:`/path`,external:false,replace:false})',
),
(
(Var.create_safe("path"), None, None),
'Event("_redirect", {path:path,external:false,replace:false})',
),
(
("/path", None, True),
'Event("_redirect", {path:`/path`,external:false,replace:true})',
),
(
("/path", True, True),
'Event("_redirect", {path:`/path`,external:true,replace:true})',
),
],
)
Expand All @@ -174,11 +191,13 @@ def test_event_redirect(input, output):
input: The input for running the test.
output: The expected output to validate the test.
"""
path, external = input
if external is None:
spec = event.redirect(path)
else:
spec = event.redirect(path, external=external)
path, external, replace = input
kwargs = {}
if external is not None:
kwargs["external"] = external
if replace is not None:
kwargs["replace"] = replace
spec = event.redirect(path, **kwargs)
assert isinstance(spec, EventSpec)
assert spec.handler.fn.__qualname__ == "_redirect"

Expand Down

0 comments on commit b2bfec8

Please sign in to comment.