feat: 添加 NotificationService 通知服务 + 测试
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from app.services.notification_service import NotificationService
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_notification_send():
|
||||
svc = NotificationService()
|
||||
announcements = [
|
||||
{
|
||||
"title": "测试公告",
|
||||
"publish_date": None,
|
||||
"purchase_name": "测试单位",
|
||||
"content_url": "https://x.com/1",
|
||||
"source_code": "test",
|
||||
"source_name": "测试来源",
|
||||
"announcement_type": "purchase",
|
||||
}
|
||||
]
|
||||
|
||||
with patch.object(svc.client, "send_textcard", AsyncMock(return_value=True)):
|
||||
count = await svc.send(announcements)
|
||||
assert count == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_notification_send_empty():
|
||||
svc = NotificationService()
|
||||
count = await svc.send([])
|
||||
assert count == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_notification_send_disabled():
|
||||
svc = NotificationService()
|
||||
announcements = [{"title": "test"}]
|
||||
|
||||
with patch.object(svc.client, "send_textcard", AsyncMock(return_value=False)):
|
||||
count = await svc.send(announcements)
|
||||
assert count == 0
|
||||
Reference in New Issue
Block a user