40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from src import hub_kv_store
|
|
|
|
|
|
class HubKvStoreTests(unittest.TestCase):
|
|
def test_youtube_pro_channels_round_trip_in_config_db(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
with patch.object(hub_kv_store, "CONFIG_DIR", Path(tmp) / "config"):
|
|
hub_kv_store.set_youtube_pro_channels(
|
|
[{"id": "lane1", "name": "Lane 1", "pm2Name": "youtube2__lane1"}]
|
|
)
|
|
|
|
rows = hub_kv_store.get_youtube_pro_channels()
|
|
|
|
self.assertEqual(rows[0]["id"], "lane1")
|
|
self.assertEqual(rows[0]["pm2Name"], "youtube2__lane1")
|
|
|
|
def test_youtube_pro_channel_write_retries_after_readonly_error(self) -> None:
|
|
with patch.object(
|
|
hub_kv_store,
|
|
"_write_youtube_pro_channels",
|
|
side_effect=[sqlite3.OperationalError("attempt to write a readonly database"), None],
|
|
) as write:
|
|
with patch.object(hub_kv_store, "_repair_permissions_best_effort") as repair:
|
|
hub_kv_store.set_youtube_pro_channels([{"id": "lane1", "name": "Lane 1"}])
|
|
|
|
self.assertEqual(write.call_count, 2)
|
|
self.assertGreaterEqual(repair.call_count, 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|