|
4 | 4 | from bs4 import BeautifulSoup |
5 | 5 |
|
6 | 6 | from library.utils.path_utils import safe_unquote |
7 | | -from library.utils.web import WebPath, extract_nearby_text, url_encode, url_to_local_path |
| 7 | +from library.utils.web import WebPath, construct_absolute_url, extract_nearby_text, url_encode, url_to_local_path |
8 | 8 | from tests.utils import p |
9 | 9 |
|
10 | 10 |
|
@@ -250,3 +250,22 @@ def test_parent_property(): |
250 | 250 | assert str(web_path.parent.parent.parent.parent.parent.parent) == "https://<netloc>/<path1>" |
251 | 251 | assert str(web_path.parent.parent.parent.parent.parent.parent.parent) == "https://<netloc>" |
252 | 252 | assert str(web_path.parent.parent.parent.parent.parent.parent.parent.parent) == "https://<netloc>" |
| 253 | + |
| 254 | +@pytest.mark.parametrize( |
| 255 | + "base_url, href, expected", |
| 256 | + [ |
| 257 | + ("https://unli.xyz/diskprices/index.html", "./ch/", "https://unli.xyz/diskprices/ch/"), |
| 258 | + ("https://unli.xyz/diskprices/index.html", "ch/", "https://unli.xyz/diskprices/ch/"), |
| 259 | + ("https://unli.xyz/diskprices/index.html", "/ch/", "https://unli.xyz/ch/"), |
| 260 | + ("https://unli.xyz/diskprices/", "ch/", "https://unli.xyz/diskprices/ch/"), |
| 261 | + ("https://unli.xyz/diskprices", "ch/", "https://unli.xyz/ch/"), |
| 262 | + ("https://unli.xyz", "diskprices/ch/", "https://unli.xyz/diskprices/ch/"), |
| 263 | + ("https://unli.xyz", "/ch/", "https://unli.xyz/ch/"), |
| 264 | + ("https://unli.xyz/", "//example.com/ch/", "https://example.com/ch/"), |
| 265 | + ("https://unli.xyz/diskprices", "ftp://example.com/ch/", "ftp://example.com/ch/"), |
| 266 | + ("https://unli.xyz/diskprices", "ssh://example.com/ch/", "ssh://example.com/ch/"), |
| 267 | + ] |
| 268 | +) |
| 269 | +def test_construct_absolute_url(base_url, href, expected): |
| 270 | + result = construct_absolute_url(base_url, href) |
| 271 | + assert result == expected |
0 commit comments