40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from dataclasses import dataclass
|
|
from io import StringIO
|
|
|
|
from django.core.management import call_command
|
|
from django.core.management.base import CommandError
|
|
import pytest
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class FakeRecord:
|
|
send_status: str = "success"
|
|
target: str = "负责人"
|
|
error_message: str = ""
|
|
|
|
|
|
def test_send_test_feishu_notification_calls_dispatcher(monkeypatch, django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
calls = []
|
|
monkeypatch.setattr(
|
|
"review_agent.management.commands.send_test_feishu_notification.dispatch_workflow_notification",
|
|
lambda context: calls.append(context) or FakeRecord(),
|
|
)
|
|
output = StringIO()
|
|
|
|
call_command("send_test_feishu_notification", "--username", user.username, stdout=output)
|
|
|
|
assert calls
|
|
assert calls[0].workflow_type == "manual_test"
|
|
assert calls[0].trigger_user_id == user.pk
|
|
assert "send_status=success" in output.getvalue()
|
|
assert "target=负责人" in output.getvalue()
|
|
|
|
|
|
def test_send_test_feishu_notification_missing_user_raises():
|
|
with pytest.raises(CommandError):
|
|
call_command("send_test_feishu_notification", "--username", "missing")
|