2026-01-09 12:37:21 +00:00
|
|
|
"""Tests for URL parsing and resolution."""
|
|
|
|
|
|
|
|
|
|
from src.network.url import URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestURL:
|
|
|
|
|
def test_parse_simple_url(self):
|
|
|
|
|
url = URL("https://example.com")
|
|
|
|
|
assert str(url) == "https://example.com"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_parse_url_with_path(self):
|
|
|
|
|
url = URL("https://example.com/path/to/page")
|
|
|
|
|
assert str(url) == "https://example.com/path/to/page"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_parse_url_with_query(self):
|
|
|
|
|
url = URL("https://example.com/search?q=test")
|
|
|
|
|
assert str(url) == "https://example.com/search?q=test"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_origin(self):
|
|
|
|
|
url = URL("https://example.com:8080/path")
|
|
|
|
|
assert url.origin() == "https://example.com:8080"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_origin_default_port(self):
|
|
|
|
|
url = URL("https://example.com/path")
|
|
|
|
|
assert url.origin() == "https://example.com"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_resolve_relative_path(self):
|
|
|
|
|
base = URL("https://example.com/dir/page.html")
|
|
|
|
|
resolved = base.resolve("other.html")
|
|
|
|
|
assert str(resolved) == "https://example.com/dir/other.html"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_resolve_absolute_path(self):
|
|
|
|
|
base = URL("https://example.com/dir/page.html")
|
|
|
|
|
resolved = base.resolve("/root/page.html")
|
|
|
|
|
assert str(resolved) == "https://example.com/root/page.html"
|
2026-01-12 09:22:34 +00:00
|
|
|
|
2026-01-09 12:37:21 +00:00
|
|
|
def test_resolve_full_url(self):
|
|
|
|
|
base = URL("https://example.com/page.html")
|
|
|
|
|
resolved = base.resolve("https://other.com/page.html")
|
|
|
|
|
assert str(resolved) == "https://other.com/page.html"
|