from __future__ import annotations from types import SimpleNamespace from ariadne.services import game_stream_profiles as profile_module from ariadne.services.game_stream_profiles import GameStreamProfileService def _settings() -> SimpleNamespace: return SimpleNamespace( game_stream_user_group="game-stream-users", game_stream_admin_group="admin", game_stream_profile_group_prefix="game-stream-profile-", ) def test_profile_defaults_to_user_profile(monkeypatch) -> None: monkeypatch.setattr(profile_module, "settings", _settings()) profile = GameStreamProfileService().profile_for("Brad Stein", ["game-stream-users"]) assert profile["allowed"] is True assert profile["profile_id"] == "user-brad-stein" assert profile["profile_group"] == "" def test_profile_group_overrides_user_profile(monkeypatch) -> None: monkeypatch.setattr(profile_module, "settings", _settings()) profile = GameStreamProfileService().profile_for("brad", ["/game-stream-profile-family"]) assert profile["allowed"] is True assert profile["profile_id"] == "family" assert profile["profile_group"] == "game-stream-profile-family" def test_profile_denies_unlisted_user(monkeypatch) -> None: monkeypatch.setattr(profile_module, "settings", _settings()) profile = GameStreamProfileService().profile_for("guest", ["other"]) assert profile["allowed"] is False assert profile["profile_id"] == "user-guest"