Files
zyrarbot/tests/test_history_repository.py
T
mmacierzanka 56e3ddba8a
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
fix: tests and linters
2026-10-01 13:59:19 +02:00

51 lines
1.7 KiB
Python

from __future__ import annotations
import unittest
from unittest.mock import MagicMock
from zyrarbot.music.history_entry import HistoryEntry
from zyrarbot.storage.adapters.postgres.history import PostgresHistory
class HistoryRepositoryTest(unittest.TestCase):
def setUp(self):
self.database = MagicMock()
self.connection = self.database.connect.return_value.__enter__.return_value
self.repository = PostgresHistory(self.database)
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(
self.repository.list(10),
[
HistoryEntry(
id="track-1",
title="Track",
url="https://example.test/track",
duration=10,
is_local=False,
)
],
)
def test_add_ignores_entries_without_a_title(self):
self.repository.add(10, HistoryEntry(id="track-1", title=""))
self.database.connect.assert_not_called()
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__":
unittest.main()