新增了插件相关的完整领域模型、应用服务、基础设施实现,包括: 1. 插件状态、注册模式、来源等基础枚举和数据结构 2. 插件清单解析、发现、加载工具类 3. 插件注册表领域服务和内存存储实现 4. 插件相关的命令、查询、事件定义 5. 插件REST API接口和DTO映射 6. 集成了原有通道适配器到插件系统 7. 新增内置插件注册和自动发现能力
117 lines
4.2 KiB
Python
117 lines
4.2 KiB
Python
"""
|
|
Integration tests for channel inbound endpoints:
|
|
- /channel/web/message
|
|
- /channel/feishu/event
|
|
- /channel/feishu/verify
|
|
- /channel/hooks/{path}
|
|
- /channel/dingtalk/callback
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
|
|
|
|
|
|
class TestWebMessage:
|
|
async def test_web_message_with_invalid_json_returns_400(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/web/message",
|
|
content=b"not-json",
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code == 400, response.text
|
|
|
|
async def test_web_message_with_valid_json_returns_accepted(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/web/message",
|
|
json={
|
|
"session_id": "intg-test-session",
|
|
"content": "hello from integration test",
|
|
"sender": "tester",
|
|
},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code in (202, 400), response.text
|
|
if response.status_code == 202:
|
|
payload = response.json()
|
|
assert "trace_id" in payload
|
|
assert payload["status"] in ("accepted", "skipped")
|
|
|
|
|
|
class TestFeishuEvent:
|
|
async def test_feishu_url_verification_returns_challenge(self, test_client):
|
|
challenge = "test_challenge_value_123"
|
|
response = await test_client.post(
|
|
"/channel/feishu/event",
|
|
json={
|
|
"type": "url_verification",
|
|
"challenge": challenge,
|
|
},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code == 200, response.text
|
|
assert response.json()["challenge"] == challenge
|
|
|
|
async def test_feishu_event_without_type_returns_code_0(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/feishu/event",
|
|
json={"event": {"message": {"content": "test"}}},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code == 200, response.text
|
|
assert response.json().get("code") == 0
|
|
|
|
async def test_feishu_verify_endpoint(self, test_client):
|
|
response = await test_client.get(
|
|
"/channel/feishu/verify",
|
|
params={"challenge": "abc", "token": "any"},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
if response.status_code == 403:
|
|
pytest.skip("Feishu verification token mismatch")
|
|
assert response.status_code == 200, response.text
|
|
|
|
|
|
class TestHooksMessage:
|
|
async def test_hooks_with_nonexistent_path_returns_404(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/hooks/nonexistent_path_xyz",
|
|
json={"event": "test"},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code == 404, response.text
|
|
|
|
async def test_hooks_with_invalid_json_returns_400(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/hooks/test_path",
|
|
content=b"not-json",
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
if response.status_code == 404:
|
|
pytest.skip("Hook mapping not configured")
|
|
assert response.status_code == 400, response.text
|
|
|
|
|
|
class TestDingTalkCallback:
|
|
async def test_dingtalk_callback_returns_accepted(self, test_client):
|
|
response = await test_client.post(
|
|
"/channel/dingtalk/callback",
|
|
json={"msgtype": "text", "text": {"content": "hello"}},
|
|
)
|
|
if response.status_code == 503:
|
|
pytest.skip("Channel gateway not initialized")
|
|
assert response.status_code == 202, response.text
|
|
payload = response.json()
|
|
assert payload.get("status") == "accepted"
|