fix: store playback history per Discord server
This commit is contained in:
5 files changed
+74
-14
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from zyrarbot.music.history_entry import HistoryEntry
|
||||
from zyrarbot.storage.history_repository import HistoryRepository
|
||||
from zyrarbot.storage.json_file_store import JsonFileStore
|
||||
|
||||
|
||||
class HistoryRepositoryTest(unittest.TestCase):
|
||||
def test_history_is_stored_in_separate_files_and_legacy_data_is_migrated(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
legacy_path = Path(directory) / "history.json"
|
||||
entry = HistoryEntry(
|
||||
id="track-1",
|
||||
title="Track",
|
||||
url="https://example.test/track",
|
||||
duration=10,
|
||||
is_local=False,
|
||||
filepath=None,
|
||||
)
|
||||
legacy_path.write_text(json.dumps({"10": [entry.to_dict()]}), encoding="utf-8")
|
||||
repository = HistoryRepository(JsonFileStore(str(legacy_path)))
|
||||
|
||||
repository.migrate_legacy(10)
|
||||
|
||||
self.assertEqual(repository.list(10)[0].id, "track-1")
|
||||
self.assertEqual(repository.list(20), [])
|
||||
self.assertTrue((Path(directory) / "history" / "10.json").exists())
|
||||
self.assertFalse((Path(directory) / "history" / "20.json").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user