Added tests for cache status detection
This commit is contained in:
@@ -685,6 +685,7 @@ class FilesystemAdapter(CachingAdapter):
|
|||||||
cache_info_extra["file_id"] = params[0]
|
cache_info_extra["file_id"] = params[0]
|
||||||
|
|
||||||
elif data_key == KEYS.SONG_FILE_PERMANENT:
|
elif data_key == KEYS.SONG_FILE_PERMANENT:
|
||||||
|
data_key = KEYS.SONG_FILE
|
||||||
cache_info_extra["cache_permanently"] = True
|
cache_info_extra["cache_permanently"] = True
|
||||||
|
|
||||||
# Set the cache info.
|
# Set the cache info.
|
||||||
@@ -711,7 +712,7 @@ class FilesystemAdapter(CachingAdapter):
|
|||||||
cache_info.save()
|
cache_info.save()
|
||||||
|
|
||||||
# Special handling for Song
|
# Special handling for Song
|
||||||
if data_key == KEYS.SONG_FILE:
|
if data_key == KEYS.SONG_FILE and data:
|
||||||
path, buffer_filename = data
|
path, buffer_filename = data
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
|
@@ -842,6 +842,19 @@ class AdapterManager:
|
|||||||
|
|
||||||
return Result(do_batch_download_songs, is_download=True, on_cancel=on_cancel)
|
return Result(do_batch_download_songs, is_download=True, on_cancel=on_cancel)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def batch_permanently_cache_songs(
|
||||||
|
song_ids: Sequence[str],
|
||||||
|
before_download: Callable[[str], None],
|
||||||
|
on_song_download_complete: Callable[[str], None],
|
||||||
|
) -> Result[None]:
|
||||||
|
assert AdapterManager._instance
|
||||||
|
# This only really makes sense if we have a caching_adapter.
|
||||||
|
if not AdapterManager._instance.caching_adapter:
|
||||||
|
return Result(None)
|
||||||
|
# TODO ACTUALLY IMPLEMENT THIS
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def batch_delete_cached_songs(
|
def batch_delete_cached_songs(
|
||||||
song_ids: Sequence[str], on_song_delete: Callable[[str], None]
|
song_ids: Sequence[str], on_song_delete: Callable[[str], None]
|
||||||
|
@@ -9,7 +9,7 @@ import pytest
|
|||||||
|
|
||||||
from peewee import SelectQuery
|
from peewee import SelectQuery
|
||||||
|
|
||||||
from sublime.adapters import api_objects as SublimeAPI, CacheMissError
|
from sublime.adapters import api_objects as SublimeAPI, CacheMissError, SongCacheStatus
|
||||||
from sublime.adapters.filesystem import FilesystemAdapter
|
from sublime.adapters.filesystem import FilesystemAdapter
|
||||||
from sublime.adapters.subsonic import api_objects as SubsonicAPI
|
from sublime.adapters.subsonic import api_objects as SubsonicAPI
|
||||||
|
|
||||||
@@ -374,6 +374,43 @@ def test_malformed_song_path(cache_adapter: FilesystemAdapter):
|
|||||||
assert song_uri2.endswith("fine/path/song2.mp3")
|
assert song_uri2.endswith("fine/path/song2.mp3")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_cached_status(cache_adapter: FilesystemAdapter):
|
||||||
|
print('ohea1')
|
||||||
|
cache_adapter.ingest_new_data(KEYS.SONG, ("1",), MOCK_SUBSONIC_SONGS[1])
|
||||||
|
assert (
|
||||||
|
cache_adapter.get_cached_status(cache_adapter.get_song_details("1"))
|
||||||
|
== SongCacheStatus.NOT_CACHED
|
||||||
|
)
|
||||||
|
|
||||||
|
print('ohea2')
|
||||||
|
cache_adapter.ingest_new_data(KEYS.SONG_FILE, ("1",), (None, MOCK_SONG_FILE))
|
||||||
|
assert (
|
||||||
|
cache_adapter.get_cached_status(cache_adapter.get_song_details("1"))
|
||||||
|
== SongCacheStatus.CACHED
|
||||||
|
)
|
||||||
|
|
||||||
|
print('ohea3')
|
||||||
|
cache_adapter.ingest_new_data(KEYS.SONG_FILE_PERMANENT, ("1",), None)
|
||||||
|
assert (
|
||||||
|
cache_adapter.get_cached_status(cache_adapter.get_song_details("1"))
|
||||||
|
== SongCacheStatus.PERMANENTLY_CACHED
|
||||||
|
)
|
||||||
|
|
||||||
|
print('ohea4')
|
||||||
|
cache_adapter.invalidate_data(KEYS.SONG_FILE, ("1",))
|
||||||
|
assert (
|
||||||
|
cache_adapter.get_cached_status(cache_adapter.get_song_details("1"))
|
||||||
|
== SongCacheStatus.CACHED_STALE
|
||||||
|
)
|
||||||
|
|
||||||
|
print('ohea5')
|
||||||
|
cache_adapter.delete_data(KEYS.SONG_FILE, ("1",))
|
||||||
|
assert (
|
||||||
|
cache_adapter.get_cached_status(cache_adapter.get_song_details("1"))
|
||||||
|
== SongCacheStatus.NOT_CACHED
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_playlists(cache_adapter: FilesystemAdapter):
|
def test_delete_playlists(cache_adapter: FilesystemAdapter):
|
||||||
cache_adapter.ingest_new_data(
|
cache_adapter.ingest_new_data(
|
||||||
KEYS.PLAYLIST_DETAILS,
|
KEYS.PLAYLIST_DETAILS,
|
||||||
|
Reference in New Issue
Block a user