Skip to main content
Glama
test_get_tables.py2.63 kB
"""Unit tests for GetTablesService.""" import pytest from mcp_sql.tools.get_tables import GetTablesService @pytest.mark.asyncio class TestGetTablesService: """Test cases for GetTablesService.""" async def test_name_property(self, tool_dependencies): """Test that the tool has the correct name.""" service = GetTablesService(**tool_dependencies) assert service.name == "get_tables" async def test_description_property(self, tool_dependencies): """Test that the tool has a description.""" service = GetTablesService(**tool_dependencies) assert len(service.description) > 0 assert "table" in service.description.lower() async def test_execute_returns_table_list(self, tool_dependencies, mock_context): """Test that execute returns a list of tables.""" service = GetTablesService(**tool_dependencies) result = await service.execute( mock_context, database="test_db", server_name="test_server" ) assert isinstance(result, list) assert len(result) == 3 assert "table1" in result assert "table2" in result assert "table3" in result async def test_execute_without_database(self, tool_dependencies, mock_context, mock_credentials): """Test execute without database name.""" mock_credentials.database = None service = GetTablesService(**tool_dependencies) result = await service.execute( mock_context, server_name="test_server" ) assert isinstance(result, list) assert len(result) == 1 assert "Error: Database name is required" in result async def test_execute_with_invalid_credentials(self, tool_dependencies_invalid, mock_context): """Test execute with invalid credentials.""" service = GetTablesService(**tool_dependencies_invalid) result = await service.execute( mock_context, database="test_db" ) 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 = GetTablesService(**tool_dependencies) await service.execute( mock_context, database="test_db", server_name="test_server" ) tool_dependencies["inspector"].get_tables.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