This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a commit to branch gc/8574
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/gc/8574 by this push:
     new 9c1b6446e fixup! [#8574] removed the async function start_server in 
favor a more simple approach to keep the server running
9c1b6446e is described below

commit 9c1b6446e0196f2a83c5b76c4dd7907571811b52
Author: Guillermo Cruz <[email protected]>
AuthorDate: Thu Feb 6 11:02:04 2025 -0700

    fixup! [#8574] removed the async function start_server in favor a more 
simple approach to keep the server running
---
 Allura/allura/command/smtp_server.py  |  1 -
 Allura/allura/tests/test_mail_util.py | 33 +++++++++++++++++++--------------
 Allura/test.ini                       |  3 +++
 AlluraTest/alluratest/smtp_debug.py   | 10 +---------
 4 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/Allura/allura/command/smtp_server.py 
b/Allura/allura/command/smtp_server.py
index 5d42e5391..1ce8e2cf0 100644
--- a/Allura/allura/command/smtp_server.py
+++ b/Allura/allura/command/smtp_server.py
@@ -25,7 +25,6 @@
 from allura.lib import helpers as h
 from paste.deploy.converters import asint
 from aiosmtpd.controller import Controller
-import asyncio
 from tg.wsgiapp import RequestLocals
 import time
 
diff --git a/Allura/allura/tests/test_mail_util.py 
b/Allura/allura/tests/test_mail_util.py
index 19001b8d5..38418ddf3 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -24,7 +24,6 @@
 from tg import config as tg_config
 from smtplib import SMTP as SMTPClient
 from alluratest.controller import setup_basic_test, setup_global_objects
-from alluratest.smtp_debug import BetterDebuggingServer
 from allura.lib.utils import ConfigProxy
 from allura.app import Application
 from allura.lib.mail_util import (
@@ -39,7 +38,8 @@
 from allura.lib.exceptions import AddressException
 from allura.tests import decorators as td
 from paste.deploy.converters import asint
-from aiosmtpd.handlers import Debugging
+from allura.command.smtp_server import MailServer
+from aiosmtpd.controller import Controller
 
 config = ConfigProxy(
     common_suffix='forgemail.domain',
@@ -335,24 +335,29 @@ def setup_method(self, method):
 
     @mock.patch('allura.command.base.log', autospec=True)
     def test(self, log):
-        mailserver = BetterDebuggingServer()
-        controller, handler = mailserver.start_server()
         hostname = tg_config.get('forgemail.host', '0.0.0.0')
-        port = asint(tg_config.get('forgemail.port', 8825))
+        port = asint(tg_config.get('forgemail.port', 8827))
+        handler = MailServer()
+        controller = Controller(handler, hostname=hostname, port=port)
+        controller.start()
+        
         with SMTPClient(hostname, port, timeout=0.1) as client:
-            resp = client.docmd("HELP", "HELO")
             code, msg = client.ehlo("example.com")
             assert code == 250
-            client.sendmail('[email protected]', ['[email protected]'],"""
-            From: Anne Person <[email protected]>
-            To: Bart Person <[email protected]>
+            mailfrom = client.docmd("MAIL FROM: <[email protected]>")
+            assert mailfrom == (250, b'OK')
+            rcpt = client.docmd("RCPT TO: <[email protected]>")
+            assert rcpt == (250, b'OK')
+            data = client.docmd("DATA")
+            assert data == (354, b'End data with <CR><LF>.<CR><LF>')
+            
+        with SMTPClient(hostname, port, timeout=0.1) as client:
+            client.sendmail('[email protected]', ['[email protected]'],"""
+            From: From Person <[email protected]>
+            To: To Person <[email protected]>
             Subject: A test
             Hi Bart, this is Anne.
             """)
-            assert isinstance(handler, Debugging)
-            text = handler.stream.getvalue()
-            assert 'From: Anne Person <[email protected]>' in text
-            assert ' To: Bart Person <[email protected]>' in text
-            assert 'Subject: A test' in text
             
+        controller.stop()
             
diff --git a/Allura/test.ini b/Allura/test.ini
index 8c3604c11..c46c0646a 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -84,6 +84,9 @@ markdown_render_max_length = 40000
 ; TODO: update tests and remove this setting override
 auth.require_email_addr = false
 
+forgemail.host = 127.0.0.1
+forgemail.port = 8827
+
 [app:task]
 use = main
 ; TurboGears will use controllers/task.py as root controller
diff --git a/AlluraTest/alluratest/smtp_debug.py 
b/AlluraTest/alluratest/smtp_debug.py
index b6cec8324..f4e1517e8 100644
--- a/AlluraTest/alluratest/smtp_debug.py
+++ b/AlluraTest/alluratest/smtp_debug.py
@@ -21,17 +21,9 @@
 from io import StringIO
 from paste.deploy.converters import asint
 
+
 class BetterDebuggingServer:
     
-    def start_server(self):
-        stream = StringIO()
-        handler = Debugging(stream)  # throws away the email
-        hostname = tg.config.get('forgemail.host', '0.0.0.0')
-        port = asint(tg.config.get('forgemail.port', 8825))
-        controller = Controller(handler, hostname=hostname, port=port)
-        controller.start()
-        return controller, handler
-    
 
     async def handle_DATA(self,  server, session, envelope):
         try:

Reply via email to