from devplacepy.avatar import avatar_url, generate_avatar_svg


def test_avatar_url_format():
    url = avatar_url("multiavatar", "testuser", 128)
    assert url == "/avatar/multiavatar/testuser?size=128"


def test_avatar_url_different_size():
    url = avatar_url("multiavatar", "testuser", 64)
    assert "size=64" in url


def test_avatar_url_contains_seed():
    url = avatar_url("multiavatar", "customuser", 128)
    assert "customuser" in url


def test_generate_avatar_svg_returns_string():
    svg = generate_avatar_svg("testuser")
    assert isinstance(svg, str)
    assert len(svg) > 100


def test_generate_avatar_svg_is_svg():
    svg = generate_avatar_svg("testuser")
    assert svg.strip().startswith("<svg")
    assert "xmlns" in svg


def test_generate_avatar_svg_deterministic():
    svg1 = generate_avatar_svg("testuser")
    svg2 = generate_avatar_svg("testuser")
    assert svg1 == svg2


def test_generate_avatar_svg_different_for_different_seeds():
    svg1 = generate_avatar_svg("alice")
    svg2 = generate_avatar_svg("bob")
    assert svg1 != svg2


def test_generate_avatar_svg_fallback_on_exception():
    svg = generate_avatar_svg("a")
    assert isinstance(svg, str)
    assert len(svg) > 50


def test_generate_avatar_svg_includes_rect_for_fallback():
    svg = generate_avatar_svg("a")
    assert "rect" in svg or "path" in svg


def test_avatar_url_with_different_seeds():
    url1 = avatar_url("multiavatar", "alice", 128)
    url2 = avatar_url("multiavatar", "bob", 128)
    assert url1 != url2


def test_generate_avatar_svg_empty_seed_uses_fallback():
    svg = generate_avatar_svg("")
    assert isinstance(svg, str)
    assert "rect" in svg or "svg" in svg
