aminghadersohi commented on code in PR #41922: URL: https://github.com/apache/superset/pull/41922#discussion_r3589767293
########## tests/unit_tests/mcp_service/system/resources/test_schema_discovery.py: ########## @@ -0,0 +1,127 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for the schema discovery MCP resources (superset://schema/*).""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client +from fastmcp.exceptions import McpError + +from superset.mcp_service.app import mcp +from superset.mcp_service.system.resources.schema_discovery import ( + _build_schema_resource, +) +from superset.utils import json + +RESOURCE_URIS = { + "chart": "superset://schema/chart", + "dataset": "superset://schema/dataset", + "dashboard": "superset://schema/dashboard", + "all": "superset://schema/all", +} + + [email protected] +def mcp_server(): Review Comment: Added `-> FastMCP` return type annotation to the `mcp_server` fixture (commit 4dba1608da). ########## tests/unit_tests/mcp_service/system/resources/test_schema_discovery.py: ########## @@ -0,0 +1,127 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for the schema discovery MCP resources (superset://schema/*).""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client +from fastmcp.exceptions import McpError + +from superset.mcp_service.app import mcp +from superset.mcp_service.system.resources.schema_discovery import ( + _build_schema_resource, +) +from superset.utils import json + +RESOURCE_URIS = { + "chart": "superset://schema/chart", + "dataset": "superset://schema/dataset", + "dashboard": "superset://schema/dashboard", + "all": "superset://schema/all", +} + + [email protected] +def mcp_server(): + return mcp + + [email protected](autouse=True) +def mock_auth(): Review Comment: Added `-> Iterator[Mock]` return type annotation to the `mock_auth` fixture, matching the convention used elsewhere in this test suite (e.g. `test_remove_chart_from_dashboard.py`) (commit 4dba1608da). ########## tests/unit_tests/mcp_service/system/resources/test_schema_discovery.py: ########## @@ -0,0 +1,127 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for the schema discovery MCP resources (superset://schema/*).""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client +from fastmcp.exceptions import McpError + +from superset.mcp_service.app import mcp +from superset.mcp_service.system.resources.schema_discovery import ( + _build_schema_resource, +) +from superset.utils import json + +RESOURCE_URIS = { + "chart": "superset://schema/chart", + "dataset": "superset://schema/dataset", + "dashboard": "superset://schema/dashboard", + "all": "superset://schema/all", +} + + [email protected] +def mcp_server(): + return mcp + + [email protected](autouse=True) +def mock_auth(): + """Mock authentication for all tests.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + mock_user = Mock() + mock_user.id = 1 + mock_user.username = "admin" + mock_get_user.return_value = mock_user + yield mock_get_user + + +async def _read_resource(mcp_server, uri): Review Comment: Added `(mcp_server: FastMCP, uri: str) -> dict[str, Any]` type hints to `_read_resource` (commit 4dba1608da). ########## tests/unit_tests/mcp_service/system/resources/test_schema_discovery.py: ########## @@ -0,0 +1,127 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for the schema discovery MCP resources (superset://schema/*).""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client +from fastmcp.exceptions import McpError + +from superset.mcp_service.app import mcp +from superset.mcp_service.system.resources.schema_discovery import ( + _build_schema_resource, +) +from superset.utils import json + +RESOURCE_URIS = { + "chart": "superset://schema/chart", + "dataset": "superset://schema/dataset", + "dashboard": "superset://schema/dashboard", + "all": "superset://schema/all", +} + + [email protected] +def mcp_server(): + return mcp + + [email protected](autouse=True) +def mock_auth(): + """Mock authentication for all tests.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + mock_user = Mock() + mock_user.id = 1 + mock_user.username = "admin" + mock_get_user.return_value = mock_user + yield mock_get_user + + +async def _read_resource(mcp_server, uri): + async with Client(mcp_server) as client: + result = await client.read_resource(uri) + return json.loads(result[0].text) + + +class TestSchemaDiscoveryResourceRegistration: + """URI pattern matching: resources are discoverable under superset://schema/*.""" + + @pytest.mark.asyncio + async def test_all_schema_resources_registered(self, mcp_server): Review Comment: Added `(self, mcp_server: FastMCP) -> None` type hints to this test method (commit 4dba1608da). ########## tests/unit_tests/mcp_service/system/resources/test_schema_discovery.py: ########## @@ -0,0 +1,127 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for the schema discovery MCP resources (superset://schema/*).""" + +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client +from fastmcp.exceptions import McpError + +from superset.mcp_service.app import mcp +from superset.mcp_service.system.resources.schema_discovery import ( + _build_schema_resource, +) +from superset.utils import json + +RESOURCE_URIS = { + "chart": "superset://schema/chart", + "dataset": "superset://schema/dataset", + "dashboard": "superset://schema/dashboard", + "all": "superset://schema/all", +} + + [email protected] +def mcp_server(): + return mcp + + [email protected](autouse=True) +def mock_auth(): + """Mock authentication for all tests.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + mock_user = Mock() + mock_user.id = 1 + mock_user.username = "admin" + mock_get_user.return_value = mock_user + yield mock_get_user + + +async def _read_resource(mcp_server, uri): + async with Client(mcp_server) as client: + result = await client.read_resource(uri) + return json.loads(result[0].text) + + +class TestSchemaDiscoveryResourceRegistration: + """URI pattern matching: resources are discoverable under superset://schema/*.""" + + @pytest.mark.asyncio + async def test_all_schema_resources_registered(self, mcp_server): + async with Client(mcp_server) as client: + resources = await client.list_resources() + + resource_uris = {str(resource.uri) for resource in resources} + for uri in RESOURCE_URIS.values(): + assert uri in resource_uris + + +class TestSchemaDiscoveryResourceSuccessPaths: + """Success paths for each model-specific and combined schema resource.""" + + @pytest.mark.asyncio + async def test_chart_schema_resource(self, mcp_server): Review Comment: Added `(self, mcp_server: FastMCP) -> None` type hints to this test method (commit 4dba1608da). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
