db: Reload the New Tracks playlist at midnight
The New Tracks playlist shows tracks that have been added within the past week. We should automatically reload it a few seconds after midnight to keep it up to date as tracks drop off the list. Implements: #58 ("Reload New Tracks playlist at midnight") Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
17e4d85f1b
commit
3e73ce0650
|
@ -1,7 +1,9 @@
|
||||||
# Copyright 2022 (c) Anna Schumaker
|
# Copyright 2022 (c) Anna Schumaker
|
||||||
"""A custom Gio.ListModel for working with playlists."""
|
"""A custom Gio.ListModel for working with playlists."""
|
||||||
|
import datetime
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from gi.repository import GObject
|
from gi.repository import GObject
|
||||||
|
from .. import alarm
|
||||||
from . import playlist
|
from . import playlist
|
||||||
from . import tracks
|
from . import tracks
|
||||||
|
|
||||||
|
@ -57,6 +59,11 @@ class Table(playlist.Table):
|
||||||
def __init__(self, sql: GObject.TYPE_PYOBJECT, **kwargs):
|
def __init__(self, sql: GObject.TYPE_PYOBJECT, **kwargs):
|
||||||
"""Initialize the Playlists Table."""
|
"""Initialize the Playlists Table."""
|
||||||
super().__init__(sql=sql, system_tracks=False, **kwargs)
|
super().__init__(sql=sql, system_tracks=False, **kwargs)
|
||||||
|
alarm.set_alarm(datetime.time(hour=0, minute=0, second=5),
|
||||||
|
self.__at_midnight)
|
||||||
|
|
||||||
|
def __at_midnight(self) -> None:
|
||||||
|
self.new_tracks.reload_tracks()
|
||||||
|
|
||||||
def __move_user_trackid(self, playlist: Playlist, trackid: int,
|
def __move_user_trackid(self, playlist: Playlist, trackid: int,
|
||||||
*, offset: int) -> bool:
|
*, offset: int) -> bool:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Copyright 2022 (c) Anna Schumaker
|
# Copyright 2022 (c) Anna Schumaker
|
||||||
"""Tests our playlist Gio.ListModel."""
|
"""Tests our playlist Gio.ListModel."""
|
||||||
|
import datetime
|
||||||
import pathlib
|
import pathlib
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
import emmental.db
|
import emmental.db
|
||||||
|
@ -326,6 +327,18 @@ class TestSystemPlaylists(tests.util.TestCase):
|
||||||
pathlib.Path("/a/b/1.ogg"),
|
pathlib.Path("/a/b/1.ogg"),
|
||||||
self.medium, self.year)
|
self.medium, self.year)
|
||||||
|
|
||||||
|
def test_midnight_alarm(self):
|
||||||
|
"""Test playlist maintenance run every night at midnight."""
|
||||||
|
with unittest.mock.patch.object(self.table.new_tracks,
|
||||||
|
"reload_tracks") as mock_reload:
|
||||||
|
self.table._Table__at_midnight()
|
||||||
|
mock_reload.assert_called()
|
||||||
|
|
||||||
|
with unittest.mock.patch("emmental.alarm.set_alarm") as mock_set:
|
||||||
|
table2 = emmental.db.playlists.Table(self.sql)
|
||||||
|
mock_set.assert_called_with(datetime.time(second=5),
|
||||||
|
table2._Table__at_midnight)
|
||||||
|
|
||||||
def test_collection(self):
|
def test_collection(self):
|
||||||
"""Test the Collection playlist."""
|
"""Test the Collection playlist."""
|
||||||
self.assertIsInstance(self.table.collection,
|
self.assertIsInstance(self.table.collection,
|
||||||
|
|
Loading…
Reference in New Issue