parametrize some tests (#3786)

This commit is contained in:
Paul Sanders 2020-10-11 22:16:17 -04:00 committed by GitHub
parent bdf7083cfd
commit 8c6baeedab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -895,9 +895,9 @@ class TestStreaming:
class TestSafeJoin: class TestSafeJoin:
def test_safe_join(self): @pytest.mark.parametrize(
# Valid combinations of *args and expected joined paths. "args, expected",
passing = ( (
(("a/b/c",), "a/b/c"), (("a/b/c",), "a/b/c"),
(("/", "a/", "b/", "c/"), "/a/b/c"), (("/", "a/", "b/", "c/"), "/a/b/c"),
(("a", "b", "c"), "a/b/c"), (("a", "b", "c"), "a/b/c"),
@ -912,14 +912,14 @@ class TestSafeJoin:
# Base directory is always considered safe # Base directory is always considered safe
(("../", "a/b/c"), "../a/b/c"), (("../", "a/b/c"), "../a/b/c"),
(("/..",), "/.."), (("/..",), "/.."),
) ),
)
def test_safe_join(self, args, expected):
assert flask.safe_join(*args) == expected
for args, expected in passing: @pytest.mark.parametrize(
assert flask.safe_join(*args) == expected "args",
(
def test_safe_join_exceptions(self):
# Should raise werkzeug.exceptions.NotFound on unsafe joins.
failing = (
# path.isabs and ``..'' checks # path.isabs and ``..'' checks
("/a", "b", "/c"), ("/a", "b", "/c"),
("/a", "../b/c"), ("/a", "../b/c"),
@ -928,11 +928,11 @@ class TestSafeJoin:
("/a", "b/../b/../../c"), ("/a", "b/../b/../../c"),
("/a", "b", "c/../.."), ("/a", "b", "c/../.."),
("/a", "b/../../c"), ("/a", "b/../../c"),
) ),
)
for args in failing: def test_safe_join_exceptions(self, args):
with pytest.raises(NotFound): with pytest.raises(NotFound):
print(flask.safe_join(*args)) print(flask.safe_join(*args))
class TestHelpers: class TestHelpers: