fix custom auth test

This commit is contained in:
Ishaan Jaff 2024-07-30 16:50:55 -07:00
parent 29a5bddcfa
commit 129bafd04c

View file

@ -1,29 +1,34 @@
import sys, os import os
import sys
import traceback import traceback
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
import os, io import io
import os
# this file is to test litellm/proxy # this file is to test litellm/proxy
sys.path.insert( sys.path.insert(
0, os.path.abspath("../..") 0, os.path.abspath("../..")
) # Adds the parent directory to the system path ) # Adds the parent directory to the system path
import pytest, asyncio import asyncio
import litellm
from litellm import embedding, completion, completion_cost, Timeout import pytest
from litellm import RateLimitError from fastapi import FastAPI
# test /chat/completion request to the proxy # test /chat/completion request to the proxy
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from fastapi import FastAPI
from litellm.proxy.proxy_server import ( import litellm
from litellm import RateLimitError, Timeout, completion, completion_cost, embedding
from litellm.proxy.proxy_server import ( # Replace with the actual module where your FastAPI router is defined
ProxyConfig,
initialize,
router, router,
save_worker_config, save_worker_config,
initialize, )
ProxyConfig,
) # Replace with the actual module where your FastAPI router is defined
# Here you create a fixture that will be used by your tests # Here you create a fixture that will be used by your tests
@ -62,7 +67,7 @@ def test_custom_auth(client):
except Exception as e: except Exception as e:
print(vars(e)) print(vars(e))
print("got an exception") print("got an exception")
assert e.code == 401 assert e.code == "401"
assert e.message == "Authentication Error, Failed custom auth" assert e.message == "Authentication Error, Failed custom auth"
pass pass
@ -86,7 +91,7 @@ def test_custom_auth_bearer(client):
except Exception as e: except Exception as e:
print(vars(e)) print(vars(e))
print("got an exception") print("got an exception")
assert e.code == 401 assert e.code == "401"
assert ( assert (
e.message e.message
== "Authentication Error, CustomAuth - Malformed API Key passed in. Ensure Key has `Bearer` prefix" == "Authentication Error, CustomAuth - Malformed API Key passed in. Ensure Key has `Bearer` prefix"