mirror of
https://github.com/beetbox/beets.git
synced 2026-07-16 10:37:00 -04:00
Add support for filtering relations
This commit is contained in:
@@ -521,7 +521,7 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
|
||||
self.assert_items_matched(results, ["path item"])
|
||||
|
||||
results = self.lib.albums(q)
|
||||
self.assert_albums_matched(results, [])
|
||||
self.assert_albums_matched(results, ["path album"])
|
||||
|
||||
# FIXME: fails on windows
|
||||
@unittest.skipIf(sys.platform == "win32", "win32")
|
||||
@@ -604,6 +604,9 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
|
||||
results = self.lib.items(q)
|
||||
self.assert_items_matched(results, ["path item"])
|
||||
|
||||
results = self.lib.albums(q)
|
||||
self.assert_albums_matched(results, ["path album"])
|
||||
|
||||
def test_path_album_regex(self):
|
||||
q = "path::b"
|
||||
results = self.lib.albums(q)
|
||||
@@ -1126,6 +1129,41 @@ class NotQueryTest(DummyDataTestCase):
|
||||
pass
|
||||
|
||||
|
||||
class RelatedQueriesTest(_common.TestCase, AssertsMixin):
|
||||
"""Test album-level queries with track-level filters and vice-versa."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.lib = beets.library.Library(":memory:")
|
||||
|
||||
albums = []
|
||||
for album_idx in range(1, 3):
|
||||
album_name = f"Album{album_idx}"
|
||||
album_items = []
|
||||
for item_idx in range(1, 3):
|
||||
item = _common.item()
|
||||
item.album = album_name
|
||||
item.title = f"{album_name} Item{item_idx}"
|
||||
self.lib.add(item)
|
||||
album_items.append(item)
|
||||
album = self.lib.add_album(album_items)
|
||||
album.artpath = f"{album_name} Artpath"
|
||||
album.store()
|
||||
albums.append(album)
|
||||
|
||||
self.album, self.another_album = albums
|
||||
|
||||
def test_get_albums_filter_by_track_field(self):
|
||||
q = "title:Album1"
|
||||
results = self.lib.albums(q)
|
||||
self.assert_albums_matched(results, ["Album1"])
|
||||
|
||||
def test_get_items_filter_by_album_field(self):
|
||||
q = "artpath::Album1"
|
||||
results = self.lib.items(q)
|
||||
self.assert_items_matched(results, ["Album1 Item1", "Album1 Item2"])
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user