Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
email_backends: Make validate_or_reconnect a private method.
Alex Vandiver3deac1205f9d
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.pyindex 82358a05f4d..e2542aa67fe 100644--- a/zerver/lib/send_email.py+++ b/zerver/lib/send_email.py@@ -410,7 +410,7 @@ def initialize_connection(connection: BaseEmailBackend | None = None) -> BaseEmaconnection.open()if isinstance(connection, PersistentSMTPEmailBackend):- connection.validate_or_reconnect()+ connection._validate_or_reconnect()return connectiondiff --git a/zerver/tests/test_send_email.py b/zerver/tests/test_send_email.pyindex ab683988dd0..594ea53a3fd 100644--- a/zerver/tests/test_send_email.py+++ b/zerver/tests/test_send_email.py@@ -89,7 +89,7 @@ class TestSendEmail(ZulipTestCase):mock.patch.object(backend, "open", wraps=backend.open) as open_call,mock.patch.object(backend, "close", wraps=backend.close) as close_call,):- # Noop raises an exception — validate_or_reconnect closes+ # Noop raises an exception — _validate_or_reconnect closes# and reopens. open() is called twice: once from# initialize_connection, once from the reconnect path.backend.connection = mock.MagicMock(spec=SMTP)@@ -113,7 +113,7 @@ class TestSendEmail(ZulipTestCase):close_call.reset_mock()open_call.reset_mock()- # Noop returns 404 — validate_or_reconnect closes and reopens.+ # Noop returns 404 — _validate_or_reconnect closes and reopens.backend.connection.noop.return_value = [404]with mock.patch("django.core.mail.backends.smtp.EmailBackend.open", side_effect=[False, True]diff --git a/zproject/email_backends.py b/zproject/email_backends.pyindex 6ce3aac98ef..2f6411991a4 100644--- a/zproject/email_backends.py+++ b/zproject/email_backends.py@@ -123,10 +123,10 @@ class PersistentSMTPEmailBackend(EmailBackend):# auto-close the connection after sending.return False- def validate_or_reconnect(self) -> None:+ def _validate_or_reconnect(self) -> None:"""Validate that the existing SMTP connection is still alive,- reconnecting if necessary. Called from initialize_connection- with backoff protection, not from open()."""+ reconnecting if necessary. Called with backoff protection,+ not from open()."""status = Nonetime_elapsed = (timezone_now() - self.opened_at).total_seconds() / 60if (