Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 4 additions & 3 deletions dcoraid/gui/panel_find_data/widget_find_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions dcoraid/gui/status_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions tests/test_gui_find_data.py
Original file line number Diff line number Diff line change
@@ -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"
Loading