fix: remove standalone (#18157)
* removed standalone * Update tests/integration_tests/reports/commands_tests.py * changed standalone * added tests * made function more generic * Update superset/reports/notifications/email.py Co-authored-by: Beto Dealmeida <roberto@dealmeida.net> Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
This commit is contained in:
parent
4ad5ad045a
commit
fa11a97585
|
|
@ -30,6 +30,7 @@ from superset.models.reports import ReportRecipientType
|
|||
from superset.reports.notifications.base import BaseNotification
|
||||
from superset.reports.notifications.exceptions import NotificationError
|
||||
from superset.utils.core import send_email_smtp
|
||||
from superset.utils.urls import modify_url_query
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -94,6 +95,11 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
|
|||
html_table = ""
|
||||
|
||||
call_to_action = __("Explore in Superset")
|
||||
url = (
|
||||
modify_url_query(self._content.url, standalone="0")
|
||||
if self._content.url is not None
|
||||
else ""
|
||||
)
|
||||
img_tags = []
|
||||
for msgid in images.keys():
|
||||
img_tags.append(
|
||||
|
|
@ -122,7 +128,7 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
|
|||
</head>
|
||||
<body>
|
||||
<p>{description}</p>
|
||||
<b><a href="{self._content.url}">{call_to_action}</a></b><p></p>
|
||||
<b><a href="{url}">{call_to_action}</a></b><p></p>
|
||||
{html_table}
|
||||
{img_tag}
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -33,3 +33,18 @@ def headless_url(path: str, user_friendly: bool = False) -> str:
|
|||
def get_url_path(view: str, user_friendly: bool = False, **kwargs: Any) -> str:
|
||||
with current_app.test_request_context():
|
||||
return headless_url(url_for(view, **kwargs), user_friendly=user_friendly)
|
||||
|
||||
|
||||
def modify_url_query(url: str, **kwargs: Any) -> str:
|
||||
"""
|
||||
Replace or add parameters to a URL.
|
||||
"""
|
||||
parts = list(urllib.parse.urlsplit(url))
|
||||
params = urllib.parse.parse_qs(parts[3])
|
||||
for k, v in kwargs.items():
|
||||
if not isinstance(v, list):
|
||||
v = [v]
|
||||
params[k] = v
|
||||
|
||||
parts[3] = "&".join(f"{k}={urllib.parse.quote(v[0])}" for k, v in params.items())
|
||||
return urllib.parse.urlunsplit(parts)
|
||||
|
|
|
|||
|
|
@ -694,9 +694,9 @@ def test_email_chart_report_schedule(
|
|||
# assert that the link sent is correct
|
||||
assert (
|
||||
'<a href="http://0.0.0.0:8080/superset/explore/?'
|
||||
"form_data=%7B%22slice_id%22%3A+"
|
||||
"form_data=%7B%22slice_id%22%3A%20"
|
||||
f"{create_report_email_chart.chart.id}%7D&"
|
||||
'standalone=true&force=false">Explore in Superset</a>'
|
||||
'standalone=0&force=false">Explore in Superset</a>'
|
||||
in email_mock.call_args[0][2]
|
||||
)
|
||||
# Assert the email smtp address
|
||||
|
|
@ -737,9 +737,9 @@ def test_email_chart_report_schedule_force_screenshot(
|
|||
# assert that the link sent is correct
|
||||
assert (
|
||||
'<a href="http://0.0.0.0:8080/superset/explore/?'
|
||||
"form_data=%7B%22slice_id%22%3A+"
|
||||
"form_data=%7B%22slice_id%22%3A%20"
|
||||
f"{create_report_email_chart_force_screenshot.chart.id}%7D&"
|
||||
'standalone=true&force=true">Explore in Superset</a>'
|
||||
'standalone=0&force=true">Explore in Superset</a>'
|
||||
in email_mock.call_args[0][2]
|
||||
)
|
||||
# Assert the email smtp address
|
||||
|
|
@ -774,9 +774,9 @@ def test_email_chart_alert_schedule(
|
|||
# assert that the link sent is correct
|
||||
assert (
|
||||
'<a href="http://0.0.0.0:8080/superset/explore/?'
|
||||
"form_data=%7B%22slice_id%22%3A+"
|
||||
"form_data=%7B%22slice_id%22%3A%20"
|
||||
f"{create_alert_email_chart.chart.id}%7D&"
|
||||
'standalone=true&force=true">Explore in Superset</a>'
|
||||
'standalone=0&force=true">Explore in Superset</a>'
|
||||
in email_mock.call_args[0][2]
|
||||
)
|
||||
# Assert the email smtp address
|
||||
|
|
@ -842,9 +842,9 @@ def test_email_chart_report_schedule_with_csv(
|
|||
# assert that the link sent is correct
|
||||
assert (
|
||||
'<a href="http://0.0.0.0:8080/superset/explore/?'
|
||||
"form_data=%7B%22slice_id%22%3A+"
|
||||
"form_data=%7B%22slice_id%22%3A%20"
|
||||
f"{create_report_email_chart_with_csv.chart.id}%7D&"
|
||||
'standalone=true&force=false">Explore in Superset</a>'
|
||||
'standalone=0&force=false">Explore in Superset</a>'
|
||||
in email_mock.call_args[0][2]
|
||||
)
|
||||
# Assert the email smtp address
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# 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.
|
||||
from superset.utils.urls import modify_url_query
|
||||
|
||||
EXPLORE_CHART_LINK = "http://localhost:9000/superset/explore/?form_data=%7B%22slice_id%22%3A+76%7D&standalone=true&force=false"
|
||||
|
||||
EXPLORE_DASHBOARD_LINK = "http://localhost:9000/superset/dashboard/3/?standalone=3"
|
||||
|
||||
|
||||
def test_convert_chart_link() -> None:
|
||||
test_url = modify_url_query(EXPLORE_CHART_LINK, standalone="0")
|
||||
assert (
|
||||
test_url
|
||||
== "http://localhost:9000/superset/explore/?form_data=%7B%22slice_id%22%3A%2076%7D&standalone=0&force=false"
|
||||
)
|
||||
|
||||
|
||||
def test_convert_dashboard_link() -> None:
|
||||
test_url = modify_url_query(EXPLORE_DASHBOARD_LINK, standalone="0")
|
||||
assert test_url == "http://localhost:9000/superset/dashboard/3/?standalone=0"
|
||||
Loading…
Reference in New Issue