test: improve debugging for test

This commit is contained in:
Krrish Dholakia 2024-08-05 19:40:49 -07:00
parent 4538eb848f
commit 5c6dcd6029
4 changed files with 19 additions and 3 deletions

View file

@ -1,5 +1,6 @@
import re
import sys
import traceback
from fastapi import Request
@ -87,14 +88,16 @@ def get_request_route(request: Request) -> str:
remove base url from path if set e.g. `/genai/chat/completions` -> `/chat/completions
"""
try:
if request.url.path.startswith(request.base_url.path):
if hasattr(request, "base_url") and request.url.path.startswith(
request.base_url.path
):
# remove base_url from path
return request.url.path[len(request.base_url.path) - 1 :]
else:
return request.url.path
except Exception as e:
verbose_proxy_logger.warning(
f"error on get_request_route: {str(e)}, defaulting to request.url.path"
verbose_proxy_logger.debug(
f"error on get_request_route: {str(e)}, defaulting to request.url.path={request.url.path}"
)
return request.url.path

View file

@ -532,6 +532,12 @@ async def user_api_key_auth(
api_key, str
): # if generated token, make sure it starts with sk-.
assert api_key.startswith("sk-") # prevent token hashes from being used
else:
verbose_logger.warning(
"litellm.proxy.proxy_server.user_api_key_auth(): Warning - Key={} is not a string.".format(
api_key
)
)
if (
prisma_client is None and custom_db_client is None

View file

@ -1389,6 +1389,7 @@ class PrismaClient:
WHERE v.token = '{token}'
"""
print_verbose("sql_query being made={}".format(sql_query))
response = await self.db.query_first(query=sql_query)
if response is not None:

View file

@ -303,6 +303,7 @@ def test_call_with_invalid_key(prisma_client):
def test_call_with_invalid_model(prisma_client):
litellm.set_verbose = True
# 3. Make a call to a key with an invalid model - expect to fail
setattr(litellm.proxy.proxy_server, "prisma_client", prisma_client)
setattr(litellm.proxy.proxy_server, "master_key", "sk-1234")
@ -326,6 +327,11 @@ def test_call_with_invalid_model(prisma_client):
request.body = return_body
# use generated key to auth in
print(
"Bearer token being sent to user_api_key_auth() - {}".format(
bearer_token
)
)
result = await user_api_key_auth(request=request, api_key=bearer_token)
pytest.fail(f"This should have failed!. IT's an invalid model")