from typing import Final import pytest from fastapi import HTTPException from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.engine.endpoints import user_scope @pytest.mark.parametrize( "role", (LitellmUserRoles.INTERNAL_USER, LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY, LitellmUserRoles.TEAM), ) def test_non_admin_cannot_start_analysis_spending(role: LitellmUserRoles) -> None: auth: Final = UserAPIKeyAuth(user_role=role, team_id="team", token="hashed-test-key") with pytest.raises(HTTPException) as error: user_scope(auth, write=True) assert error.value.status_code == 403 def test_admin_can_configure_lens_and_viewer_can_only_read() -> None: admin: Final = UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN) viewer: Final = UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY) assert user_scope(admin, write=True).all_teams assert user_scope(viewer).all_teams