From d8906aece0045aed9dcd0f0cf1891970c7cb00e8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 09:16:26 +0000 Subject: [PATCH] test: improve coverage for notify_settings_updated error handling Adds unit tests for the notify_settings_updated function in app/utils/settings_sync.py to verify that exceptions during Redis publish, settings reload, and OCR language check are properly caught and logged as warnings without raising up the call stack. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_settings_audit_log.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/test_settings_audit_log.py b/tests/test_settings_audit_log.py index 8f14ed8e..67075f81 100644 --- a/tests/test_settings_audit_log.py +++ b/tests/test_settings_audit_log.py @@ -289,7 +289,8 @@ class TestNotifySettingsUpdated: call_args = mock_redis_instance.set.call_args[0] assert call_args[0] == SETTINGS_VERSION_KEY - def test_does_not_raise_on_redis_failure(self): + @patch("app.utils.settings_sync.logger") + def test_does_not_raise_on_redis_failure(self, mock_logger): """notify_settings_updated must not propagate Redis errors.""" from app.utils.settings_sync import notify_settings_updated @@ -297,6 +298,35 @@ class TestNotifySettingsUpdated: mock_redis_module.from_url.side_effect = Exception("Redis down") # Should not raise notify_settings_updated() + mock_logger.warning.assert_any_call("Could not publish settings update to Redis: Redis down") + + @patch("app.utils.settings_sync.logger") + def test_does_not_raise_on_reload_failure(self, mock_logger): + """notify_settings_updated must not propagate settings reload errors.""" + from app.utils.settings_sync import notify_settings_updated + + with patch("app.utils.config_loader.reload_settings_from_db") as mock_reload: + mock_reload.side_effect = Exception("Reload error") + # We mock redis so that we skip over the redis block, and mock ensure_ocr_languages_async to prevent its side effects. + with patch("app.utils.settings_sync.redis"): + with patch("app.utils.ocr_language_manager.ensure_ocr_languages_async"): + # Should not raise + notify_settings_updated() + mock_logger.warning.assert_any_call("Could not reload in-process settings: Reload error") + + @patch("app.utils.settings_sync.logger") + def test_does_not_raise_on_ocr_language_check_failure(self, mock_logger): + """notify_settings_updated must not propagate OCR language check errors.""" + from app.utils.settings_sync import notify_settings_updated + + with patch("app.utils.ocr_language_manager.ensure_ocr_languages_async") as mock_ensure: + mock_ensure.side_effect = Exception("OCR error") + # We mock redis and reload_settings_from_db so we only test the OCR block failure. + with patch("app.utils.settings_sync.redis"): + with patch("app.utils.config_loader.reload_settings_from_db"): + # Should not raise + notify_settings_updated() + mock_logger.warning.assert_any_call("Could not schedule OCR language check: OCR error") @pytest.mark.unit