forked from phoenix/litellm-mirror
test(test_proxy_server_keys.py): use global client
This commit is contained in:
parent
c2b928a286
commit
d3bbf5bdff
2 changed files with 18 additions and 16 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
Giving up get_data(...) after 3 tries (prisma.errors.ClientNotConnectedError: Client is not connected to the query engine, you must call `connect()` before attempting to query data.)
|
||||||
|
Giving up get_data(...) after 3 tries (prisma.errors.ClientNotConnectedError: Client is not connected to the query engine, you must call `connect()` before attempting to query data.)
|
||||||
|
Giving up get_data(...) after 3 tries (prisma.errors.ClientNotConnectedError: Client is not connected to the query engine, you must call `connect()` before attempting to query data.)
|
|
@ -1,4 +1,4 @@
|
||||||
import sys, os, time, asyncio
|
import sys, os, time
|
||||||
import traceback
|
import traceback
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
@ -23,22 +23,22 @@ from concurrent.futures import ThreadPoolExecutor
|
||||||
# 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 fastapi import FastAPI
|
||||||
from litellm.proxy.proxy_server import router, save_worker_config, initialize, startup_event # Replace with the actual module where your FastAPI router is defined
|
from litellm.proxy.proxy_server import router, save_worker_config, startup_event # Replace with the actual module where your FastAPI router is defined
|
||||||
|
filepath = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
config_fp = f"{filepath}/test_configs/test_config.yaml"
|
||||||
|
save_worker_config(config=config_fp, model=None, alias=None, api_base=None, api_version=None, debug=False, temperature=None, max_tokens=None, request_timeout=600, max_budget=None, telemetry=False, drop_params=True, add_function_to_prompt=False, headers=None, save=False, use_queue=False)
|
||||||
|
app = FastAPI()
|
||||||
|
app.include_router(router) # Include your router in the test app
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def wrapper_startup_event():
|
||||||
|
await startup_event()
|
||||||
|
|
||||||
# Here you create a fixture that will be used by your tests
|
# Here you create a fixture that will be used by your tests
|
||||||
# Make sure the fixture returns TestClient(app)
|
# Make sure the fixture returns TestClient(app)
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def client():
|
def client():
|
||||||
filepath = os.path.dirname(os.path.abspath(__file__))
|
with TestClient(app) as client:
|
||||||
config_fp = f"{filepath}/test_configs/test_config.yaml"
|
yield client
|
||||||
save_worker_config(config=config_fp, model=None, alias=None, api_base=None, api_version=None, debug=False, temperature=None, max_tokens=None, request_timeout=600, max_budget=None, telemetry=False, drop_params=True, add_function_to_prompt=False, headers=None, save=False, use_queue=False)
|
|
||||||
initialize(config=config_fp)
|
|
||||||
app = FastAPI()
|
|
||||||
app.include_router(router) # Include your router in the test app
|
|
||||||
import asyncio
|
|
||||||
asyncio.run(startup_event())
|
|
||||||
return TestClient(app)
|
|
||||||
|
|
||||||
def test_add_new_key(client):
|
def test_add_new_key(client):
|
||||||
try:
|
try:
|
||||||
|
@ -71,8 +71,8 @@ def test_add_new_key(client):
|
||||||
|
|
||||||
# # Run the test - only runs via pytest
|
# # Run the test - only runs via pytest
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_add_new_key_max_parallel_limit(client):
|
def test_add_new_key_max_parallel_limit(client):
|
||||||
try:
|
try:
|
||||||
# Your test data
|
# Your test data
|
||||||
test_data = {"duration": "20m", "max_parallel_requests": 1}
|
test_data = {"duration": "20m", "max_parallel_requests": 1}
|
||||||
|
@ -88,7 +88,6 @@ async def test_add_new_key_max_parallel_limit(client):
|
||||||
result = response.json()
|
result = response.json()
|
||||||
def _post_data():
|
def _post_data():
|
||||||
json_data = {'model': 'azure-model', "messages": [{"role": "user", "content": f"this is a test request, write a short poem {time.time()}"}]}
|
json_data = {'model': 'azure-model', "messages": [{"role": "user", "content": f"this is a test request, write a short poem {time.time()}"}]}
|
||||||
print(f"bearer token key: {result['key']}")
|
|
||||||
response = client.post("/chat/completions", json=json_data, headers={"Authorization": f"Bearer {result['key']}"})
|
response = client.post("/chat/completions", json=json_data, headers={"Authorization": f"Bearer {result['key']}"})
|
||||||
return response
|
return response
|
||||||
def _run_in_parallel():
|
def _run_in_parallel():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue