EnxDev commented on code in PR #38711:
URL: https://github.com/apache/superset/pull/38711#discussion_r2954881477
##########
tests/integration_tests/reports/api_tests.py:
##########
@@ -1527,6 +1527,177 @@ def test_update_report_schedule(self):
assert updated_model.chart_id == report_schedule_data["chart"]
assert updated_model.database_id == report_schedule_data["database"]
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_clear_recipients(self):
+ """
+ ReportSchedule API: clear recipients on empty list
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ assert len(report_schedule.recipients) == 2
+
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [],
+ }
+
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 200
+ db.session.expire(report_schedule)
+ assert report_schedule.recipients == []
+
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_empty_email_target(self):
+ """
+ ReportSchedule API: Test update with empty email target returns 400
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [
+ {
+ "type": ReportRecipientType.EMAIL,
+ "recipient_config_json": {"target": ""},
+ }
+ ],
+ }
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 400
+
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_invalid_email(self):
+ """
+ ReportSchedule API: Test update with invalid email returns 400
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [
+ {
+ "type": ReportRecipientType.EMAIL,
+ "recipient_config_json": {"target": "notanemail"},
+ }
+ ],
+ }
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 400
+
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_invalid_cc_email(self):
+ """
+ ReportSchedule API: Test update with invalid ccTarget
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [
+ {
+ "type": ReportRecipientType.EMAIL,
+ "recipient_config_json": {
+ "target": "[email protected]",
+ "ccTarget": "bademail",
+ },
+ }
+ ],
+ }
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 400
+
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_invalid_bcc_email(self):
+ """
+ ReportSchedule API: Test update with invalid bccTarget
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [
+ {
+ "type": ReportRecipientType.EMAIL,
+ "recipient_config_json": {
+ "target": "[email protected]",
+ "bccTarget": "bademail",
+ },
+ }
+ ],
+ }
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 400
+
+ @pytest.mark.usefixtures("create_report_schedules")
+ def test_update_report_schedule_slack_empty_target_allowed(self):
+ """
+ ReportSchedule API: Test that Slack recipients skip email validation
+ """
+ report_schedule = (
+ db.session.query(ReportSchedule)
+ .filter(ReportSchedule.name == "name2")
+ .one_or_none()
+ )
+ self.login(ADMIN_USERNAME)
+ report_schedule_data = {
+ "recipients": [
+ {
+ "type": ReportRecipientType.SLACK,
+ "recipient_config_json": {"target": ""},
+ }
+ ],
+ }
+ uri = f"api/v1/report/{report_schedule.id}"
+ rv = self.put_assert_metric(uri, report_schedule_data, "put")
+ assert rv.status_code == 200
Review Comment:
This test verifies that email validation is scoped to type == "Email" only,
as intended.
Slack recipient validation is a separate concern Slack targets use channel
names/IDs, not email addresses, and have their own validation path during
delivery.
Adding Slack target validation is out of scope for this PR.
--
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]