feat(auth): separate read and write bilibili accounts
This commit is contained in:
1 parent
5c2ab7b187
commit
178ab64b18
17 files changed
+671
-707
No files matched your search
@@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""favsort 写账号配置隔离测试: uv run python tests/test_favsort_config.py"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
import favsort # noqa: E402
|
||||
|
||||
|
||||
def test_loads_write_account_only():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "config.json"
|
||||
path.write_text(json.dumps({
|
||||
"bilibili": {
|
||||
"read": {"mid": 11, "csrf": "read-csrf", "cookie": "read-cookie"},
|
||||
"write": {"mid": 22, "csrf": "write-csrf", "cookie": "write-cookie"},
|
||||
},
|
||||
"overrides": {"1": {"mid": 2, "name": "UP"}},
|
||||
}), encoding="utf-8")
|
||||
old = favsort.CONFIG_PATH
|
||||
favsort.CONFIG_PATH = str(path)
|
||||
try:
|
||||
cfg = favsort.load_config()
|
||||
finally:
|
||||
favsort.CONFIG_PATH = old
|
||||
assert cfg["mid"] == 22
|
||||
assert cfg["csrf"] == "write-csrf"
|
||||
assert cfg["cookie"] == "write-cookie"
|
||||
assert cfg["overrides"] == {"1": {"mid": 2, "name": "UP"}}
|
||||
|
||||
|
||||
def test_rejects_flat_config():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "config.json"
|
||||
path.write_text(json.dumps({"mid": 1, "csrf": "x", "cookie": "y"}), encoding="utf-8")
|
||||
old = favsort.CONFIG_PATH
|
||||
favsort.CONFIG_PATH = str(path)
|
||||
try:
|
||||
try:
|
||||
favsort.load_config()
|
||||
except SystemExit as exc:
|
||||
assert "bilibili.write" in str(exc)
|
||||
else:
|
||||
raise AssertionError("flat config 必须拒绝")
|
||||
finally:
|
||||
favsort.CONFIG_PATH = old
|
||||
|
||||
|
||||
def main():
|
||||
test_loads_write_account_only()
|
||||
test_rejects_flat_config()
|
||||
print("OK: favsort 仅使用 bilibili.write 配置测试全部通过")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user