X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=tests%2Ftest_simadb.py;h=42e897d9126eded521fdde2470bc892b0337d2e8;hb=d81c669fc639184a61c7f9b514d179addbbddf17;hp=3be8758bf4448b17b6eca3ef8853761a9d4bbff3;hpb=5cbf72d42c713c5a719fa407e6969f0a84fdfe21;p=mpd-sima.git diff --git a/tests/test_simadb.py b/tests/test_simadb.py index 3be8758..42e897d 100644 --- a/tests/test_simadb.py +++ b/tests/test_simadb.py @@ -4,7 +4,7 @@ import datetime import unittest import os -from sima.lib.db import SimaDB +from sima.lib.simadb import SimaDB from sima.lib.track import Track from sima.lib.meta import Album, Artist, MetaContainer @@ -70,12 +70,12 @@ class Test_00DB(Main): def test_01_add_track(self): trk = Track(**DEVOLT) trk_id = self.db.get_track(trk) - self.assertEqual(trk_id, self.db.get_track(trk), + self.assertEqual(trk_id, self.db.get_track(trk, add=False), 'Same track, same record') def test_02_history(self): # set records in the past to ease purging then - last = CURRENT - datetime.timedelta(hours=1) + last = CURRENT - datetime.timedelta(seconds=5) trk = Track(**DEVOLT) self.db.add_history(trk, date=last) self.db.add_history(trk, date=last) @@ -168,6 +168,40 @@ class Test_00DB(Main): trk04.artist, trk03.artist], art_history) + 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): @@ -244,10 +278,14 @@ class Test_00DB(Main): self.assertIn(('fooart',), artists) conn.close() + def test_06_add_album(self): + pass class Test_01BlockList(Main): def test_blocklist_addition(self): + trk = Track(file='/foo/bar/baz', name='title') + self.assertIs(self.db.get_bl_track(trk, add=False), None) tracks_ids = list() # Set 6 records, same album for i in range(1, 6): # starts at 1 to ensure records are in the past @@ -255,16 +293,16 @@ class Test_01BlockList(Main): albumartist='fooalbart', album='foolbum',) # Add track, save its DB id tracks_ids.append(self.db.get_track(trk)) - # set records in the past to ease purging then - last = CURRENT - datetime.timedelta(minutes=i) - self.db.add_history(trk, date=last) # Add to history if i == 1: self.db.get_bl_track(trk) + self.assertIsNot(self.db.get_bl_track(trk, add=False), None) if i == 2: - self.db.get_bl_track(trk) self.db.get_bl_album(Album(name=trk.album)) if i == 3: self.db.get_bl_artist(trk.Artist) + if i == 4: + self.assertIs(self.db.get_bl_track(trk, add=False), None) + def test_blocklist_triggers_00(self): trk01 = Track(file='01', name='01', artist='artist A', album='album A') @@ -322,5 +360,16 @@ class Test_02Genre(Main): genre_hist = self.db.fetch_genres_history(limit=10) self.assertEqual([g[0] for g in genre_hist], genres[:10]) + def test_null_genres(self): + conn = self.db.get_database_connection() + genres = list() + for i in range(1, 2): # starts at 1 to ensure records are in the past + trk = Track(file=f'/foo/bar.{i}', name=f'{i}-baz', + album='foolbum', artist=f'{i}-art') + last = CURRENT - datetime.timedelta(minutes=i) + self.db.add_history(trk, date=last) + genre_hist = self.db.fetch_genres_history(limit=10) + self.assertEqual(genre_hist, []) + # VIM MODLINE # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8