Skip to main content
Glama
test_get_databases.py2.68 kB
"""Unit tests for GetDatabasesService.""" import pytest from mcp_sql.tools.get_databases import GetDatabasesService @pytest.mark.asyncio class TestGetDatabasesService: """Test cases for GetDatabasesService.""" async def test_name_property(self, tool_dependencies): """Test that the tool has the correct name.""" service = GetDatabasesService(**tool_dependencies) assert service.name == "get_databases" async def test_description_property(self, tool_dependencies): """Test that the tool has a description.""" service = GetDatabasesService(**tool_dependencies) assert len(service.description) > 0 assert "database" in service.description.lower() async def test_execute_returns_database_list(self, tool_dependencies, mock_context): """Test that execute returns a list of databases.""" service = GetDatabasesService(**tool_dependencies) result = await service.execute( mock_context, server_name="test_server" ) assert isinstance(result, list) assert len(result) == 3 assert "db1" in result assert "db2" in result assert "db3" in result async def test_execute_with_invalid_credentials(self, tool_dependencies_invalid, mock_context): """Test execute with invalid credentials.""" service = GetDatabasesService(**tool_dependencies_invalid) result = await service.execute( mock_context, server_name="test_server" ) assert isinstance(result, list) assert len(result) == 1 assert "Error: Missing credentials" in result async def test_execute_calls_inspector(self, tool_dependencies, mock_context): """Test that execute calls the database inspector.""" service = GetDatabasesService(**tool_dependencies) await service.execute( mock_context, server_name="test_server" ) tool_dependencies["inspector"].get_databases.assert_called_once() async def test_execute_with_all_params(self, tool_dependencies, mock_context): """Test execute with all optional parameters.""" service = GetDatabasesService(**tool_dependencies) result = await service.execute( mock_context, server_name="custom_server", user="custom_user", password="custom_pass", driver="Custom Driver", port=3306 ) assert isinstance(result, list) tool_dependencies["credentials_manager"].get_from_context.assert_called_once()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yuuues/mcp-sql'

If you have feedback or need assistance with the MCP directory API, please join our Discord server