from datetime import date import pytest from fan_passport.competition_registry import ( CompetitionDefinition, CompetitionRegistry, CompetitionType, ContentNamespace, LeaderboardScope, RegistryError, SeasonWindow, build_default_registry, ) def test_default_registry_contains_world_cup_namespace_and_future_passports() -> None: registry = build_default_registry() assert "world-cup:2026" in registry.namespaces() assert "premier-league:2026-27" in registry.namespaces() assert "champions-league:2026-27" in registry.namespaces() world_cup = registry.get("world-cup", "2026") assert world_cup.content_key("challenge", "watch-england") == "world-cup:2026:challenge:watch-england" assert ( world_cup.leaderboard_key(LeaderboardScope.GLOBAL) == "leaderboard:world-cup:2026:global:overall" ) def test_active_on_returns_competitions_inside_window() -> None: registry = build_default_registry() active = registry.active_on(date(2026, 6, 20)) assert [competition.registry_key for competition in active] == ["world-cup:2026"] def test_registry_rejects_duplicate_competition_season() -> None: competition = CompetitionDefinition( slug="test-cup", name="Test Cup", competition_type=CompetitionType.CLUB_CUP, season_label="2026", governing_body="Test", region="Global", window=SeasonWindow(date(2026, 1, 1), date(2026, 1, 31)), ) with pytest.raises(RegistryError, match="duplicate"): CompetitionRegistry([competition, competition]) def test_namespace_parse_and_lookup_are_stable() -> None: namespace = ContentNamespace.parse("world-cup:2026") registry = build_default_registry() assert namespace.value == "world-cup:2026" assert registry.get_namespace(namespace).name == "FIFA World Cup" assert registry.get_namespace("world-cup:2026").season_label == "2026" def test_get_requires_season_when_multiple_seasons_exist() -> None: registry = CompetitionRegistry( [ CompetitionDefinition( slug="sample-league", name="Sample League 2026", competition_type=CompetitionType.CLUB_LEAGUE, season_label="2026", governing_body="Sample", region="Earth", window=SeasonWindow(date(2026, 1, 1), date(2026, 12, 31)), ), CompetitionDefinition( slug="sample-league", name="Sample League 2027", competition_type=CompetitionType.CLUB_LEAGUE, season_label="2027", governing_body="Sample", region="Earth", window=SeasonWindow(date(2027, 1, 1), date(2027, 12, 31)), ), ] ) with pytest.raises(RegistryError, match="multiple seasons"): registry.get("sample-league")