mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-05-01 21:00:44 +00:00
improved test suite and fixed error propagation bug in telegram
This commit is contained in:
parent
5e58d452b8
commit
3f8b9af2c3
12 changed files with 1299 additions and 0 deletions
73
tests/test_models_validators.py
Normal file
73
tests/test_models_validators.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import pytest
|
||||
from unittest.mock import patch
|
||||
from api.models import MessagesRequest, TokenCountRequest, Message
|
||||
from config.settings import Settings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_settings():
|
||||
settings = Settings()
|
||||
settings.model = "target-model-from-settings"
|
||||
return settings
|
||||
|
||||
|
||||
def test_messages_request_map_model_claude_to_default(mock_settings):
|
||||
with patch("api.models.get_settings", return_value=mock_settings):
|
||||
request = MessagesRequest(
|
||||
model="claude-3-opus",
|
||||
max_tokens=100,
|
||||
messages=[Message(role="user", content="hello")],
|
||||
)
|
||||
|
||||
assert request.model == "target-model-from-settings"
|
||||
assert request.original_model == "claude-3-opus"
|
||||
|
||||
|
||||
def test_messages_request_map_model_non_claude_unchanged(mock_settings):
|
||||
with patch("api.models.get_settings", return_value=mock_settings):
|
||||
request = MessagesRequest(
|
||||
model="gpt-4",
|
||||
max_tokens=100,
|
||||
messages=[Message(role="user", content="hello")],
|
||||
)
|
||||
|
||||
# normalize_model_name returns original if not Claude
|
||||
assert request.model == "gpt-4"
|
||||
|
||||
|
||||
def test_messages_request_map_model_with_provider_prefix(mock_settings):
|
||||
with patch("api.models.get_settings", return_value=mock_settings):
|
||||
request = MessagesRequest(
|
||||
model="anthropic/claude-3-haiku",
|
||||
max_tokens=100,
|
||||
messages=[Message(role="user", content="hello")],
|
||||
)
|
||||
|
||||
assert request.model == "target-model-from-settings"
|
||||
|
||||
|
||||
def test_token_count_request_model_validation(mock_settings):
|
||||
with patch("api.models.get_settings", return_value=mock_settings):
|
||||
request = TokenCountRequest(
|
||||
model="claude-3-sonnet", messages=[Message(role="user", content="hello")]
|
||||
)
|
||||
|
||||
assert request.model == "target-model-from-settings"
|
||||
|
||||
|
||||
def test_messages_request_model_mapping_logs(mock_settings):
|
||||
with (
|
||||
patch("api.models.get_settings", return_value=mock_settings),
|
||||
patch("api.models.logger.debug") as mock_log,
|
||||
):
|
||||
MessagesRequest(
|
||||
model="claude-2.1",
|
||||
max_tokens=100,
|
||||
messages=[Message(role="user", content="hello")],
|
||||
)
|
||||
|
||||
mock_log.assert_called()
|
||||
args = mock_log.call_args[0][0]
|
||||
assert "MODEL MAPPING" in args
|
||||
assert "claude-2.1" in args
|
||||
assert "target-model-from-settings" in args
|
||||
Loading…
Add table
Add a link
Reference in a new issue