mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
Enhance proxy CLI tests by adding SSL initialization checks for Granian server. Remove Python version skip conditions and implement tests to ensure SSL certificate and key are required for server initialization.
This commit is contained in:
parent
8bd00082ce
commit
3064335896
1 changed files with 43 additions and 8 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import click
|
||||
import fastapi
|
||||
import pytest
|
||||
|
||||
|
|
@ -143,10 +145,6 @@ class TestProxyInitializationHelpers:
|
|||
mock_app, "localhost", 8000, "cert.pem", "key.pem", "ECDHE"
|
||||
)
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 10),
|
||||
reason="Granian is only bundled for Python 3.10+ in litellm[proxy]",
|
||||
)
|
||||
@patch("granian.Granian")
|
||||
@patch("builtins.print")
|
||||
def test_init_granian_server(self, mock_print, mock_granian_cls):
|
||||
|
|
@ -176,10 +174,6 @@ class TestProxyInitializationHelpers:
|
|||
assert "runtime_threads" not in call_kwargs
|
||||
mock_server.serve.assert_called_once()
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 10),
|
||||
reason="Granian is only bundled for Python 3.10+ in litellm[proxy]",
|
||||
)
|
||||
@patch("granian.Granian")
|
||||
@patch("builtins.print")
|
||||
def test_init_granian_server_runtime_threads(self, mock_print, mock_granian_cls):
|
||||
|
|
@ -200,6 +194,47 @@ class TestProxyInitializationHelpers:
|
|||
)
|
||||
assert mock_granian_cls.call_args.kwargs["runtime_threads"] == 4
|
||||
|
||||
@patch("granian.Granian")
|
||||
@patch("builtins.print")
|
||||
def test_init_granian_server_ssl(self, mock_print, mock_granian_cls):
|
||||
pytest.importorskip("granian")
|
||||
mock_server = MagicMock()
|
||||
mock_granian_cls.return_value = mock_server
|
||||
fake_interfaces = SimpleNamespace(ASGI="asgi")
|
||||
with patch("granian.constants.Interfaces", fake_interfaces):
|
||||
ProxyInitializationHelpers._init_granian_server(
|
||||
host="0.0.0.0",
|
||||
port=4000,
|
||||
num_workers=1,
|
||||
ssl_certfile_path="/path/to/cert.pem",
|
||||
ssl_keyfile_path="/path/to/key.pem",
|
||||
max_requests_before_restart=None,
|
||||
ciphers=None,
|
||||
granian_runtime_threads=None,
|
||||
)
|
||||
call_kwargs = mock_granian_cls.call_args.kwargs
|
||||
assert call_kwargs["ssl_cert"] == Path("/path/to/cert.pem")
|
||||
assert call_kwargs["ssl_key"] == Path("/path/to/key.pem")
|
||||
mock_server.serve.assert_called_once()
|
||||
|
||||
@patch("granian.Granian")
|
||||
def test_init_granian_server_ssl_requires_cert_and_key(self, mock_granian_cls):
|
||||
pytest.importorskip("granian")
|
||||
fake_interfaces = SimpleNamespace(ASGI="asgi")
|
||||
with patch("granian.constants.Interfaces", fake_interfaces):
|
||||
with pytest.raises(click.ClickException, match="Both --ssl_certfile_path"):
|
||||
ProxyInitializationHelpers._init_granian_server(
|
||||
host="0.0.0.0",
|
||||
port=4000,
|
||||
num_workers=1,
|
||||
ssl_certfile_path="/path/to/cert.pem",
|
||||
ssl_keyfile_path=None,
|
||||
max_requests_before_restart=None,
|
||||
ciphers=None,
|
||||
granian_runtime_threads=None,
|
||||
)
|
||||
mock_granian_cls.assert_not_called()
|
||||
|
||||
@patch("subprocess.Popen")
|
||||
def test_run_ollama_serve(self, mock_popen):
|
||||
# Execute
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue