Skip to content

Commit

Permalink
fix(alert|report): allow null on chart and dashboard field (apache#13680
Browse files Browse the repository at this point in the history
)

* allow null on chart and dashboard field

* update api test
  • Loading branch information
Lily Kuang authored and Allan Caetano de Oliveira committed May 21, 2021
1 parent 02b2305 commit 25443e0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions superset/reports/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class ReportSchedulePostSchema(Schema):
sql = fields.String(
description=sql_description, example="SELECT value FROM time_series_table"
)
chart = fields.Integer(required=False)
dashboard = fields.Integer(required=False)
chart = fields.Integer(required=False, allow_none=True)
dashboard = fields.Integer(required=False, allow_none=True)
database = fields.Integer(required=False)
owners = fields.List(fields.Integer(description=owners_description))
validator_type = fields.String(
Expand Down
55 changes: 54 additions & 1 deletion tests/reports/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,16 @@ def test_create_report_schedule_uniqueness(self):
db.session.delete(created_model)
db.session.commit()

@pytest.mark.usefixtures("create_report_schedules")
@pytest.mark.usefixtures(
"load_birth_names_dashboard_with_slices", "create_report_schedules"
)
def test_create_report_schedule_schema(self):
"""
ReportSchedule Api: Test create report schedule schema check
"""
self.login(username="admin")
chart = db.session.query(Slice).first()
dashboard = db.session.query(Dashboard).first()
example_db = get_example_database()

# Check that a report does not have a database reference
Expand Down Expand Up @@ -590,6 +593,56 @@ def test_create_report_schedule_schema(self):
rv = self.client.post(uri, json=report_schedule_data)
assert rv.status_code == 400

# Test that report can be created with null dashboard
report_schedule_data = {
"type": ReportScheduleType.ALERT,
"name": "new4",
"description": "description",
"crontab": "0 9 * * *",
"recipients": [
{
"type": ReportRecipientType.EMAIL,
"recipient_config_json": {"target": "target@superset.org"},
},
{
"type": ReportRecipientType.SLACK,
"recipient_config_json": {"target": "channel"},
},
],
"working_timeout": 3600,
"chart": chart.id,
"dashboard": None,
"database": example_db.id,
}
uri = "api/v1/report/"
rv = self.client.post(uri, json=report_schedule_data)
assert rv.status_code == 201

# Test that report can be created with null chart
report_schedule_data = {
"type": ReportScheduleType.ALERT,
"name": "new5",
"description": "description",
"crontab": "0 9 * * *",
"recipients": [
{
"type": ReportRecipientType.EMAIL,
"recipient_config_json": {"target": "target@superset.org"},
},
{
"type": ReportRecipientType.SLACK,
"recipient_config_json": {"target": "channel"},
},
],
"working_timeout": 3600,
"chart": None,
"dashboard": dashboard.id,
"database": example_db.id,
}
uri = "api/v1/report/"
rv = self.client.post(uri, json=report_schedule_data)
assert rv.status_code == 201

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_create_report_schedule_chart_dash_validation(self):
"""
Expand Down

0 comments on commit 25443e0

Please sign in to comment.