From 1aa059748a41a64c9e76591c6dc1413330fb02e1 Mon Sep 17 00:00:00 2001 From: Christophe CHAUVET Date: Thu, 26 Feb 2026 09:41:28 +0000 Subject: [PATCH] fix: rewrite port detection value --- .../management/commands/generate_postfix_maps.py | 11 +++++++---- modoboa/core/tests/test_core.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modoboa/core/management/commands/generate_postfix_maps.py b/modoboa/core/management/commands/generate_postfix_maps.py index 6e0321867..bf437b0f9 100644 --- a/modoboa/core/management/commands/generate_postfix_maps.py +++ b/modoboa/core/management/commands/generate_postfix_maps.py @@ -95,16 +95,19 @@ query = {{ query|safe }} if dburl else settings.DATABASES["default"] ) + dbhost = db_settings.get("HOST", "127.0.0.1") if "sqlite" in db_settings["ENGINE"]: dbtype = "sqlite" + dbport = None elif "postgresql" in db_settings["ENGINE"]: dbtype = "postgres" + dbport = db_settings.get("PORT", "5432") else: dbtype = "mysql" - dbhost = db_settings.get("HOST", "127.0.0.1") - dbport = db_settings.get("PORT", "") - if len(dbport): - dbhost += ":" + dbport + dbport = db_settings.get("PORT", "3306") + + if dbport: + dbhost += f":{dbport}" commandline = "{} {}".format( os.path.basename(sys.argv[0]), " ".join(sys.argv[1:]) diff --git a/modoboa/core/tests/test_core.py b/modoboa/core/tests/test_core.py index 94d0bd331..83151622f 100644 --- a/modoboa/core/tests/test_core.py +++ b/modoboa/core/tests/test_core.py @@ -4,6 +4,7 @@ from io import StringIO import json import pathlib import shutil +import tempfile import httmock from dateutil.relativedelta import relativedelta @@ -133,6 +134,21 @@ class ManagementCommandsTestCase(SimpleModoTestCase): ]: self.assertFalse(config[param].startswith("http")) + def test_generate_postfix_maps(self): + """Run generate_postfix_maps command""" + + workdir = tempfile.mkdtemp() + # test SQLite URL + management.call_command("generate_postfix_maps", "--dburl", "sqlite://testdb.sqlite", "--destdir", workdir) + + workdir = tempfile.mkdtemp() + # test PostgreSQL URL + management.call_command("generate_postfix_maps", "--dburl", "postgres://user:password@localhost/testdb", "--destdir", workdir) + + workdir = tempfile.mkdtemp() + # test MySQL URL + management.call_command("generate_postfix_maps", "--dburl", "mysql://user:password@localhost/testdb", "--destdir", workdir) + def test_clean_inactive_accounts(self): """Run clean_inactive_accounts command.""" management.call_command("load_initial_data")