ForcePilot/backend/test/unit/channels/test_twitch_token_utils.py
Kris 3264900bc9 test: 新增多渠道单元测试用例并配置测试环境变量
新增了Twitch、Telegram、Discord、Slack、Mattermost、WeChat、Zalo等多渠道的单元测试用例,覆盖了令牌处理、速率限制、消息去重、会话解析、格式转换、安全策略等模块
同时在测试配置中添加了测试用的OpenAI API密钥环境变量
2026-05-12 00:56:47 +08:00

30 lines
900 B
Python

from __future__ import annotations
from yuxi.channels.adapters.twitch.token_utils import ensure_oauth_prefix, normalize_token
class TestEnsureOAuthPrefix:
def test_already_has_prefix(self):
assert ensure_oauth_prefix("oauth:abc123") == "oauth:abc123"
def test_adds_prefix_when_missing(self):
assert ensure_oauth_prefix("abc123") == "oauth:abc123"
def test_strips_whitespace(self):
assert ensure_oauth_prefix(" oauth:abc123 ") == "oauth:abc123"
def test_strips_and_adds(self):
assert ensure_oauth_prefix(" abc123 ") == "oauth:abc123"
def test_empty_token(self):
assert ensure_oauth_prefix("") == "oauth:"
class TestNormalizeToken:
def test_returns_prefixed(self):
assert normalize_token("abc") == "oauth:abc"
def test_preserves_existing_prefix(self):
assert normalize_token("oauth:abc") == "oauth:abc"