update: refactor auth and model tools

This commit is contained in:
Amin Ghadersohi
2025-07-16 12:28:55 +10:00
parent 9eac6ef433
commit e5eebe28f9
12 changed files with 173 additions and 93 deletions

View File

@@ -0,0 +1,52 @@
from datetime import datetime
from types import SimpleNamespace
import pytest
from pydantic import BaseModel
from superset.mcp_service.auth import mcp_auth_hook
# Dummy Pydantic output schema
class DummyOutputSchema(BaseModel):
id: int
name: str
# Dummy list schema
class DummyListSchema(BaseModel):
items: list
count: int
total_count: int
page: int
page_size: int
total_pages: int
has_previous: bool
has_next: bool
columns_requested: list
columns_loaded: list
filters_applied: list
pagination: object
timestamp: datetime
# Dummy error schema
class DummyErrorSchema(BaseModel):
error: str
error_type: str
timestamp: datetime
# Dummy DAO
class DummyDAO:
@classmethod
def list(cls, **kwargs):
# Return a list of dummy objects and a total count
return [SimpleNamespace(id=1, name="foo"), SimpleNamespace(id=2, name="bar")], 2
@classmethod
def find_by_id(cls, id):
if id == 1:
return SimpleNamespace(id=1, name="foo")
return None
def dummy_serializer(obj, columns=None):
# Serialize mock object to DummyOutputSchema
return DummyOutputSchema(id=obj.id, name=obj.name)
# All ModelListTool and ModelGetInfoTool tests have been moved to test_model_tools.py

View File

@@ -3,8 +3,7 @@ from types import SimpleNamespace
import pytest
from pydantic import BaseModel
from superset.mcp_service.utils import ModelGetInfoTool, ModelListTool
from superset.mcp_service.model_tools import ModelGetInfoTool, ModelListTool
# Dummy Pydantic output schema
class DummyOutputSchema(BaseModel):
@@ -166,4 +165,4 @@ def test_model_get_info_tool_exception():
)
with pytest.raises(Exception) as exc:
tool.run(1)
assert "fail" in str(exc.value)
assert "fail" in str(exc.value)