From 5f39860335021e21f539cbf48cd5bbc1dee6e7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Fri, 23 Oct 2026 10:48:33 +0200 Subject: [PATCH] fix: use API server URL for site title in "Find data" tab `WidgetFindData` passed the server from the settings to `StatusWidget.get_title`. In the playground, the server is stored without scheme ("dcor-dev.mpl.mpg.de"), so fetching the site title failed with `MissingSchema`. Use `get_ckan_api().server` instead, which contains the correct scheme (https by default, or http if configured, e.g. for local test environments), like the status widget already does. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG | 2 + .../gui/panel_find_data/widget_find_data.py | 7 ++-- dcoraid/gui/status_widget.py | 8 ++++ tests/test_gui_find_data.py | 40 +++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 tests/test_gui_find_data.py diff --git a/CHANGELOG b/CHANGELOG index 3e50891..55ec669 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,8 @@ limits `all_fields` list results to 25 items) - fix: datasets shared with the user were searched in all circles and collections instead of only those the user is a member of + - fix: "Find data" tab failed to fetch the site title when the server + was stored without scheme (e.g. in the playground) - enh: automatically create a new DCOR-dev user in the playground user scenario if the previous user was purged - enh: `dcoraid-upload-task` reads the API key from the `DCOR_API_KEY` diff --git a/dcoraid/gui/panel_find_data/widget_find_data.py b/dcoraid/gui/panel_find_data/widget_find_data.py index e4afde8..22b3b24 100644 --- a/dcoraid/gui/panel_find_data/widget_find_data.py +++ b/dcoraid/gui/panel_find_data/widget_find_data.py @@ -2,6 +2,7 @@ from PyQt6 import QtCore, QtWidgets +from ..api import get_ckan_api from ..status_widget import StatusWidget from .widget_find_data_ui import Ui_Form @@ -18,9 +19,9 @@ def __init__(self, *args, **kwargs): self.ui = Ui_Form() self.ui.setupUi(self) - settings = QtCore.QSettings() - server = settings.value("auth/server", "dcor.mpl.mpg.de") - title = StatusWidget.get_title(server) + # Use the server URL of the API, which contains the scheme + # (the server might be stored without scheme in the settings). + title = StatusWidget.get_title(get_ckan_api().server) self.ui.label_search.setText(f"Search {title or 'DCOR'}") self.database = None diff --git a/dcoraid/gui/status_widget.py b/dcoraid/gui/status_widget.py index 1ce91a2..a676285 100644 --- a/dcoraid/gui/status_widget.py +++ b/dcoraid/gui/status_widget.py @@ -55,6 +55,10 @@ def __init__(self, *args, **kwargs): @staticmethod def get_favicon(server): + """Return the favicon of `server` (e.g. `CKANAPI.server`) + + The `server` must be a URL including the scheme. + """ dldir = pathlib.Path( QtCore.QStandardPaths.writableLocation( QtCore.QStandardPaths.StandardLocation.AppDataLocation) @@ -83,6 +87,10 @@ def get_favicon(server): @staticmethod def get_title(server): + """Return the site title of `server` (e.g. `CKANAPI.server`) + + The `server` must be a URL including the scheme. + """ dldir = pathlib.Path( QtCore.QStandardPaths.writableLocation( QtCore.QStandardPaths.StandardLocation.AppDataLocation) diff --git a/tests/test_gui_find_data.py b/tests/test_gui_find_data.py new file mode 100644 index 0000000..5d18a91 --- /dev/null +++ b/tests/test_gui_find_data.py @@ -0,0 +1,40 @@ +"""Offline tests for the "Find data" panel""" +from unittest import mock + +import pytest +from PyQt6 import QtCore + +import dcoraid.gui.api +from dcoraid.gui.panel_find_data import widget_find_data + + +@pytest.fixture +def server_settings(): + """Use separate settings for testing and restore the original ones""" + app_name = QtCore.QCoreApplication.applicationName() + QtCore.QCoreApplication.setApplicationName("dcoraid-test-find-data") + settings = QtCore.QSettings() + settings.clear() + dcoraid.gui.api._CKAN_API = None + yield settings + settings.clear() + settings.sync() + QtCore.QCoreApplication.setApplicationName(app_name) + dcoraid.gui.api._CKAN_API = None + + +@pytest.mark.parametrize("server,url", [ + # The playground stores the server without scheme. + ["dcor-dev.mpl.mpg.de", "https://dcor-dev.mpl.mpg.de"], + # Local test environments might only support HTTP. + ["http://192.168.122.143", "http://192.168.122.143"], +]) +def test_find_data_title_uses_api_server(qtbot, server_settings, server, + url): + server_settings.setValue("auth/server", server) + with mock.patch.object(widget_find_data.StatusWidget, "get_title", + return_value="DCOR Test") as get_title: + widget = widget_find_data.WidgetFindData() + qtbot.addWidget(widget) + get_title.assert_called_once_with(url) + assert widget.ui.label_search.text() == "Search DCOR Test"