fix: tests and linters
Panel / Lint, typy i build (pull_request) Successful in 25s
Backend / Testy i kontrakt API (pull_request) Successful in 31s
Backend / Lint i formatowanie (pull_request) Failing after 32s
Backend / Testowy build obrazu (pull_request) Skipped

This commit is contained in:
mmacierzanka committed 2026-10-01 13:59:19 +02:00
1 parent 0b1b448766
commit 56e3ddba8a
7 files changed
+122 -131

No files matched your search

+35 -38
View File
@@ -1,52 +1,49 @@
import json
import tempfile
from __future__ import annotations
import unittest
from pathlib import Path
from unittest.mock import MagicMock
from zyrarbot.music.history_entry import HistoryEntry
from zyrarbot.storage.history_repository import HistoryRepository
from zyrarbot.storage.json_file_store import JsonFileStore
from zyrarbot.storage.adapters.postgres.history import PostgresHistory
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)))
def setUp(self):
self.database = MagicMock()
self.connection = self.database.connect.return_value.__enter__.return_value
self.repository = PostgresHistory(self.database)
repository.migrate_legacy(10)
def test_list_maps_database_rows_to_history_entries(self):
self.connection.execute.return_value.fetchall.return_value = [
("track-1", "Track", "https://example.test/track", 10, False)
]
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())
self.assertEqual(
self.repository.list(10),
[
HistoryEntry(
id="track-1",
title="Track",
url="https://example.test/track",
duration=10,
is_local=False,
)
],
)
def test_new_entries_are_available_after_repository_reload(self):
with tempfile.TemporaryDirectory() as directory:
store = JsonFileStore(str(Path(directory) / "history.json"))
entry = HistoryEntry(
id="track-2",
title="Another track",
url="https://example.test/another-track",
)
def test_add_ignores_entries_without_a_title(self):
self.repository.add(10, HistoryEntry(id="track-1", title=""))
HistoryRepository(store).add(42, entry)
self.database.connect.assert_not_called()
reloaded = HistoryRepository(store)
self.assertEqual(reloaded.list(42), [entry])
persisted = json.loads(
(Path(directory) / "history" / "42.json").read_text(encoding="utf-8")
)
self.assertEqual(persisted["entries"][0]["id"], "track-2")
def test_add_persists_entry_for_guild(self):
self.connection.execute.return_value.fetchall.return_value = []
entry = HistoryEntry(id="track-1", title="Track", url="https://example.test/track")
self.repository.add(10, entry)
statements = [call.args[0] for call in self.connection.execute.call_args_list]
self.assertTrue(any("INSERT INTO history_entries" in statement for statement in statements))
if __name__ == "__main__":