docstr: ReportSchedule Api: Test create report schedule schema check
docstr_tok: ["ReportSchedule","Api",":","Test","create","report","schedule","schema","check"]
code: 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
      report_schedule_data = {
          "type": ReportScheduleType.REPORT,
          "name": "name3",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "crontab": "0 9 * * *",
          "chart": chart.id,
          "database": example_db.id,
      }
      uri = "api/v1/report/"
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 400
  
      # Test that report can be created with null grace period
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new3",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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,
          "database": example_db.id,
      }
      uri = "api/v1/report/"
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 201
  
      # Test that grace period and working timeout cannot be < 1
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new3",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "crontab": "0 9 * * *",
          "recipients": [
              {
                  "type": ReportRecipientType.EMAIL,
                  "recipient_config_json": {
                      "target": "target@superset.org"
                  },
              },
              {
                  "type": ReportRecipientType.SLACK,
                  "recipient_config_json": {"target": "channel"},
              },
          ],
          "working_timeout": -10,
          "chart": chart.id,
          "database": example_db.id,
      }
      uri = "api/v1/report/"
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 400
  
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new3",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "crontab": "0 9 * * *",
          "recipients": [
              {
                  "type": ReportRecipientType.EMAIL,
                  "recipient_config_json": {
                      "target": "target@superset.org"
                  },
              },
              {
                  "type": ReportRecipientType.SLACK,
                  "recipient_config_json": {"target": "channel"},
              },
          ],
          "grace_period": -10,
          "working_timeout": 3600,
          "chart": chart.id,
          "database": example_db.id,
      }
      uri = "api/v1/report/"
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 400
  
      # Test that report can be created with null dashboard
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new4",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 201
  
      # Test that report can be created with null chart
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new5",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 201
  
      # Test that report cannot be created with null timezone
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new5",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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,
          "timezone": None,
          "dashboard": dashboard.id,
          "database": example_db.id,
      }
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 400
      data = json.loads(rv.data.decode("utf-8"))
      assert data == {
          "message": {"timezone": ["Field may not be null."]}
      }
  
      # Test that report cannot be created with an invalid timezone
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new5",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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,
          "timezone": "this is not a timezone",
          "dashboard": dashboard.id,
          "database": example_db.id,
      }
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      assert rv.status_code == 400
      data = json.loads(rv.data.decode("utf-8"))
      assert data == {
          "message": {
              "timezone": [
                  f"Must be one of: {', '.join(pytz.all_timezones)}."
              ]
          }
      }
  
      # Test that report should reflect the timezone value passed in
      report_schedule_data = {
          "type": ReportScheduleType.ALERT,
          "name": "new6",
          "description": "description",
          "creation_method": ReportCreationMethod.ALERTS_REPORTS,
          "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,
          "timezone": "America/Los_Angeles",
          "dashboard": dashboard.id,
          "database": example_db.id,
      }
      uri = "api/v1/report/"
      rv = self.post_assert_metric(uri, report_schedule_data, "post")
      data = json.loads(rv.data.decode("utf-8"))
      assert data["result"]["timezone"] == "America/Los_Angeles"
      assert rv.status_code == 201
  
imports: from datetime import datetime
  import json
  import pytz
  import pytest
  import prison
  from parameterized import parameterized
  from sqlalchemy.sql import func
  from superset import db, security_manager
  from superset.models.core import Database
  from superset.models.slice import Slice
  from superset.models.dashboard import Dashboard
  from superset.reports.models import ReportSchedule, ReportCreationMethod, ReportRecipients, ReportExecutionLog, ReportScheduleType, ReportRecipientType, ReportState
  from superset.utils.database import get_example_database
  from tests.integration_tests.base_tests import SupersetTestCase
  from tests.integration_tests.conftest import with_feature_flags
  from tests.integration_tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices, load_birth_names_data
  from tests.integration_tests.reports.utils import insert_report_schedule
label_desc: Use image node_id 23 for calling the TestReportSchedulesApi obj's underlying member method code with example usage: obj.test_create_report_schedule_schema() without return types