From 3975901e11cc892e929081536ee2ec9edbc157dc Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 5 Jan 2016 18:19:40 +0000 Subject: [PATCH 1/3] Fix search breakage --- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 2 +- openlp/plugins/remotes/html/openlp.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 3934ca53c..57a789ee2 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -960,7 +960,7 @@ class BibleMediaItem(MediaManagerItem): search_results = self.plugin.manager.get_verses(bible, string, False, showError) if search_results: verse_text = ' '.join([verse.text for verse in search_results]) - return [[string, verse_text]] + return [[string, verse_text, ""]] return [] def create_item_from_id(self, item_id): diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 248da94ea..85c5ace72 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -701,7 +701,7 @@ class ImageMediaItem(MediaManagerItem): results = [] for file_object in files: filename = os.path.split(str(file_object.filename))[1] - results.append([file_object.filename, filename]) + results.append([file_object.filename, filename, ""]) return results def create_item_from_id(self, item_id): diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index a5be8b25c..73a84649b 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -272,7 +272,7 @@ window.OpenLP = { value[0] = OpenLP.escapeString(value[0]) } var txt = ""; - if (value[2].length > 0) { + if (value.length > 2 && value[2].length > 0) { txt = value[1] + " ( " + value[2] + " )"; } else { txt = value[1]; From 2bbdf51aca27b6970e4cf68db9aca2ad9cde6455 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 5 Jan 2016 18:20:47 +0000 Subject: [PATCH 2/3] remove extra string --- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 57a789ee2..3934ca53c 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -960,7 +960,7 @@ class BibleMediaItem(MediaManagerItem): search_results = self.plugin.manager.get_verses(bible, string, False, showError) if search_results: verse_text = ' '.join([verse.text for verse in search_results]) - return [[string, verse_text, ""]] + return [[string, verse_text]] return [] def create_item_from_id(self, item_id): diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 85c5ace72..248da94ea 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -701,7 +701,7 @@ class ImageMediaItem(MediaManagerItem): results = [] for file_object in files: filename = os.path.split(str(file_object.filename))[1] - results.append([file_object.filename, filename, ""]) + results.append([file_object.filename, filename]) return results def create_item_from_id(self, item_id): From 8df7c3a9ead53723146cd2be0e213809567cb4a2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 5 Jan 2016 19:32:12 +0000 Subject: [PATCH 3/3] add tests --- openlp/plugins/remotes/html/openlp.js | 2 +- .../openlp_plugins/songs/test_mediaitem.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 73a84649b..128c78cb6 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -272,7 +272,7 @@ window.OpenLP = { value[0] = OpenLP.escapeString(value[0]) } var txt = ""; - if (value.length > 2 && value[2].length > 0) { + if (value.length > 2) { txt = value[1] + " ( " + value[2] + " )"; } else { txt = value[1]; diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index a19f7d704..bc6e56af5 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -257,3 +257,22 @@ class TestMediaItem(TestCase, TestMixin): # THEN: They should not match self.assertFalse(result, "Authors should not match") + + def build_remote_search_test(self): + """ + Test results for the remote search api + """ + # GIVEN: A Song and a search a JSON array should be returned. + mock_song = MagicMock() + mock_song.id = 123 + mock_song.title = 'My Song' + mock_song.search_title = 'My Song' + mock_song.alternate_title = 'My alternative' + self.media_item.search_entire = MagicMock() + self.media_item.search_entire.return_value = [mock_song] + + # WHEN: I process a search + search_results = self.media_item.search('My Song', False) + + # THEN: The correct formatted results are returned + self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])