mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
test - pass through endpoint
This commit is contained in:
parent
4f32f283a3
commit
d085ce2d97
1 changed files with 51 additions and 0 deletions
51
litellm/tests/test_pass_through_endpoints.py
Normal file
51
litellm/tests/test_pass_through_endpoints.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
sys.path.insert(
|
||||||
|
0, os.path.abspath("../..")
|
||||||
|
) # Adds-the parent directory to the system path
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from litellm.proxy.proxy_server import app, initialize_pass_through_endpoints
|
||||||
|
|
||||||
|
|
||||||
|
# Mock the async_client used in the pass_through_request function
|
||||||
|
async def mock_request(*args, **kwargs):
|
||||||
|
return httpx.Response(200, json={"message": "Mocked response"})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
return TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_pass_through_endpoint(client, monkeypatch):
|
||||||
|
# Mock the httpx.AsyncClient.request method
|
||||||
|
monkeypatch.setattr("httpx.AsyncClient.request", mock_request)
|
||||||
|
|
||||||
|
# Define a pass-through endpoint
|
||||||
|
pass_through_endpoints = [
|
||||||
|
{
|
||||||
|
"path": "/test-endpoint",
|
||||||
|
"target": "https://api.example.com/v1/chat/completions",
|
||||||
|
"headers": {"Authorization": "Bearer test-token"},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Initialize the pass-through endpoint
|
||||||
|
await initialize_pass_through_endpoints(pass_through_endpoints)
|
||||||
|
|
||||||
|
# Make a request to the pass-through endpoint
|
||||||
|
response = client.post("/test-endpoint", json={"prompt": "Hello, world!"})
|
||||||
|
|
||||||
|
# Assert the response
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"message": "Mocked response"}
|
Loading…
Add table
Add a link
Reference in a new issue