Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): remove unused webserver config & handle trailing slashes #22849

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ def _try_json_readsha(filepath: str, length: int) -> str | None:
# values may be "Last day", "Last week", "<ISO date> : now", etc.
DEFAULT_TIME_FILTER = NO_TIME_RANGE

SUPERSET_WEBSERVER_PROTOCOL = "http"
SUPERSET_WEBSERVER_ADDRESS = "0.0.0.0"
SUPERSET_WEBSERVER_PORT = 8088

# This is an important setting, and should be lower than your
# [load balancer / proxy / envoy / kong / ...] timeout settings.
# You should also make sure to configure your WSGI server
Expand Down
4 changes: 2 additions & 2 deletions superset/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from superset.tags.models import Tag, TaggedObject
from superset.utils.date_parser import parse_human_datetime
from superset.utils.machine_auth import MachineAuthProvider
from superset.utils.urls import get_url_path

logger = get_task_logger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -233,8 +234,7 @@
"""
result = {}
try:
baseurl = app.config["WEBDRIVER_BASEURL"]
url = f"{baseurl}api/v1/chart/warm_up_cache"
url = get_url_path("Superset.warm_up_cache")

Check warning on line 237 in superset/tasks/cache.py

View check run for this annotation

Codecov / codecov/patch

superset/tasks/cache.py#L237

Added line #L237 was not covered by tests
logger.info("Fetching %s with payload %s", url, data)
req = request.Request(
url, data=bytes(data, "utf-8"), headers=headers, method="PUT"
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/superset_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
DATA_DIR, "unittests.integration_tests.db"
)
DEBUG = False
SUPERSET_WEBSERVER_PORT = 8081
SILENCE_FAB = False
# Allowing SQLALCHEMY_DATABASE_URI and SQLALCHEMY_EXAMPLES_URI to be defined as an env vars for
# continuous integration
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/superset_test_config_thumbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
DATA_DIR, "unittests.integration_tests.db"
)
DEBUG = True
SUPERSET_WEBSERVER_PORT = 8081

# Allowing SQLALCHEMY_DATABASE_URI to be defined as an env var for
# continuous integration
Expand Down
58 changes: 58 additions & 0 deletions tests/integration_tests/tasks/test_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 unittest import mock

import pytest

from tests.integration_tests.test_app import app


@pytest.mark.parametrize(
"base_url",
[
"http://base-url",
"http://base-url/",
],
ids=["Without trailing slash", "With trailing slash"],
)
@mock.patch("superset.tasks.cache.request.Request")
@mock.patch("superset.tasks.cache.request.urlopen")
def test_fetch_url(mock_urlopen, mock_request_cls, base_url):
from superset.tasks.cache import fetch_url

mock_request = mock.MagicMock()
mock_request_cls.return_value = mock_request

mock_urlopen.return_value = mock.MagicMock()
mock_urlopen.return_value.code = 200

app.config["WEBDRIVER_BASEURL"] = base_url
headers = {"key": "value"}
data = "data"
data_encoded = b"data"

result = fetch_url(data, headers)

assert data == result["success"]
mock_request_cls.assert_called_once_with(
"http://base-url/superset/warm_up_cache/",
data=data_encoded,
headers=headers,
method="PUT",
)
# assert the same Request object is used
mock_urlopen.assert_called_once_with(mock_request, timeout=mock.ANY)
Loading