mirror of
https://github.com/simonw/dclient.git
synced 2026-09-28 04:44:28 +02:00
parent
055d6a6ffc
commit
8a205d81a3
6 changed files with 304 additions and 12 deletions
67
tests/test_utils.py
Normal file
67
tests/test_utils.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
from dclient.utils import token_for_url, url_matches_prefix
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url,prefix_url,expected",
|
||||
(
|
||||
("https://example.com/foo/bar", "https://example.com/foo", True),
|
||||
("https://example.com/foo/bar2", "https://example.com/foo/bar", False),
|
||||
("https://example.com/foo/bar/baz", "https://example.com/foo/bar", True),
|
||||
("https://example.com/foo/bar/baz", "https://example.com/foo", True),
|
||||
("https://example.com/foo.json", "https://example.com/foo", True),
|
||||
# different scheme
|
||||
(
|
||||
"http://example.com/foo/bar",
|
||||
"https://example.com/foo",
|
||||
False,
|
||||
),
|
||||
# different netloc
|
||||
(
|
||||
"https://example.org/foo/bar",
|
||||
"https://example.com/foo",
|
||||
False,
|
||||
),
|
||||
# exactly the same
|
||||
("https://example.com/foo", "https://example.com/foo", True),
|
||||
# trailing '/'
|
||||
(
|
||||
"https://example.com/foo/bar",
|
||||
"https://example.com/foo/bar/",
|
||||
False,
|
||||
),
|
||||
(
|
||||
"https://example.com/foo/bar/baz",
|
||||
"https://example.com/foo/bar/",
|
||||
True,
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_url_matches_prefix(url, prefix_url, expected):
|
||||
assert url_matches_prefix(url, prefix_url) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url,tokens,expected",
|
||||
(
|
||||
("https://foo.com/bar", {"https://foo.com": "foo"}, "foo"),
|
||||
("https://foo.com/bar", {"https://foo.com/baz": "baz"}, None),
|
||||
(
|
||||
"https://foo.com/bar",
|
||||
{"https://foo.com": "foo", "https://foo.com/bar": "bar"},
|
||||
"bar",
|
||||
),
|
||||
(
|
||||
"https://foo.com/bar/baz",
|
||||
{
|
||||
"https://foo.com": "foo",
|
||||
"https://foo.com/bar/baz": "baz",
|
||||
"https://foo.com/bar": "bar",
|
||||
},
|
||||
"baz",
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_token_for_url(url, tokens, expected):
|
||||
# Should always return longest matching of the available options
|
||||
assert token_for_url(url, tokens) == expected
|
||||
Loading…
Add table
Add a link
Reference in a new issue