Copilot commented on code in PR #39997: URL: https://github.com/apache/superset/pull/39997#discussion_r3236441103
########## tests/unit_tests/commands/chart/update_test.py: ########## @@ -0,0 +1,50 @@ +# 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. +from unittest.mock import MagicMock, patch + +import pytest + +from superset.commands.chart.exceptions import ChartForbiddenError +from superset.exceptions import SupersetSecurityException + + +@patch("superset.commands.chart.update.ChartDAO.find_by_id") +@patch("superset.commands.chart.update.security_manager") +def test_update_chart_ownership_enforced_for_query_context_update( + mock_sm: MagicMock, + mock_find_by_id: MagicMock, Review Comment: The decorator order means `mock_find_by_id` is the parameter that should map to the bottom-most decorator (`security_manager`), and vice versa. With `@patch` decorators, the bottom decorator is the first argument. As written, `mock_sm` actually receives the `find_by_id` mock and `mock_find_by_id` receives the `security_manager` mock, so `mock_find_by_id.return_value = MagicMock(...)` is configuring the security_manager mock, and `mock_sm.raise_for_ownership = MagicMock(side_effect=exc)` is setting an attribute on the find_by_id mock. The test may still pass coincidentally (because `find_by_id` returns a MagicMock truthy value and the real `security_manager` is not invoked at all in this test path — except it is), so verify by swapping the parameter names to `mock_find_by_id, mock_sm` matching decorator order. ########## tests/unit_tests/commands/chart/update_test.py: ########## @@ -0,0 +1,50 @@ +# 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. +from unittest.mock import MagicMock, patch + +import pytest + +from superset.commands.chart.exceptions import ChartForbiddenError +from superset.exceptions import SupersetSecurityException Review Comment: Imports of `UpdateChartCommand` and `SupersetError`/`ErrorLevel`/`SupersetErrorType` are placed inside the test function body (lines 32–33) while other imports are at module top. Move them to the top-level imports for consistency unless there is a specific circular-import reason to defer them. ########## tests/unit_tests/commands/chart/update_test.py: ########## @@ -0,0 +1,50 @@ +# 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. +from unittest.mock import MagicMock, patch + +import pytest + +from superset.commands.chart.exceptions import ChartForbiddenError +from superset.exceptions import SupersetSecurityException + + +@patch("superset.commands.chart.update.ChartDAO.find_by_id") +@patch("superset.commands.chart.update.security_manager") +def test_update_chart_ownership_enforced_for_query_context_update( Review Comment: Consider also adding a positive test (owner/admin succeeds for a query_context-only payload) and a test for a non-query-context update path to lock in that the ownership check still runs there. This prevents future regressions in either direction. -- 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]
