forked from openlp/openlp
Merge branch 'fix-remote-search-bugs' into 'master'
Fix issues with searching from the web remote See merge request openlp/openlp!397
This commit is contained in:
commit
42cfb674e2
@ -73,6 +73,22 @@ class FolderLibraryItem(MediaManagerItem):
|
|||||||
self.add_folder_action.setText(UiStrings().AddFolder)
|
self.add_folder_action.setText(UiStrings().AddFolder)
|
||||||
self.add_folder_action.setToolTip(UiStrings().AddFolderDot)
|
self.add_folder_action.setToolTip(UiStrings().AddFolderDot)
|
||||||
|
|
||||||
|
def create_item_from_id(self, item_id):
|
||||||
|
"""
|
||||||
|
Create a media item from an item id.
|
||||||
|
|
||||||
|
:param item_id: Id to make live
|
||||||
|
"""
|
||||||
|
Item = self.item_class
|
||||||
|
if isinstance(item_id, (str, Path)):
|
||||||
|
# Probably a file name
|
||||||
|
item_data = self.manager.get_object_filtered(Item, Item.file_path == str(item_id))
|
||||||
|
else:
|
||||||
|
item_data = item_id
|
||||||
|
item = QtWidgets.QTreeWidgetItem()
|
||||||
|
item.setData(0, QtCore.Qt.UserRole, item_data)
|
||||||
|
return item
|
||||||
|
|
||||||
def on_add_folder_click(self):
|
def on_add_folder_click(self):
|
||||||
"""
|
"""
|
||||||
Called to add a new folder
|
Called to add a new folder
|
||||||
@ -355,7 +371,7 @@ class FolderLibraryItem(MediaManagerItem):
|
|||||||
:return: The search result.
|
:return: The search result.
|
||||||
"""
|
"""
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
items = self.manager.get_all_objects(self.item_class, self.item_class.file_path.match(string))
|
items = self.manager.get_all_objects(self.item_class, self.item_class.file_path.ilike('%' + string + '%'))
|
||||||
return [self.format_search_result(item) for item in items]
|
return [self.format_search_result(item) for item in items]
|
||||||
|
|
||||||
def validate_and_load(self, file_paths, target_folder=None):
|
def validate_and_load(self, file_paths, target_folder=None):
|
||||||
|
43
tests/openlp_core/ui/test_library.py
Normal file
43
tests/openlp_core/ui/test_library.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# ---------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2022 OpenLP Developers #
|
||||||
|
# ---------------------------------------------------------------------- #
|
||||||
|
# This program is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# This program is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License #
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
|
##########################################################################
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
|
from openlp.core.ui.library import FolderLibraryItem
|
||||||
|
|
||||||
|
|
||||||
|
def test_folderlibrary_create_item_from_id(registry, settings):
|
||||||
|
"""Test the create_item_from_id method"""
|
||||||
|
# GIVEN: An instance of the FolderLibraryItem
|
||||||
|
mocked_item = MagicMock()
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
mocked_manager.get_object_filtered.return_value = mocked_item
|
||||||
|
MockFolder = MagicMock()
|
||||||
|
MockItem = MagicMock()
|
||||||
|
library_item = FolderLibraryItem(None, MagicMock(manager=mocked_manager), MockFolder, MockItem)
|
||||||
|
|
||||||
|
# WHEN: create_item_from_id is called
|
||||||
|
result = library_item.create_item_from_id('path/to/video.mp4')
|
||||||
|
|
||||||
|
# THEN: The result should be a QTreeWidgetItem with a mocked object as data
|
||||||
|
assert isinstance(result, QtWidgets.QTreeWidgetItem)
|
||||||
|
assert result.data(0, QtCore.Qt.UserRole) is mocked_item
|
Loading…
Reference in New Issue
Block a user