Merge pull request #3948 from modoboa/3517-fix-dbport

fix: rewrite port detection value
This commit is contained in:
Antoine Nguyen
2026-03-02 14:14:49 +01:00
committed by GitHub
2 changed files with 23 additions and 4 deletions
@@ -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:])
+16
View File
@@ -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")