test: cover the validator, the directory and the site

This commit is contained in:
randogoth 2026-10-11 15:05:42 +03:00
parent 003bb0b4b1
commit 1e75a69381
44 changed files with 1796 additions and 0 deletions

31
tests/test_domains.py Normal file
View file

@ -0,0 +1,31 @@
"""Registrable-domain comparison, which is what the same-site rules rest on."""
import pytest
from mews.fetch import registered_domain, same_site
CASES = [
("example.com", "example.com"),
("img.example.com", "example.com"),
("a.b.example.co.uk", "example.co.uk"),
("EXAMPLE.COM", "example.com"),
("example.com.", "example.com"),
("a.github.io", "a.github.io"),
("not-a-tld", None),
("", None),
]
@pytest.mark.parametrize(("host", "expected"), CASES)
def test_registrable_domain(host, expected):
assert registered_domain(host) == expected
def test_subdomains_of_one_domain_are_one_site():
assert same_site("example.com", "img.example.com")
def test_two_sites_on_a_shared_suffix_are_not_one_site():
"""The reason this uses a public suffix list rather than counting labels."""
assert not same_site("a.github.io", "b.github.io")
assert not same_site("example.co.uk", "evil.co.uk")