from news.util import canonical_url, content_hash, stable_id def test_canonical_url_strips_tracking_and_www(): a = canonical_url("https://www.bbc.co.uk/news/world-123?utm_source=rss&utm_medium=feed") b = canonical_url("https://bbc.co.uk/news/world-123/") assert a == b == "https://bbc.co.uk/news/world-123" def test_canonical_url_keeps_meaningful_query(): url = canonical_url("https://news.ycombinator.com/item?id=4242&utm_campaign=x") assert url == "https://news.ycombinator.com/item?id=4242" def test_canonical_url_drops_fragment(): assert canonical_url("https://x.com/a#section") == "https://x.com/a" def test_stable_id_is_deterministic_and_distinct(): assert stable_id("source", "u") == stable_id("source", "u") assert stable_id("source", "u") != stable_id("source", "v") def test_content_hash_matches_only_identical_text(): assert content_hash("a b") == content_hash("a b") assert content_hash("a b") != content_hash("a b")