my eye

test_easyuri.py

Raw

"""Test easyuri."""

import easyuri


def test_correct_public_suffix():
    """Assert FQDNs have public suffixes."""
    for fqdn, suffix in {
        "foo.com": "com",
        "foo.net": "net",
        "foo.co.uk": "co.uk",
        "foo.cnpy.gdn": "cnpy.gdn",
    }.items():
        assert easyuri.split_suffix(fqdn).suffix == suffix


def test_incorrect_public_suffix():
    """Assert FQDNs have no suffix."""
    for fqdn in (
        "foo.cob",
        "foo.nx",
        "foo.co.u",
        "foo.po",
    ):
        assert easyuri.split_suffix(fqdn).suffix == ""


def test_split_fqdn():
    """Assert FQDNs split correctly."""
    for fqdn, labels in {
        "abba.foo.com": ("abba", "foo", "com"),
        "abba.foo.net": ("abba", "foo", "net"),
        "abba.foo.co.uk": ("abba", "foo", "co.uk"),
        "abba.foo.cnpy.gdn": ("abba", "foo", "cnpy.gdn"),
    }.items():
        assert easyuri.parse(fqdn).labels == labels


def test_split_parts():
    """Assert URLs are split correctly."""
    for url, (host, path) in {
        "abba.foo.com": ("abba.foo.com", ""),
        "abba.foo.com/foo": ("abba.foo.com", "foo"),
        "abba.foo.com/foo/bar": ("abba.foo.com", "foo/bar"),
        "abba.foo.com/foo/bar.xml": ("abba.foo.com", "foo/bar.xml"),
    }.items():
        url = easyuri.parse(url)
        assert url.host == host
        assert url.path == path