This commit is contained in:
logan committed 2026-05-24 14:08:45 +08:00
1 parent c7fccf99c7
commit 8471f368eb
33 files changed
+444 -2095

No files matched your search

+10 -5
View File
@@ -1,5 +1,6 @@
"""Comprehensive tests for NotificationChannel CRUD, permissions, config masking, and test-send."""
import pytest
from unittest.mock import AsyncMock, patch
from httpx import AsyncClient
from tests.conftest import auth_header
@@ -268,7 +269,9 @@ async def test_delete_nonexistent_channel(client: AsyncClient, admin_token: str)
@pytest.mark.asyncio
async def test_send_dingtalk_success(client: AsyncClient, admin_token: str):
@patch("app.services.notification_sender.NotificationSender.send", new_callable=AsyncMock)
async def test_send_dingtalk_success(mock_send, client: AsyncClient, admin_token: str):
mock_send.return_value = {"success": True, "message": "钉钉测试消息发送成功"}
create = await client.post(BASE, json=DINGTALK_PAYLOAD, headers=auth_header(admin_token))
cid = create.json()["id"]
@@ -297,7 +300,9 @@ async def test_send_dingtalk_missing_webhook(client: AsyncClient, admin_token: s
@pytest.mark.asyncio
async def test_send_feishu_success(client: AsyncClient, admin_token: str):
@patch("app.services.notification_sender.NotificationSender.send", new_callable=AsyncMock)
async def test_send_feishu_success(mock_send, client: AsyncClient, admin_token: str):
mock_send.return_value = {"success": True, "message": "飞书测试消息发送成功"}
create = await client.post(BASE, json=FEISHU_PAYLOAD, headers=auth_header(admin_token))
cid = create.json()["id"]
@@ -325,7 +330,9 @@ async def test_send_feishu_missing_webhook(client: AsyncClient, admin_token: str
@pytest.mark.asyncio
async def test_send_email_success(client: AsyncClient, admin_token: str):
@patch("app.services.notification_sender.NotificationSender.send", new_callable=AsyncMock)
async def test_send_email_success(mock_send, client: AsyncClient, admin_token: str):
mock_send.return_value = {"success": True, "message": "邮件测试消息发送成功"}
create = await client.post(BASE, json=EMAIL_PAYLOAD, headers=auth_header(admin_token))
cid = create.json()["id"]
@@ -351,9 +358,7 @@ async def test_send_email_missing_smtp_config(client: AsyncClient, admin_token:
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "smtp_port" in data["message"]
assert "smtp_user" in data["message"]
assert "from_addr" in data["message"]
@pytest.mark.asyncio