From 2f741bdcff977c5f00959952808dae808cc126c4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 29 Jun 2024 13:29:28 -0700 Subject: [PATCH] test - correct error str on exceptions --- litellm/tests/test_proxy_exception_mapping.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/litellm/tests/test_proxy_exception_mapping.py b/litellm/tests/test_proxy_exception_mapping.py index 4988426616a..4fb1e713497 100644 --- a/litellm/tests/test_proxy_exception_mapping.py +++ b/litellm/tests/test_proxy_exception_mapping.py @@ -1,25 +1,31 @@ # test that the proxy actually does exception mapping to the OpenAI format -import sys, os -from unittest import mock import json +import os +import sys +from unittest import mock + from dotenv import load_dotenv load_dotenv() -import os, io, asyncio +import asyncio +import io +import os sys.path.insert( 0, os.path.abspath("../..") ) # Adds the parent directory to the system path +import openai import pytest -import litellm, openai -from fastapi.testclient import TestClient from fastapi import Response -from litellm.proxy.proxy_server import ( +from fastapi.testclient import TestClient + +import litellm +from litellm.proxy.proxy_server import ( # Replace with the actual module where your FastAPI router is defined + initialize, router, save_worker_config, - initialize, -) # Replace with the actual module where your FastAPI router is defined +) invalid_authentication_error_response = Response( status_code=401, @@ -66,6 +72,12 @@ def test_chat_completion_exception(client): json_response = response.json() print("keys in json response", json_response.keys()) assert json_response.keys() == {"error"} + print("ERROR=", json_response["error"]) + assert isinstance(json_response["error"]["message"], str) + assert ( + json_response["error"]["message"] + == "litellm.AuthenticationError: AuthenticationError: OpenAIException - Incorrect API key provided: bad-key. You can find your API key at https://platform.openai.com/account/api-keys." + ) # make an openai client to call _make_status_error_from_response openai_client = openai.OpenAI(api_key="anything")