mirror of
https://github.com/langgenius/dify.git
synced 2026-06-18 07:41:09 +08:00
test: replace logger patch with caplog in version and rag pipeline tests (#37554)
This commit is contained in:
parent
e189ceb397
commit
3f81ec1212
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import controllers.console.version as version_module
|
||||
@ -18,15 +19,15 @@ class TestHasNewVersion:
|
||||
)
|
||||
assert result is False
|
||||
|
||||
def test_has_new_version_invalid_version(self):
|
||||
with patch.object(version_module.logger, "warning") as log_warning:
|
||||
def test_has_new_version_invalid_version(self, caplog):
|
||||
with caplog.at_level(logging.WARNING, logger="controllers.console.version"):
|
||||
result = version_module._has_new_version(
|
||||
latest_version="invalid",
|
||||
current_version="1.0.0",
|
||||
)
|
||||
|
||||
assert result is False
|
||||
log_warning.assert_called_once()
|
||||
assert "Invalid version format" in caplog.text
|
||||
|
||||
|
||||
class TestCheckVersionUpdate:
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import json
|
||||
import logging
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
@ -468,16 +469,14 @@ class TestRagPipelineTaskProxy:
|
||||
# Assert
|
||||
proxy._dispatch.assert_called_once()
|
||||
|
||||
@patch("services.rag_pipeline.rag_pipeline_task_proxy.logger")
|
||||
def test_delay_method_with_empty_entities(self, mock_logger):
|
||||
def test_delay_method_with_empty_entities(self, caplog):
|
||||
"""Test delay method with empty rag_pipeline_invoke_entities."""
|
||||
# Arrange
|
||||
proxy = RagPipelineTaskProxy("tenant-123", "user-456", [])
|
||||
|
||||
# Act
|
||||
proxy.delay()
|
||||
with caplog.at_level(logging.WARNING, logger="services.rag_pipeline.rag_pipeline_task_proxy"):
|
||||
proxy.delay()
|
||||
|
||||
# Assert
|
||||
mock_logger.warning.assert_called_once_with(
|
||||
"Received empty rag pipeline invoke entities, no tasks delivered: %s %s", "tenant-123", "user-456"
|
||||
)
|
||||
assert "Received empty rag pipeline invoke entities, no tasks delivered: tenant-123 user-456" in caplog.text
|
||||
|
||||
Loading…
Reference in New Issue
Block a user