fix: remove patch logger in test, use caplog instead (Closes #37468) (#39159)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
sahasweety 2026-07-17 11:52:20 +05:30 committed by GitHub
parent aff8a49bbf
commit 83f40b85f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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."""