From 1745749cd2745c94c3f852e9c02dfde19d8d9c20 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Fri, 28 Mar 2025 20:53:41 +0100 Subject: Fix ruff errors and warnings in hello_world service --- servers/hello_world/tests/test_prompts.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 servers/hello_world/tests/test_prompts.py (limited to 'servers/hello_world/tests/test_prompts.py') diff --git a/servers/hello_world/tests/test_prompts.py b/servers/hello_world/tests/test_prompts.py new file mode 100644 index 0000000..9709718 --- /dev/null +++ b/servers/hello_world/tests/test_prompts.py @@ -0,0 +1,47 @@ +import pytest +import asyncio +from unittest.mock import AsyncMock, MagicMock, patch +import mcp.types as types +from mcp_server_hello_world.server import HelloWorldServer, create_server, GREETING_PROMPT_TEMPLATE + +class TestPrompts: + """Test the prompt functionality.""" + + @pytest.mark.asyncio + async def test_list_prompts(self): + """Test the list_prompts method.""" + # Create a server + mcp = create_server() + + # Get the list of prompts + prompts = await mcp.list_prompts() + + # Verify the result + assert len(prompts) == 1 + assert prompts[0].name == "greeting" + assert "simple greeting prompt" in prompts[0].description.lower() + + @pytest.mark.asyncio + async def test_get_prompt(self): + """Test the get_prompt method.""" + # Create a server + mcp = create_server() + + # Get the prompt + prompt = await mcp.get_prompt("greeting", {"name": "Test User"}) + + # Verify the result + expected_prompt = GREETING_PROMPT_TEMPLATE.format(name="Test User") + assert len(prompt.messages) > 0 + assert prompt.messages[0].role == "user" + assert prompt.messages[0].content.type == "text" + assert expected_prompt.strip() in prompt.messages[0].content.text + + # Test with unknown prompt + with pytest.raises(ValueError): + await mcp.get_prompt("unknown", {"name": "Test User"}) + + # Test with missing name argument + with pytest.raises(ValueError) as excinfo: + await mcp.get_prompt("greeting", {}) + assert "Missing required arguments" in str(excinfo.value) -- cgit v1.2.3