Add tests for fix_url
This commit is contained in:
parent
31cf687e2f
commit
4a7aae4045
@ -27,9 +27,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def fix_url(url: str) -> str:
|
||||
if not url:
|
||||
return ""
|
||||
tmp_url = urlsplit(url)
|
||||
new_path = posixpath.normpath(tmp_url.path)
|
||||
if new_path in (".", "/"):
|
||||
new_path = ""
|
||||
# joinurl only works properly if there is a trailing slash
|
||||
tmp_url = tmp_url._replace(path=posixpath.normpath(tmp_url.path) + "/")
|
||||
tmp_url = tmp_url._replace(path=new_path + "/")
|
||||
return tmp_url.geturl()
|
||||
|
||||
|
||||
|
@ -5,6 +5,7 @@ import os
|
||||
import pytest
|
||||
|
||||
import comicapi.utils
|
||||
import comictalker.talker_utils
|
||||
|
||||
|
||||
def test_os_sorted():
|
||||
@ -200,3 +201,20 @@ titles_2 = [
|
||||
@pytest.mark.parametrize("value, result", titles_2)
|
||||
def test_sanitize_title(value, result):
|
||||
assert comicapi.utils.sanitize_title(value) == result.casefold()
|
||||
|
||||
|
||||
urls = [
|
||||
("", ""),
|
||||
("http://test.test", "http://test.test/"),
|
||||
("http://test.test/", "http://test.test/"),
|
||||
("http://test.test/..", "http://test.test/"),
|
||||
("http://test.test/../hello", "http://test.test/hello/"),
|
||||
("http://test.test/../hello/", "http://test.test/hello/"),
|
||||
("http://test.test/../hello/..", "http://test.test/"),
|
||||
("http://test.test/../hello/../", "http://test.test/"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value, result", urls)
|
||||
def test_fix_url(value, result):
|
||||
assert comictalker.talker_utils.fix_url(value) == result
|
||||
|
Loading…
Reference in New Issue
Block a user