test_recreation_server.py•1.38 kB
"""
Module for testing the MCP server creation and tool registration.
This module contains unit tests to verify the correct setup and behavior of the server.
"""
import unittest
from unittest.mock import patch, Mock
from hkopenai.hk_recreation_mcp_server.server import server
class TestApp(unittest.TestCase):
"""
Test class for verifying MCP server creation and tool functionality.
This class tests the initialization of the server and the registration of tools.
"""
@patch("hkopenai.hk_recreation_mcp_server.server.FastMCP")
@patch("hkopenai.hk_recreation_mcp_server.tools.creative_goods_trade.register")
def test_create_mcp_server(self, mock_tool_creative_goods_trade, mock_fastmcp):
"""Test the creation and configuration of the MCP server with mocked dependencies."""
# Setup mocks
mock_server = Mock()
# Configure mock_server.tool to return a mock that acts as the decorator
# This mock will then be called with the function to be decorated
mock_server.tool.return_value = Mock()
mock_fastmcp.return_value = mock_server
# Test server creation
mcp_instance = server()
# Verify server creation
mock_fastmcp.assert_called_once()
mock_tool_creative_goods_trade.assert_called_once_with(mock_server)
if __name__ == "__main__":
unittest.main()