The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Adding tests
yuneng-jiang883f83a9cbc1
diff --git a/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysPage.test.tsx b/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysPage.test.tsxnew file mode 100644index 00000000000..46df98a31de--- /dev/null+++ b/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysPage.test.tsx@@ -0,0 +1,102 @@+import { screen } from "@testing-library/react";+import { vi, it, expect, beforeEach, MockedFunction } from "vitest";+import { renderWithProviders } from "../../../tests/test-utils";+import DeletedKeysPage from "./DeletedKeysPage";+import { useDeletedKeys, DeletedKeyResponse } from "@/app/(dashboard)/hooks/keys/useKeys";++vi.mock("@/app/(dashboard)/hooks/keys/useKeys", () => ({+ useDeletedKeys: vi.fn(),+}));++const mockUseDeletedKeys = useDeletedKeys as MockedFunction<typeof useDeletedKeys>;++const mockDeletedKey: DeletedKeyResponse = {+ token: "sk-1234567890abcdef",+ token_id: "key-1",+ key_name: "test-key",+ key_alias: "Test Key Alias",+ spend: 5.5,+ max_budget: 100,+ expires: "2024-12-31T23:59:59Z",+ models: ["gpt-3.5-turbo"],+ aliases: {},+ config: {},+ user_id: "user-1",+ team_id: "team-1",+ max_parallel_requests: 10,+ metadata: {},+ tpm_limit: 1000,+ rpm_limit: 100,+ duration: "30d",+ budget_duration: "1m",+ budget_reset_at: "2024-12-01T00:00:00Z",+ allowed_cache_controls: [],+ allowed_routes: [],+ permissions: {},+ model_spend: {},+ model_max_budget: {},+ soft_budget_cooldown: false,+ blocked: false,+ litellm_budget_table: {},+ organization_id: "org-1",+ created_at: "2024-11-01T10:00:00Z",+ updated_at: "2024-11-15T10:00:00Z",+ team_spend: 5.5,+ team_alias: "Test Team",+ team_tpm_limit: 5000,+ team_rpm_limit: 500,+ team_max_budget: 500,+ team_models: ["gpt-3.5-turbo"],+ team_blocked: false,+ soft_budget: 50,+ team_model_aliases: {},+ team_member_spend: 0,+ team_metadata: {},+ end_user_id: "end-user-1",+ end_user_tpm_limit: 100,+ end_user_rpm_limit: 10,+ end_user_max_budget: 10,+ last_refreshed_at: Date.now(),+ api_key: "sk-1234567890abcdef",+ user_role: "user",+ rpm_limit_per_model: {},+ tpm_limit_per_model: {},+ user_tpm_limit: 1000,+ user_rpm_limit: 100,+ user_email: "[email protected]",+ deleted_at: "2024-11-15T10:00:00Z",+ deleted_by: "user-1",+};++beforeEach(() => {+ vi.clearAllMocks();++ mockUseDeletedKeys.mockReturnValue({+ data: {+ keys: [mockDeletedKey],+ total_count: 1,+ current_page: 1,+ total_pages: 1,+ },+ isPending: false,+ isFetching: false,+ } as any);+});++it("should render DeletedKeysPage component", () => {+ renderWithProviders(<DeletedKeysPage />);++ expect(screen.getByText("Test Key Alias")).toBeInTheDocument();+});++it("should handle loading state", () => {+ mockUseDeletedKeys.mockReturnValue({+ data: undefined,+ isPending: true,+ isFetching: false,+ } as any);++ renderWithProviders(<DeletedKeysPage />);++ expect(screen.getByText("🚅 Loading keys...")).toBeInTheDocument();+});diff --git a/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysTable/DeletedKeysTable.test.tsx b/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysTable/DeletedKeysTable.test.tsxnew file mode 100644index 00000000000..081ae0a80b5--- /dev/null+++ b/ui/litellm-dashboard/src/components/DeletedKeysPage/DeletedKeysTable/DeletedKeysTable.test.tsx@@ -0,0 +1,101 @@+import { screen } from "@testing-library/react";+import { vi, it, expect, beforeEach } from "vitest";+import { renderWithProviders } from "../../../../tests/test-utils";+import { DeletedKeysTable } from "./DeletedKeysTable";+import { DeletedKeyResponse } from "@/app/(dashboard)/hooks/keys/useKeys";++const mockDeletedKey: DeletedKeyResponse = {+ token: "sk-1234567890abcdef",+ token_id: "key-1",+ key_name: "test-key",+ key_alias: "Test Key Alias",+ spend: 5.5,+ max_budget: 100,+ expires: "2024-12-31T23:59:59Z",+ models: ["gpt-3.5-turbo"],+ aliases: {},+ config: {},+ user_id: "user-1",+ team_id: "team-1",+ max_parallel_requests: 10,+ metadata: {},+ tpm_limit: 1000,+ rpm_limit: 100,+ duration: "30d",+ budget_duration: "1m",+ budget_reset_at: "2024-12-01T00:00:00Z",+ allowed_cache_controls: [],+ allowed_routes: [],+ permissions: {},+ model_spend: {},+ model_max_budget: {},+ soft_budget_cooldown: false,+ blocked: false,+ litellm_budget_table: {},+ organization_id: "org-1",+ created_at: "2024-11-01T10:00:00Z",+ updated_at: "2024-11-15T10:00:00Z",+ team_spend: 5.5,+ team_alias: "Test Team",+ team_tpm_limit: 5000,+ team_rpm_limit: 500,+ team_max_budget: 500,+ team_models: ["gpt-3.5-turbo"],+ team_blocked: false,+ soft_budget: 50,+ team_model_aliases: {},+ team_member_spend: 0,+ team_metadata: {},+ end_user_id: "end-user-1",+ end_user_tpm_limit: 100,+ end_user_rpm_limit: 10,+ end_user_max_budget: 10,+ last_refreshed_at: Date.now(),+ api_key: "sk-1234567890abcdef",+ user_role: "user",+ rpm_limit_per_model: {},+ tpm_limit_per_model: {},+ user_tpm_limit: 1000,+ user_rpm_limit: 100,+ user_email: "[email protected]",+ deleted_at: "2024-11-15T10:00:00Z",+ deleted_by: "user-1",+};++beforeEach(() => {+ vi.clearAllMocks();+});++it("should render DeletedKeysTable component", () => {+ renderWithProviders(+ <DeletedKeysTable+ keys={[mockDeletedKey]}+ totalCount={1}+ isLoading={false}+ isFetching={false}+ pageIndex={0}+ pageSize={50}+ onPageChange={vi.fn()}+ />,+ );++ expect(screen.getByText("Test Key Alias")).toBeInTheDocument();+});++it("should display key information correctly", () => {+ renderWithProviders(+ <DeletedKeysTable+ keys={[mockDeletedKey]}+ totalCount={1}+ isLoading={false}+ isFetching={false}+ pageIndex={0}+ pageSize={50}+ onPageChange={vi.fn()}+ />,+ );++ expect(screen.getByText("Test Key Alias")).toBeInTheDocument();+ expect(screen.getByText("sk-1234567890abcdef")).toBeInTheDocument();+ expect(screen.getByText("Showing 1 - 1 of 1 results")).toBeInTheDocument();+});diff --git a/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsPage.test.tsx b/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsPage.test.tsxnew file mode 100644index 00000000000..77d2e94067e--- /dev/null+++ b/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsPage.test.tsx@@ -0,0 +1,56 @@+import { screen } from "@testing-library/react";+import { vi, it, expect, beforeEach, MockedFunction } from "vitest";+import { renderWithProviders } from "../../../tests/test-utils";+import DeletedTeamsPage from "./DeletedTeamsPage";+import { useDeletedTeams, DeletedTeam } from "@/app/(dashboard)/hooks/teams/useTeams";++vi.mock("@/app/(dashboard)/hooks/teams/useTeams", () => ({+ useDeletedTeams: vi.fn(),+}));++const mockUseDeletedTeams = useDeletedTeams as MockedFunction<typeof useDeletedTeams>;++const mockDeletedTeam: DeletedTeam = {+ team_id: "team-1",+ team_alias: "Test Team",+ models: ["gpt-3.5-turbo", "gpt-4"],+ max_budget: 500,+ budget_duration: "1m",+ tpm_limit: 5000,+ rpm_limit: 500,+ organization_id: "org-1",+ created_at: "2024-10-01T10:00:00Z",+ keys: [],+ members_with_roles: [],+ deleted_at: "2024-11-15T10:00:00Z",+ deleted_by: "user-1",+ spend: 100.5,+};++beforeEach(() => {+ vi.clearAllMocks();++ mockUseDeletedTeams.mockReturnValue({+ data: [mockDeletedTeam],+ isPending: false,+ isFetching: false,+ } as any);+});++it("should render DeletedTeamsPage component", () => {+ renderWithProviders(<DeletedTeamsPage />);++ expect(screen.getByText("Test Team")).toBeInTheDocument();+});++it("should handle loading state", () => {+ mockUseDeletedTeams.mockReturnValue({+ data: undefined,+ isPending: true,+ isFetching: false,+ } as any);++ renderWithProviders(<DeletedTeamsPage />);++ expect(screen.getByText("🚅 Loading teams...")).toBeInTheDocument();+});diff --git a/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsTable/DeletedTeamsTable.test.tsx b/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsTable/DeletedTeamsTable.test.tsxnew file mode 100644index 00000000000..803e3a0f2f5--- /dev/null+++ b/ui/litellm-dashboard/src/components/DeletedTeamsPage/DeletedTeamsTable/DeletedTeamsTable.test.tsx@@ -0,0 +1,44 @@+import { screen } from "@testing-library/react";+import { vi, it, expect, beforeEach } from "vitest";+import { renderWithProviders } from "../../../../tests/test-utils";+import { DeletedTeamsTable } from "./DeletedTeamsTable";+import { DeletedTeam } from "@/app/(dashboard)/hooks/teams/useTeams";++const mockDeletedTeam: DeletedTeam = {+ team_id: "team-1",+ team_alias: "Test Team",+ models: ["gpt-3.5-turbo", "gpt-4"],+ max_budget: 500,+ budget_duration: "1m",+ tpm_limit: 5000,+ rpm_limit: 500,+ organization_id: "org-1",+ created_at: "2024-10-01T10:00:00Z",+ keys: [],+ members_with_roles: [],+ deleted_at: "2024-11-15T10:00:00Z",+ deleted_by: "user-1",+ spend: 100.5,+};++beforeEach(() => {+ vi.clearAllMocks();+});++it("should render DeletedTeamsTable component", () => {+ renderWithProviders(+ <DeletedTeamsTable teams={[mockDeletedTeam]} isLoading={false} isFetching={false} />,+ );++ expect(screen.getByText("Test Team")).toBeInTheDocument();+});++it("should display team information correctly", () => {+ renderWithProviders(+ <DeletedTeamsTable teams={[mockDeletedTeam]} isLoading={false} isFetching={false} />,+ );++ expect(screen.getByText("Test Team")).toBeInTheDocument();+ expect(screen.getByText("team-1")).toBeInTheDocument();+ expect(screen.getByText("Showing 1 team")).toBeInTheDocument();+});diff --git a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsxindex a04fbf3943d..5511a671db7 100644--- a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx+++ b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx@@ -14,6 +14,7 @@ export interface Team {created_at: string;keys: KeyResponse[];members_with_roles: Member[];+ spend: number;}export interface KeyResponse {