From dcfb70d1bd441aecde2feefc044727b9fd7a106b Mon Sep 17 00:00:00 2001 From: Joe Li Date: Wed, 6 May 2026 16:02:37 -0700 Subject: [PATCH] test(reports): mock get_channels_with_search in slack token-callable test With ALERT_REPORT_SLACK_V2 now defaulting to True, a SLACK recipient's first send triggers the v1->v2 auto-upgrade, which calls get_channels_with_search to resolve channel names to channel IDs. The existing test mocked WebClient.conversations_list to return a plain dict that lacked the `.data` attribute the upgrade path reads, so the upgrade raised "'dict' object has no attribute 'data'" and the test errored. Patch get_channels_with_search directly (matching the pattern already used by the other v2-conversion tests in this file) so the upgrade can resolve channels without going through the WebClient mock plumbing. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/integration_tests/reports/commands_tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index ae1c855d85a..67e0ae2f6fc 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -1975,11 +1975,13 @@ def test_slack_chart_alert_no_attachment(email_mock, create_alert_email_chart): "load_birth_names_dashboard_with_slices", "create_report_slack_chart", ) +@patch("superset.commands.report.execute.get_channels_with_search") @patch("superset.utils.slack.WebClient") @patch("superset.utils.screenshots.ChartScreenshot.get_screenshot") def test_slack_token_callable_chart_report( screenshot_mock, slack_client_mock_class, + get_channels_with_search_mock, create_report_slack_chart, ): """ @@ -1990,9 +1992,20 @@ def test_slack_token_callable_chart_report( channel_name = notification_targets[0] channel_id = "channel_id" slack_client_mock_class.return_value = Mock() + # should_use_v2_api() probes via conversations_list(); a non-erroring return + # is enough — it doesn't read the response body. The v2 upgrade then resolves + # channel names through get_channels_with_search, which we mock directly. slack_client_mock_class.return_value.conversations_list.return_value = { "channels": [{"id": channel_id, "name": channel_name}] } + get_channels_with_search_mock.return_value = [ + { + "id": channel_id, + "name": channel_name, + "is_member": True, + "is_private": False, + } + ] slack_token_mock = Mock(return_value="cool_code") with patch.dict("flask.current_app.config", {"SLACK_API_TOKEN": slack_token_mock}):