codeant-ai-for-open-source[bot] commented on code in PR #39914:
URL: https://github.com/apache/superset/pull/39914#discussion_r3508329672
##########
tests/unit_tests/reports/notifications/slack_tests.py:
##########
@@ -431,3 +465,524 @@ def test_slack_mixin_get_body_truncates_large_table(
)
body = notification._get_body(content=content)
assert "(table was truncated)" in body
+
+
+# ---------------------------------------------------------------------------
+# Bulletproof v2 send-path coverage
+#
+# The tests above exercise the chat_postMessage path (text-only sends). The
+# tests below cover files_upload_v2 across screenshots/CSV/PDF, multi-channel
+# fan-out, exception mapping, backoff, statsd, and logs propagation. Together
+# they guarantee that every observable behavior of SlackV2Notification.send()
+# is locked down before Slack v1 is removed.
+# ---------------------------------------------------------------------------
+
+
+def _make_v2_notification(content, target: str = "C12345"):
+ """Helper to build a SlackV2Notification with a given target string."""
+ from superset.reports.models import ReportRecipients, ReportRecipientType
+
+ return SlackV2Notification(
+ recipient=ReportRecipients(
+ type=ReportRecipientType.SLACKV2,
+ recipient_config_json=f'{{"target": "{target}"}}',
+ ),
+ content=content,
+ )
+
+
+def _make_content(mock_header_data, **overrides):
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag missing type annotations for helper functions in test files
when the repository's test mypy settings explicitly allow untyped defs.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
tests/integration_tests/reports/commands_tests.py:
##########
@@ -1978,11 +1978,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,
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require type annotations for pytest fixture parameters or test
function signatures in test suites; test files are exempt from this typing
convention as long as the repository's test mypy/ruff configuration allows it.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
tests/unit_tests/reports/notifications/slack_tests.py:
##########
@@ -431,3 +465,524 @@ def test_slack_mixin_get_body_truncates_large_table(
)
body = notification._get_body(content=content)
assert "(table was truncated)" in body
+
+
+# ---------------------------------------------------------------------------
+# Bulletproof v2 send-path coverage
+#
+# The tests above exercise the chat_postMessage path (text-only sends). The
+# tests below cover files_upload_v2 across screenshots/CSV/PDF, multi-channel
+# fan-out, exception mapping, backoff, statsd, and logs propagation. Together
+# they guarantee that every observable behavior of SlackV2Notification.send()
+# is locked down before Slack v1 is removed.
+# ---------------------------------------------------------------------------
+
+
+def _make_v2_notification(content, target: str = "C12345"):
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require explicit type hints for helper functions in test code;
tests are exempt from the untyped-defs rule under the mypy overrides.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.<ext>`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
tests/unit_tests/reports/notifications/slack_tests.py:
##########
@@ -431,3 +465,524 @@ def test_slack_mixin_get_body_truncates_large_table(
)
body = notification._get_body(content=content)
assert "(table was truncated)" in body
+
+
+# ---------------------------------------------------------------------------
+# Bulletproof v2 send-path coverage
+#
+# The tests above exercise the chat_postMessage path (text-only sends). The
+# tests below cover files_upload_v2 across screenshots/CSV/PDF, multi-channel
+# fan-out, exception mapping, backoff, statsd, and logs propagation. Together
+# they guarantee that every observable behavior of SlackV2Notification.send()
+# is locked down before Slack v1 is removed.
+# ---------------------------------------------------------------------------
+
+
+def _make_v2_notification(content, target: str = "C12345"):
+ """Helper to build a SlackV2Notification with a given target string."""
+ from superset.reports.models import ReportRecipients, ReportRecipientType
+
+ return SlackV2Notification(
+ recipient=ReportRecipients(
+ type=ReportRecipientType.SLACKV2,
+ recipient_config_json=f'{{"target": "{target}"}}',
+ ),
+ content=content,
+ )
+
+
+def _make_content(mock_header_data, **overrides):
+ """Helper to build a minimal NotificationContent."""
+ from superset.reports.notifications.base import NotificationContent
+
+ defaults: dict = {
+ "name": "test alert",
+ "header_data": mock_header_data,
+ "description": "desc",
+ }
+ defaults.update(overrides)
+ return NotificationContent(**defaults)
+
+
+@patch("superset.reports.notifications.slackv2.g")
+@patch("superset.reports.notifications.slackv2.get_slack_client")
+def test_v2_send_with_single_screenshot_calls_files_upload_v2(
+ slack_client_mock: MagicMock,
+ flask_global_mock: MagicMock,
+ mock_header_data,
+) -> None:
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag missing type hints in test function signatures; test files are
exempt under the `tests.*` mypy override.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
tests/unit_tests/reports/notifications/slack_tests.py:
##########
@@ -431,3 +465,524 @@ def test_slack_mixin_get_body_truncates_large_table(
)
body = notification._get_body(content=content)
assert "(table was truncated)" in body
+
+
+# ---------------------------------------------------------------------------
+# Bulletproof v2 send-path coverage
+#
+# The tests above exercise the chat_postMessage path (text-only sends). The
+# tests below cover files_upload_v2 across screenshots/CSV/PDF, multi-channel
+# fan-out, exception mapping, backoff, statsd, and logs propagation. Together
+# they guarantee that every observable behavior of SlackV2Notification.send()
+# is locked down before Slack v1 is removed.
+# ---------------------------------------------------------------------------
+
+
+def _make_v2_notification(content, target: str = "C12345"):
+ """Helper to build a SlackV2Notification with a given target string."""
+ from superset.reports.models import ReportRecipients, ReportRecipientType
+
+ return SlackV2Notification(
+ recipient=ReportRecipients(
+ type=ReportRecipientType.SLACKV2,
+ recipient_config_json=f'{{"target": "{target}"}}',
+ ),
+ content=content,
+ )
+
+
+def _make_content(mock_header_data, **overrides):
+ """Helper to build a minimal NotificationContent."""
+ from superset.reports.notifications.base import NotificationContent
+
+ defaults: dict = {
+ "name": "test alert",
+ "header_data": mock_header_data,
+ "description": "desc",
+ }
+ defaults.update(overrides)
+ return NotificationContent(**defaults)
+
+
+@patch("superset.reports.notifications.slackv2.g")
+@patch("superset.reports.notifications.slackv2.get_slack_client")
+def test_v2_send_with_single_screenshot_calls_files_upload_v2(
+ slack_client_mock: MagicMock,
+ flask_global_mock: MagicMock,
+ mock_header_data,
+) -> None:
+ flask_global_mock.logs_context = {"execution_id": uuid.uuid4()}
+ content = _make_content(mock_header_data,
screenshots=[b"screenshot-bytes"])
+ notification = _make_v2_notification(content, target="C12345")
+
+ notification.send()
+
+ upload = slack_client_mock.return_value.files_upload_v2
+ upload.assert_called_once()
+ kwargs = upload.call_args.kwargs
+ assert kwargs["channel"] == "C12345"
+ assert kwargs["file"] == b"screenshot-bytes"
+ assert kwargs["title"] == "test alert"
+ assert kwargs["filename"] == "test alert.png"
+ assert "test alert" in kwargs["initial_comment"]
+ # chat_postMessage should NOT be called when files are present
+ slack_client_mock.return_value.chat_postMessage.assert_not_called()
+
+
+@patch("superset.reports.notifications.slackv2.g")
+@patch("superset.reports.notifications.slackv2.get_slack_client")
+def test_v2_send_with_multiple_screenshots_uploads_each(
+ slack_client_mock: MagicMock,
+ flask_global_mock: MagicMock,
+ mock_header_data,
+) -> None:
+ flask_global_mock.logs_context = {}
+ content = _make_content(
+ mock_header_data, screenshots=[b"shot-1", b"shot-2", b"shot-3"]
+ )
+ notification = _make_v2_notification(content, target="C12345")
+
+ notification.send()
+
+ upload = slack_client_mock.return_value.files_upload_v2
+ assert upload.call_count == 3
+ uploaded_files = [c.kwargs["file"] for c in upload.call_args_list]
+ assert uploaded_files == [b"shot-1", b"shot-2", b"shot-3"]
+ # All three uploads target the same single channel
+ for c in upload.call_args_list:
+ assert c.kwargs["channel"] == "C12345"
+ assert c.kwargs["filename"] == "test alert.png"
+
+
+@patch("superset.reports.notifications.slackv2.g")
+@patch("superset.reports.notifications.slackv2.get_slack_client")
+def test_v2_send_with_csv_calls_files_upload_v2(
+ slack_client_mock: MagicMock,
+ flask_global_mock: MagicMock,
+ mock_header_data,
+) -> None:
+ flask_global_mock.logs_context = {}
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag missing docstrings for self-describing test functions,
especially when the test name and assertions make the intent clear.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.<ext>`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]