diff --git a/tests/unit/models/test_config.py b/tests/unit/models/test_config.py index 47afc9159..d9040e88e 100644 --- a/tests/unit/models/test_config.py +++ b/tests/unit/models/test_config.py @@ -365,8 +365,8 @@ def test_dump_configuration(tmp_path) -> None: } -def test_dump_configuration_with_mcp_servers(tmp_path) -> None: - """Test the ability to dump configuration with MCP servers.""" +def test_dump_configuration_with_one_mcp_server(tmp_path) -> None: + """Test the ability to dump configuration with one MCP server configured.""" mcp_servers = [ ModelContextProtocolServer(name="test-server", url="http://localhost:8080"), ] @@ -429,3 +429,87 @@ def test_dump_configuration_with_mcp_servers(tmp_path) -> None: }, ], } + + +def test_dump_configuration_with_more_mcp_servers(tmp_path) -> None: + """Test the ability to dump configuration with more MCP servers configured.""" + mcp_servers = [ + ModelContextProtocolServer(name="test-server-1", url="http://localhost:8081"), + ModelContextProtocolServer(name="test-server-2", url="http://localhost:8082"), + ModelContextProtocolServer(name="test-server-3", url="http://localhost:8083"), + ] + cfg = Configuration( + name="test_name", + service=ServiceConfiguration(), + llama_stack=LLamaStackConfiguration( + use_as_library_client=True, library_client_config_path="foo" + ), + user_data_collection=UserDataCollection( + feedback_disabled=True, feedback_storage=None + ), + mcp_servers=mcp_servers, + ) + dump_file = tmp_path / "test.json" + cfg.dump(dump_file) + + with open(dump_file, "r", encoding="utf-8") as fin: + content = json.load(fin) + assert content is not None + assert "mcp_servers" in content + assert len(content["mcp_servers"]) == 3 + assert content["mcp_servers"][0]["name"] == "test-server-1" + assert content["mcp_servers"][0]["url"] == "http://localhost:8081" + assert content["mcp_servers"][0]["provider_id"] == "model-context-protocol" + assert content["mcp_servers"][1]["name"] == "test-server-2" + assert content["mcp_servers"][1]["url"] == "http://localhost:8082" + assert content["mcp_servers"][1]["provider_id"] == "model-context-protocol" + assert content["mcp_servers"][2]["name"] == "test-server-3" + assert content["mcp_servers"][2]["url"] == "http://localhost:8083" + assert content["mcp_servers"][2]["provider_id"] == "model-context-protocol" + + # check the whole deserialized JSON file content + assert content == { + "name": "test_name", + "service": { + "host": "localhost", + "port": 8080, + "auth_enabled": False, + "workers": 1, + "color_log": True, + "access_log": True, + "tls_config": { + "tls_certificate_path": None, + "tls_key_path": None, + "tls_key_password": None, + }, + }, + "llama_stack": { + "url": None, + "api_key": None, + "use_as_library_client": True, + "library_client_config_path": "foo", + }, + "user_data_collection": { + "feedback_disabled": True, + "feedback_storage": None, + "transcripts_disabled": True, + "transcripts_storage": None, + }, + "mcp_servers": [ + { + "name": "test-server-1", + "provider_id": "model-context-protocol", + "url": "http://localhost:8081", + }, + { + "name": "test-server-2", + "provider_id": "model-context-protocol", + "url": "http://localhost:8082", + }, + { + "name": "test-server-3", + "provider_id": "model-context-protocol", + "url": "http://localhost:8083", + }, + ], + } diff --git a/tests/unit/models/test_requests.py b/tests/unit/models/test_requests.py index 3f97329b2..5376cbaf7 100644 --- a/tests/unit/models/test_requests.py +++ b/tests/unit/models/test_requests.py @@ -50,6 +50,7 @@ def test_with_attachments(self) -> None: query="Tell me about Kubernetes", attachments=attachments, ) + assert qr.attachments is not None assert len(qr.attachments) == 2 assert qr.attachments[0].attachment_type == "log" assert qr.attachments[0].content_type == "text/plain" @@ -108,6 +109,7 @@ def test_validate_provider_and_model(self) -> None: provider="OpenAI", model="gpt-3.5-turbo", ) + assert qr is not None validated_qr = qr.validate_provider_and_model() assert validated_qr.provider == "OpenAI" assert validated_qr.model == "gpt-3.5-turbo" diff --git a/tests/unit/runners/test_uvicorn_runner.py b/tests/unit/runners/test_uvicorn_runner.py index 9de996bc1..1568fed7b 100644 --- a/tests/unit/runners/test_uvicorn_runner.py +++ b/tests/unit/runners/test_uvicorn_runner.py @@ -1,9 +1,8 @@ """Unit tests for runners.""" +from pathlib import Path from unittest.mock import patch -from pydantic import FilePath - from models.config import ServiceConfiguration, TLSConfiguration from runners.uvicorn import start_uvicorn @@ -78,9 +77,9 @@ def test_start_uvicorn_empty_tls_configuration() -> None: def test_start_uvicorn_tls_configuration() -> None: """Test the function to start Uvicorn server using custom TLS configuration.""" tls_config = TLSConfiguration( - tls_certificate_path="tests/configuration/server.crt", - tls_key_path="tests/configuration/server.key", - tls_key_password="tests/configuration/password", + tls_certificate_path=Path("tests/configuration/server.crt"), + tls_key_path=Path("tests/configuration/server.key"), + tls_key_password=Path("tests/configuration/password"), ) configuration = ServiceConfiguration( host="x.y.com", port=1234, workers=10, tls_config=tls_config @@ -95,8 +94,8 @@ def test_start_uvicorn_tls_configuration() -> None: port=1234, workers=10, log_level=20, - ssl_certfile=FilePath("tests/configuration/server.crt"), - ssl_keyfile=FilePath("tests/configuration/server.key"), + ssl_certfile=Path("tests/configuration/server.crt"), + ssl_keyfile=Path("tests/configuration/server.key"), ssl_keyfile_password="tests/configuration/password", use_colors=True, access_log=True,