import pytest

# 导入实际的 SensitiveFilter 实现
from app.services.content.sensitive_filter import SensitiveFilter


def test_filter_politics_words():
    """政治敏感词被替换为占位符"""
    filter = SensitiveFilter()
    result = filter.filter(
        content="这是一个关于台湾问题的分析",
        platform="zhihu"
    )
    assert "**" in result.filtered_content
    assert len(result.found_words) > 0
    assert result.found_words[0].category == "politics"

def test_filter_medical_words():
    """医疗敏感词处理"""
    filter = SensitiveFilter()
    result = filter.filter(
        content="这个药品效果很好",
        platform="wechat"
    )
    # 医疗类敏感词应被检测
    assert result.found_words is not None

def test_filter_finance_words():
    """金融敏感词处理"""
    filter = SensitiveFilter()
    result = filter.filter(
        content="年化收益率10%",
        platform="zhihu"
    )
    # 金融敏感词检测
    assert result.found_words is not None

def test_filter_multiple_categories():
    """多分类同时过滤"""
    filter = SensitiveFilter()
    result = filter.filter(
        content="这是内容包含政治和医疗敏感词的内容",
        platform="wechat"
    )
    categories = [w.category for w in result.found_words]
    assert len(set(categories)) >= 1  # 至少检测到一个分类

def test_add_custom_words():
    """自定义敏感词添加"""
    filter = SensitiveFilter()
    filter.add_custom_words("custom", ["敏感词1", "敏感词2"])
    
    result = filter.filter(
        content="这是一段包含敏感词1的内容",
        platform="zhihu"
    )
    assert "敏感词1" not in result.filtered_content