mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
tests fix use correct import responses
This commit is contained in:
parent
4293dd2c2a
commit
e03686de5f
2 changed files with 20 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ import sys
|
|||
|
||||
import pytest
|
||||
import requests
|
||||
import responses
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../../..")
|
||||
|
|
@ -125,7 +126,8 @@ def test_completions_all_parameters(client, sample_messages):
|
|||
}
|
||||
|
||||
|
||||
def test_completions_mock_response(client, sample_messages, requests_mock):
|
||||
@responses.activate
|
||||
def test_completions_mock_response(client, sample_messages):
|
||||
"""Test completions with a mocked successful response"""
|
||||
mock_response = {
|
||||
"id": "chatcmpl-123",
|
||||
|
|
@ -146,7 +148,12 @@ def test_completions_mock_response(client, sample_messages, requests_mock):
|
|||
}
|
||||
|
||||
# Mock the POST request
|
||||
requests_mock.post(f"{client._base_url}/chat/completions", json=mock_response)
|
||||
responses.add(
|
||||
responses.POST,
|
||||
f"{client._base_url}/chat/completions",
|
||||
json=mock_response,
|
||||
status=200,
|
||||
)
|
||||
|
||||
response = client.completions(model="gpt-4", messages=sample_messages)
|
||||
|
||||
|
|
@ -157,12 +164,14 @@ def test_completions_mock_response(client, sample_messages, requests_mock):
|
|||
)
|
||||
|
||||
|
||||
def test_completions_unauthorized_error(client, sample_messages, requests_mock):
|
||||
@responses.activate
|
||||
def test_completions_unauthorized_error(client, sample_messages):
|
||||
"""Test that completions raises UnauthorizedError for 401 responses"""
|
||||
# Mock a 401 response
|
||||
requests_mock.post(
|
||||
responses.add(
|
||||
responses.POST,
|
||||
f"{client._base_url}/chat/completions",
|
||||
status_code=401,
|
||||
status=401,
|
||||
json={"error": "Unauthorized"},
|
||||
)
|
||||
|
||||
|
|
@ -170,12 +179,14 @@ def test_completions_unauthorized_error(client, sample_messages, requests_mock):
|
|||
client.completions(model="gpt-4", messages=sample_messages)
|
||||
|
||||
|
||||
def test_completions_other_errors(client, sample_messages, requests_mock):
|
||||
@responses.activate
|
||||
def test_completions_other_errors(client, sample_messages):
|
||||
"""Test that completions raises HTTPError for other error responses"""
|
||||
# Mock a 500 response
|
||||
requests_mock.post(
|
||||
responses.add(
|
||||
responses.POST,
|
||||
f"{client._base_url}/chat/completions",
|
||||
status_code=500,
|
||||
status=500,
|
||||
json={"error": "Internal Server Error"},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import sys
|
|||
|
||||
import pytest
|
||||
import requests
|
||||
import responses
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../../..")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue