forked from openlp/openlp
added SongBook name and Song Number to "Entire Song" Search
lp:~samothjtm/openlp/bug-1695587 (revision 2748) [SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/2076/ [SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1986/ [SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1902/ [SUCCESS] https://ci.openlp.io/job/Branch-04a-Code_Analysis/1280/ [SUCCESS] https://ci.openlp.io/job/Branch-04b-Test_Coverage/1130/ [SUCCESS] https://ci.openlp.io/job/Branch-04c-Code_Analysis2/259... bzr-revno: 2748
This commit is contained in:
commit
e37ef1b74b
@ -231,9 +231,14 @@ class SongMediaItem(MediaManagerItem):
|
||||
|
||||
def search_entire(self, search_keywords):
|
||||
search_string = '%{text}%'.format(text=clean_string(search_keywords))
|
||||
return self.plugin.manager.get_all_objects(
|
||||
Song, or_(Song.search_title.like(search_string), Song.search_lyrics.like(search_string),
|
||||
Song.comments.like(search_string)))
|
||||
return self.plugin.manager.session.query(Song) \
|
||||
.join(SongBookEntry, isouter=True) \
|
||||
.join(Book, isouter=True) \
|
||||
.filter(or_(Book.name.like(search_string), SongBookEntry.entry.like(search_string),
|
||||
# hint: search_title contains alternate title
|
||||
Song.search_title.like(search_string), Song.search_lyrics.like(search_string),
|
||||
Song.comments.like(search_string))) \
|
||||
.all()
|
||||
|
||||
def on_song_list_load(self):
|
||||
"""
|
||||
|
@ -46,9 +46,10 @@ class TestMediaItem(TestCase, TestMixin):
|
||||
Registry.create()
|
||||
Registry().register('service_list', MagicMock())
|
||||
Registry().register('main_window', MagicMock())
|
||||
self.mocked_plugin = MagicMock()
|
||||
with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \
|
||||
patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'):
|
||||
self.media_item = SongMediaItem(None, MagicMock())
|
||||
self.media_item = SongMediaItem(None, self.mocked_plugin)
|
||||
self.media_item.save_auto_select_id = MagicMock()
|
||||
self.media_item.list_view = MagicMock()
|
||||
self.media_item.list_view.save_auto_select_id = MagicMock()
|
||||
@ -558,3 +559,35 @@ class TestMediaItem(TestCase, TestMixin):
|
||||
|
||||
# THEN: The correct formatted results are returned
|
||||
self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])
|
||||
|
||||
@patch('openlp.plugins.songs.lib.mediaitem.Book')
|
||||
@patch('openlp.plugins.songs.lib.mediaitem.SongBookEntry')
|
||||
@patch('openlp.plugins.songs.lib.mediaitem.Song')
|
||||
@patch('openlp.plugins.songs.lib.mediaitem.or_')
|
||||
def test_entire_song_search(self, mocked_or, MockedSong, MockedSongBookEntry, MockedBook):
|
||||
"""
|
||||
Test that searching the entire song does the right queries
|
||||
"""
|
||||
# GIVEN: A song media item, a keyword and some mocks
|
||||
keyword = 'Jesus'
|
||||
mocked_song = MagicMock()
|
||||
mocked_or.side_effect = lambda a, b, c, d, e: ' '.join([a, b, c, d, e])
|
||||
MockedSong.search_title.like.side_effect = lambda a: a
|
||||
MockedSong.search_lyrics.like.side_effect = lambda a: a
|
||||
MockedSong.comments.like.side_effect = lambda a: a
|
||||
MockedSongBookEntry.entry.like.side_effect = lambda a: a
|
||||
MockedBook.name.like.side_effect = lambda a: a
|
||||
|
||||
# WHEN: search_entire_song() is called with the keyword
|
||||
self.media_item.search_entire(keyword)
|
||||
|
||||
# THEN: The correct calls were made
|
||||
MockedSong.search_title.like.assert_called_once_with('%jesus%')
|
||||
MockedSong.search_lyrics.like.assert_called_once_with('%jesus%')
|
||||
MockedSong.comments.like.assert_called_once_with('%jesus%')
|
||||
MockedSongBookEntry.entry.like.assert_called_once_with('%jesus%')
|
||||
MockedBook.name.like.assert_called_once_with('%jesus%')
|
||||
mocked_or.assert_called_once_with('%jesus%', '%jesus%', '%jesus%', '%jesus%', '%jesus%')
|
||||
self.mocked_plugin.manager.session.query.assert_called_once_with(MockedSong)
|
||||
|
||||
self.assertEqual(self.mocked_plugin.manager.session.query.mock_calls[4][0], '().join().join().filter().all')
|
||||
|
Loading…
Reference in New Issue
Block a user