X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=tests%2Ftest_simadb.py;h=c3e400deb00f7e35a57b6607be2c3b1020e8e39a;hb=6dc2257a2358877b8d1039791d046cf981e39b9f;hp=52e3e4409a53e36b088f13a7ce3075f9355cb243;hpb=798ce9e58b7725118a05245ddb723f6e909ded95;p=mpd-sima.git diff --git a/tests/test_simadb.py b/tests/test_simadb.py index 52e3e44..c3e400d 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 @@ -14,6 +14,7 @@ DEVOLT = { 'albumartist': 'Devolt', 'albumartistsort': 'Devolt', 'artist': 'Devolt', + 'genre': ['Rock'], 'date': '2011-12-01', 'disc': '1/1', 'file': 'music/Devolt/2011-Grey/03-Devolt - Crazy.mp3', @@ -69,7 +70,7 @@ 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): @@ -97,7 +98,8 @@ class Test_00DB(Main): # recent first, oldest last hist = list() for i in range(1, 5): # starts at 1 to ensure records are in the past - trk = Track(file=f'/foo/bar.{i}', name='{i}-baz', album='foolbum') + trk = Track(file=f'/foo/bar.{i}', name=f'{i}-baz', + album='foolbum', genre=f'{i}') hist.append(trk) last = CURRENT - datetime.timedelta(minutes=i) self.db.add_history(trk, date=last) @@ -246,6 +248,8 @@ class Test_00DB(Main): 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 @@ -253,16 +257,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') @@ -305,5 +309,31 @@ class Test_01BlockList(Main): conn.close() +class Test_02Genre(Main): + + def test_genre(self): + conn = self.db.get_database_connection() + self.db.get_genre('Post-Rock', with_connection=conn) + genres = list() + for i in range(1, 15): # 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', genre=f'{i}') + genres.append(f'{i}') + last = CURRENT - datetime.timedelta(minutes=i) + self.db.add_history(trk, date=last) + 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