+ def test_albums_history(self):
+ # set records in the past to ease purging then
+ last = CURRENT - datetime.timedelta(seconds=5)
+ track = {
+ 'album': 'album', 'title': 'title',
+ 'albumartist': 'albumartist',
+ 'artist': 'artist',
+ 'file': 'foo/bar.flac',
+ 'musicbrainz_albumartistid': 'd8e7e3e2-49ab-4f7c-b148-fc946d521f99',
+ 'musicbrainz_albumid': 'ea2ef2cf-59e1-443a-817e-9066e3e0be4b',
+ 'musicbrainz_artistid': 'd8e7e3e2-49ab-4f7c-b148-fc946d521f99',}
+ self.db.purge_history(duration=0)
+ self.db.add_history(Track(**track), last)
+ alb_history = self.db.fetch_albums_history()
+ alb = alb_history[0]
+ self.assertEqual(alb.Artist.name, track.get('albumartist'))
+ # Fetching Album history for "artist" should return "album"
+ artist = Artist(track.get('artist'), mbid=track.get('musicbrainz_artistid'))
+ alb_history = self.db.fetch_albums_history(artist)
+ self.assertTrue(alb_history)
+ # Falls back to album and MBID when albumartist and
+ # musicbrainz_albumartistid are not set
+ self.db.purge_history(duration=0)
+ track = {
+ 'album': 'no albumartist set', 'title': 'title',
+ 'artist': 'no album artist set',
+ 'file': 'bar/foo.flac',
+ 'musicbrainz_artistid': 'dddddddd-49ab-4f7c-b148-dddddddddddd',}
+ self.db.add_history(Track(**track), last)
+ alb_history = self.db.fetch_albums_history()
+ album = alb_history[0]
+ self.assertEqual(album.albumartist, track['artist'])
+ self.assertEqual(album.Artist.mbid, track['musicbrainz_artistid'])
+
+ def test_04_filtering_history(self):
+ # Controls artist history filtering
+ for i in range(0, 5):
+ trk = Track(file=f'/foo/bar.{i}', name=f'{i}-baz',
+ artist=f'{i}-art', album=f'{i}-lbum')
+ last = CURRENT - datetime.timedelta(minutes=i)
+ self.db.add_history(trk, date=last)
+ if i == 5: # bounce latest record
+ self.db.add_history(trk, date=last)
+ art_history = self.db.fetch_artists_history()
+ # Already checked but to be sure, we should have 5 artists in history
+ self.assertEqual(len(art_history), 5)
+ for needle in ['4-art', Artist(name='4-art')]:
+ art_history = self.db.fetch_artists_history(needle=needle)
+ self.assertEqual(art_history, [needle])
+ needle = Artist(name='not-art')
+ art_history = self.db.fetch_artists_history(needle=needle)
+ self.assertEqual(art_history, [])
+ # Controls artists history filtering
+ # for a list of Artist objects
+ needle_list = [Artist(name='3-art'), Artist(name='4-art')]
+ art_history = self.db.fetch_artists_history(needle=needle_list)
+ self.assertEqual(art_history, needle_list)
+ # for a MetaContainer
+ needle_meta = MetaContainer(needle_list)
+ art_history = self.db.fetch_artists_history(needle=needle_meta)
+ self.assertEqual(art_history, needle_list)
+ # for a list of string (Meta object handles Artist/str comparison)
+ art_history = self.db.fetch_artists_history(['3-art', '4-art'])
+ self.assertEqual(art_history, needle_list)
+
+ # Controls album history filtering
+ needle = Artist(name='4-art')
+ alb_history = self.db.fetch_albums_history(needle=needle)
+ self.assertEqual(alb_history, [Album(name='4-lbum')])
+
+ def test_05_triggers(self):