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: use caplog in ext login tests (#39542)

Evana0b917425ad2
diff --git a/api/tests/unit_tests/extensions/test_ext_login.py b/api/tests/unit_tests/extensions/test_ext_login.py
index cd7bde22967..2207dac1e6a 100644
--- a/api/tests/unit_tests/extensions/test_ext_login.py
+++ b/api/tests/unit_tests/extensions/test_ext_login.py
@@ -52,25 +52,25 @@ def test_on_user_logged_in_sets_end_user_logging_identity() -> None:
assert get_identity_context() == ("tenant-id", "end-user-id", "browser")
-def test_on_user_logged_in_does_not_break_auth_when_identity_is_unavailable() -> None:
+def test_on_user_logged_in_does_not_break_auth_when_identity_is_unavailable(caplog: pytest.LogCaptureFixture) -> None:
account = mock.Mock(spec=ext_login.Account)
type(account).current_tenant_id = mock.PropertyMock(side_effect=RuntimeError("unavailable"))
account.id = "account-id"
clear_request_context()
- with mock.patch.object(ext_login.logger, "exception") as logger_exception:
+ with caplog.at_level("ERROR", logger=ext_login.logger.name):
ext_login.on_user_logged_in(None, account)
assert get_identity_context() == ("", "", "")
- logger_exception.assert_called_once_with("Failed to set logging identity context")
+ assert "Failed to set logging identity context" in caplog.text
-def test_on_user_logged_in_logs_unsupported_user_type() -> None:
+def test_on_user_logged_in_logs_unsupported_user_type(caplog: pytest.LogCaptureFixture) -> None:
unsupported_user = cast(ext_login.LoginUser, object())
clear_request_context()
- with mock.patch.object(ext_login.logger, "exception") as logger_exception:
+ with caplog.at_level("ERROR", logger=ext_login.logger.name):
ext_login.on_user_logged_in(None, unsupported_user)
assert get_identity_context() == ("", "", "")
- logger_exception.assert_called_once_with("Failed to set logging identity context")
+ assert "Failed to set logging identity context" in caplog.text