refactor(ReportModal): simplify state reducer and improve error handling (#19942)

This commit is contained in:
Jesse Yang
2022-05-05 10:06:40 -07:00
committed by GitHub
parent 58e65ad5bb
commit 7b88ec7e25
16 changed files with 317 additions and 315 deletions

View File

@@ -31,7 +31,7 @@ from superset.models.slice import Slice
from superset.models.dashboard import Dashboard
from superset.models.reports import (
ReportSchedule,
ReportCreationMethodType,
ReportCreationMethod,
ReportRecipients,
ReportExecutionLog,
ReportScheduleType,
@@ -452,7 +452,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "new3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"recipients": [
{
"type": ReportRecipientType.EMAIL,
@@ -499,7 +499,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "name3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"chart": chart.id,
"database": example_db.id,
@@ -508,7 +508,7 @@ class TestReportSchedulesApi(SupersetTestCase):
rv = self.client.post(uri, json=report_schedule_data)
assert rv.status_code == 422
data = json.loads(rv.data.decode("utf-8"))
assert data == {"message": {"name": ["Name must be unique"]}}
assert data == {"message": {"name": ['An alert named "name3" already exists']}}
# Check that uniqueness is composed by name and type
report_schedule_data = {
@@ -516,7 +516,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "name3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"chart": chart.id,
}
uri = "api/v1/report/"
@@ -546,7 +546,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"chart": chart.id,
"database": example_db.id,
@@ -560,7 +560,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -585,7 +585,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -609,7 +609,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -635,7 +635,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new4",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -661,7 +661,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new5",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -687,7 +687,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new5",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -714,7 +714,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new5",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -745,7 +745,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new6",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"recipients": [
{
@@ -784,7 +784,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name3",
"description": "description",
"creation_method": ReportCreationMethodType.CHARTS,
"creation_method": ReportCreationMethod.CHARTS,
"crontab": "0 9 * * *",
"chart": 0,
}
@@ -812,7 +812,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name3",
"description": "description",
"creation_method": ReportCreationMethodType.DASHBOARDS,
"creation_method": ReportCreationMethod.DASHBOARDS,
"crontab": "0 9 * * *",
}
uri = "api/v1/report/"
@@ -839,7 +839,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name4",
"description": "description",
"creation_method": ReportCreationMethodType.CHARTS,
"creation_method": ReportCreationMethod.CHARTS,
"crontab": "0 9 * * *",
"working_timeout": 3600,
"chart": chart.id,
@@ -855,7 +855,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name5",
"description": "description",
"creation_method": ReportCreationMethodType.CHARTS,
"creation_method": ReportCreationMethod.CHARTS,
"crontab": "0 9 * * *",
"working_timeout": 3600,
"chart": chart.id,
@@ -897,7 +897,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name4",
"description": "description",
"creation_method": ReportCreationMethodType.DASHBOARDS,
"creation_method": ReportCreationMethod.DASHBOARDS,
"crontab": "0 9 * * *",
"working_timeout": 3600,
"dashboard": dashboard.id,
@@ -913,7 +913,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.REPORT,
"name": "name5",
"description": "description",
"creation_method": ReportCreationMethodType.DASHBOARDS,
"creation_method": ReportCreationMethod.DASHBOARDS,
"crontab": "0 9 * * *",
"working_timeout": 3600,
"dashboard": dashboard.id,
@@ -956,7 +956,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "new3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"chart": chart.id,
"dashboard": dashboard.id,
"database": example_db.id,
@@ -980,7 +980,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"chart": chart.id,
}
@@ -1006,7 +1006,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"type": ReportScheduleType.ALERT,
"name": "new3",
"description": "description",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"crontab": "0 9 * * *",
"chart": chart_max_id + 1,
"database": database_max_id + 1,
@@ -1029,7 +1029,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "new3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"dashboard": dashboard_max_id + 1,
"database": examples_db.id,
}
@@ -1197,7 +1197,7 @@ class TestReportSchedulesApi(SupersetTestCase):
rv = self.client.put(uri, json=report_schedule_data)
data = json.loads(rv.data.decode("utf-8"))
assert rv.status_code == 422
assert data == {"message": {"name": ["Name must be unique"]}}
assert data == {"message": {"name": ['An alert named "name3" already exists']}}
@pytest.mark.usefixtures("create_report_schedules")
def test_update_report_schedule_not_found(self):
@@ -1546,7 +1546,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "new3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"recipients": [
{
"type": ReportRecipientType.EMAIL,
@@ -1581,7 +1581,7 @@ class TestReportSchedulesApi(SupersetTestCase):
"name": "new3",
"description": "description",
"crontab": "0 9 * * *",
"creation_method": ReportCreationMethodType.ALERTS_REPORTS,
"creation_method": ReportCreationMethod.ALERTS_REPORTS,
"recipients": [
{
"type": ReportRecipientType.EMAIL,