mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
aff8a49bbf
commit
83f40b85f4
@ -13,7 +13,9 @@ from services.trigger.webhook_service import WebhookService
|
||||
class TestWebhookServiceUnit:
|
||||
"""Unit tests for WebhookService focusing on business logic without database dependencies."""
|
||||
|
||||
def test_trigger_workflow_execution_propagates_quota_error_without_error_log(self):
|
||||
def test_trigger_workflow_execution_propagates_quota_error_without_error_log(
|
||||
self, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
webhook_trigger = MagicMock(
|
||||
webhook_id="webhook-123",
|
||||
tenant_id="tenant-123",
|
||||
@ -24,6 +26,7 @@ class TestWebhookServiceUnit:
|
||||
quota_charge = MagicMock()
|
||||
quota_error = QuotaExceededError(feature="workflow", tenant_id="tenant-123", required=1)
|
||||
|
||||
caplog.set_level(logging.INFO)
|
||||
with (
|
||||
patch(
|
||||
"services.trigger.webhook_service.EndUserService.get_or_create_end_user_by_type",
|
||||
@ -36,8 +39,6 @@ class TestWebhookServiceUnit:
|
||||
"services.trigger.webhook_service.AsyncWorkflowService.trigger_workflow_async",
|
||||
side_effect=quota_error,
|
||||
),
|
||||
patch("services.trigger.webhook_service.logger.info") as mock_log_info,
|
||||
patch("services.trigger.webhook_service.logger.exception") as mock_log_exception,
|
||||
):
|
||||
with pytest.raises(QuotaExceededError) as exc_info:
|
||||
WebhookService.trigger_workflow_execution(
|
||||
@ -48,13 +49,13 @@ class TestWebhookServiceUnit:
|
||||
|
||||
assert exc_info.value is quota_error
|
||||
quota_charge.refund.assert_called_once_with()
|
||||
mock_log_info.assert_called_once_with(
|
||||
"Tenant %s quota exceeded for feature %s, skipping webhook trigger %s",
|
||||
webhook_trigger.tenant_id,
|
||||
quota_error.feature,
|
||||
webhook_trigger.webhook_id,
|
||||
|
||||
# Verify logs using caplog instead of mock_log
|
||||
assert len(caplog.records) == 1
|
||||
assert caplog.records[0].levelno == logging.INFO
|
||||
assert caplog.records[0].message == (
|
||||
"Tenant tenant-123 quota exceeded for feature workflow, skipping webhook trigger webhook-123"
|
||||
)
|
||||
mock_log_exception.assert_not_called()
|
||||
|
||||
def test_extract_webhook_data_json(self):
|
||||
"""Test webhook data extraction from JSON request."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user