s
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import ast
|
||||
import asyncio
|
||||
import json
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -19,6 +20,15 @@ class _JsonRequest:
|
||||
return self._payload
|
||||
|
||||
|
||||
class _ReadRequest:
|
||||
headers: dict[str, str] = {}
|
||||
|
||||
class _Client:
|
||||
host = "127.0.0.1"
|
||||
|
||||
client = _Client()
|
||||
|
||||
|
||||
def _json_body(resp) -> dict[str, object]: # noqa: ANN001
|
||||
return json.loads(resp.body)
|
||||
|
||||
@@ -180,7 +190,7 @@ class WebDynamicProcessesTests(unittest.TestCase):
|
||||
with patch("web.allows_url_config", return_value=True):
|
||||
with patch("web.managed_url_config_relpath", return_value=rel):
|
||||
with patch("web._sync_youtube_pro_runtime_files", side_effect=AssertionError("unexpected resync")):
|
||||
payload = asyncio.run(web.get_url_config("youtube"))
|
||||
payload = asyncio.run(web.get_url_config(_ReadRequest(), process="youtube"))
|
||||
|
||||
self.assertEqual(_json_body(payload)["content"], "https://live.douyin.com/new\n")
|
||||
self.assertEqual(payload.headers.get("cache-control"), "no-store, max-age=0, must-revalidate")
|
||||
@@ -204,6 +214,26 @@ class WebDynamicProcessesTests(unittest.TestCase):
|
||||
self.assertEqual(_json_body(payload)["message"], "配置保存成功")
|
||||
self.assertEqual(captured[-1][0]["urlLines"], "https://live.douyin.com/fresh\n")
|
||||
|
||||
def test_save_url_config_returns_json_when_channel_store_readonly(self) -> None:
|
||||
channels = [{"id": "lane1", "name": "Lane 1", "pm2Name": "youtube2__lane1", "urlLines": "old\n"}]
|
||||
|
||||
with patch("web.allows_url_config", return_value=True):
|
||||
with patch("web.managed_url_config_relpath", return_value="URL_config.youtube2__lane1.ini"):
|
||||
with patch("web.governed_save_managed_file"):
|
||||
with patch("web.get_youtube_pro_channels", return_value=channels):
|
||||
with patch("web.set_youtube_pro_channels", side_effect=sqlite3.OperationalError("attempt to write a readonly database")):
|
||||
payload = asyncio.run(
|
||||
web.save_url_config(
|
||||
_JsonRequest({"content": "https://live.douyin.com/fresh\n"}),
|
||||
process="youtube2__lane1",
|
||||
)
|
||||
)
|
||||
|
||||
body = _json_body(payload)
|
||||
self.assertEqual(payload.status_code, 500)
|
||||
self.assertIn("多频道状态数据库写入失败", body["error"])
|
||||
self.assertIn("config", body["error"])
|
||||
|
||||
def test_save_config_updates_matching_youtube_pro_channel_stream_key(self) -> None:
|
||||
captured: list[list[dict[str, object]]] = []
|
||||
channels = [{"id": "lane1", "name": "Lane 1", "pm2Name": "youtube2__lane1", "streamKey": "old-key"}]
|
||||
|
||||
Reference in New Issue
Block a user