You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/07/06 23:47:30 UTC

[superset] branch fix-custom-width created (now ffbc14a1bc)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch fix-custom-width
in repository https://gitbox.apache.org/repos/asf/superset.git


      at ffbc14a1bc fix(report): edit without custom width

This branch includes the following new commits:

     new ffbc14a1bc fix(report): edit without custom width

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: fix(report): edit without custom width

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch fix-custom-width
in repository https://gitbox.apache.org/repos/asf/superset.git

commit ffbc14a1bc0b711978dff350fa97cc4155afb26b
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Jul 6 15:30:36 2023 -0700

    fix(report): edit without custom width
---
 superset/reports/schemas.py              | 16 +++++--
 tests/unit_tests/reports/__init__.py     | 16 +++++++
 tests/unit_tests/reports/schemas_test.py | 75 ++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/superset/reports/schemas.py b/superset/reports/schemas.py
index 7bdbf34f12..11ae5ebc89 100644
--- a/superset/reports/schemas.py
+++ b/superset/reports/schemas.py
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-from typing import Any, Union
+from typing import Any, Optional, Union
 
 from croniter import croniter
 from flask import current_app
@@ -220,7 +220,12 @@ class ReportSchedulePostSchema(Schema):
     )
 
     @validates("custom_width")
-    def validate_custom_width(self, value: int) -> None:  # pylint: disable=no-self-use
+    def validate_custom_width(
+        self, value: Optional[int]
+    ) -> None:  # pylint: disable=no-self-use
+        if value is None:
+            return
+
         min_width = current_app.config["ALERT_REPORTS_MIN_CUSTOM_SCREENSHOT_WIDTH"]
         max_width = current_app.config["ALERT_REPORTS_MAX_CUSTOM_SCREENSHOT_WIDTH"]
         if not min_width <= value <= max_width:
@@ -344,7 +349,12 @@ class ReportSchedulePutSchema(Schema):
     )
 
     @validates("custom_width")
-    def validate_custom_width(self, value: int) -> None:  # pylint: disable=no-self-use
+    def validate_custom_width(
+        self, value: Optional[int]
+    ) -> None:  # pylint: disable=no-self-use
+        if value is None:
+            return
+
         min_width = current_app.config["ALERT_REPORTS_MIN_CUSTOM_SCREENSHOT_WIDTH"]
         max_width = current_app.config["ALERT_REPORTS_MAX_CUSTOM_SCREENSHOT_WIDTH"]
         if not min_width <= value <= max_width:
diff --git a/tests/unit_tests/reports/__init__.py b/tests/unit_tests/reports/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/tests/unit_tests/reports/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/unit_tests/reports/schemas_test.py b/tests/unit_tests/reports/schemas_test.py
new file mode 100644
index 0000000000..0fab6d11b9
--- /dev/null
+++ b/tests/unit_tests/reports/schemas_test.py
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+from marshmallow import ValidationError
+from pytest_mock import MockFixture
+
+from superset.reports.schemas import ReportSchedulePostSchema, ReportSchedulePutSchema
+
+
+def test_report_post_schema_custom_width_validation(mocker: MockFixture) -> None:
+    """
+    Test the custom width validation.
+    """
+    current_app = mocker.patch("superset.reports.schemas.current_app")
+    current_app.config = {
+        "ALERT_REPORTS_MIN_CUSTOM_SCREENSHOT_WIDTH": 100,
+        "ALERT_REPORTS_MAX_CUSTOM_SCREENSHOT_WIDTH": 200,
+    }
+
+    schema = ReportSchedulePostSchema()
+
+    schema.load(
+        {
+            "type": "Report",
+            "name": "A report",
+            "description": "My report",
+            "active": True,
+            "crontab": "* * * * *",
+            "timezone": "America/Los_Angeles",
+            "custom_width": 100,
+        }
+    )
+
+    # not required
+    schema.load(
+        {
+            "type": "Report",
+            "name": "A report",
+            "description": "My report",
+            "active": True,
+            "crontab": "* * * * *",
+            "timezone": "America/Los_Angeles",
+        }
+    )
+
+    with pytest.raises(ValidationError) as excinfo:
+        schema.load(
+            {
+                "type": "Report",
+                "name": "A report",
+                "description": "My report",
+                "active": True,
+                "crontab": "* * * * *",
+                "timezone": "America/Los_Angeles",
+                "custom_width": 1000,
+            }
+        )
+    assert excinfo.value.messages == {
+        "custom_width": ["Screenshot width must be between 100px and 200px"]
+    }