Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: replace logger patch with caplog in version and rag pipeline tests (#37554)

Prajeeth Channa3f81ec12129f
diff --git a/api/tests/unit_tests/controllers/console/test_version.py b/api/tests/unit_tests/controllers/console/test_version.py
index 8d8d324be1f..335c8692969 100644
--- a/api/tests/unit_tests/controllers/console/test_version.py
+++ b/api/tests/unit_tests/controllers/console/test_version.py
@@ -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:
diff --git a/api/tests/unit_tests/services/test_rag_pipeline_task_proxy.py b/api/tests/unit_tests/services/test_rag_pipeline_task_proxy.py
index cfc685e4cbd..ce14d55d4de 100644
--- a/api/tests/unit_tests/services/test_rag_pipeline_task_proxy.py
+++ b/api/tests/unit_tests/services/test_rag_pipeline_task_proxy.py
@@ -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