summaryrefslogtreecommitdiff
path: root/servers/hello_world/tests/test_prompts.py
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-03-28 20:53:41 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2025-03-28 20:53:41 +0100
commit1745749cd2745c94c3f852e9c02dfde19d8d9c20 (patch)
tree8ed13f3de5fac78d804124e27fbcf1b678e83253 /servers/hello_world/tests/test_prompts.py
Fix ruff errors and warnings in hello_world service
Diffstat (limited to 'servers/hello_world/tests/test_prompts.py')
-rw-r--r--servers/hello_world/tests/test_prompts.py47
1 files changed, 47 insertions, 0 deletions
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)