syntax fix
Sonarqube Scanner / Prepare environment (push) Successful in 5s
Sonarqube Scanner / Build and test (push) Successful in 19s
Sonarqube Scanner / SonarQube analysis (push) Failing after 55s
Sonarqube Scanner / Deploy to Server (push) Successful in 4s

This commit is contained in:
Florian Zumpe
2026-10-03 12:53:42 +02:00
parent 171ea88d55
commit cf4170f590
2 changed files with 30 additions and 14 deletions
+15
View File
@@ -86,6 +86,21 @@ class ModerationTests(unittest.TestCase):
self.assertEqual(self.run_cli(args), 1)
self.assertFalse(self.path.exists())
def test_export_prefix_accepts_whitespace_and_preserves_variable_names(self):
env_file = self.root / ".env"
for prefix in ["export ", " export\t", "\texport ", ""]:
env_file.write_text(f'{prefix}DATA_DIR="anderer Ordner"\n', encoding="utf-8")
self.assertEqual(moderate_routes.database_path(self.root),
self.root / "anderer Ordner" / "wegwichtel.sqlite")
env_file.write_text("exportDATA_DIR=anders\nexport_path=anders\n", encoding="utf-8")
self.assertEqual(moderate_routes.database_path(self.root), self.path)
def test_env_read_errors_are_reported_without_changing_database(self):
with patch.object(Path, "read_text", side_effect=PermissionError("Lesen nicht erlaubt")):
self.assertEqual(self.run_cli(["-e", "1"]), 1)
self.assertIsNone(self.activation())
self.assertIn("Lesen nicht erlaubt", self.error.getvalue())
def test_bad_env_reports_line_without_secrets(self):
for value in ["secret-without-equals", 'DATA_DIR="secret']:
(self.root / ".env").write_text(value, encoding="utf-8")
+15 -14
View File
@@ -5,10 +5,10 @@ import argparse
from datetime import datetime, timezone
import os
from pathlib import Path
import re
import shlex
import sqlite3
import sys
import re
PROJECT_ROOT = Path(__file__).resolve().parents[2]
@@ -18,19 +18,20 @@ def database_path(project_root):
settings = {}
env_file = project_root / ".env"
try:
for number, line in enumerate(env_file.read_text(encoding="utf-8-sig").splitlines(), 1):
line = re.sub(r'^\s*export\s+', '', line).strip()
if not line or line.startswith("#"):
continue
if line.startswith("export "):
line = line[7:].lstrip()
key, separator, value = line.partition("=")
if not separator:
raise ValueError(f"Ungültige .env-Angabe in Zeile {number}.")
try:
settings[key.strip()] = " ".join(shlex.split(value, comments=True))
except ValueError as error:
raise ValueError(f"Ungültige .env-Anführungszeichen in Zeile {number}.") from error
contents = env_file.read_text(encoding="utf-8-sig")
except FileNotFoundError:
contents = ""
for number, line in enumerate(contents.splitlines(), 1):
line = re.sub(r'^\s*export\s+', '', line).strip()
if not line or line.startswith("#"):
continue
key, separator, value = line.partition("=")
if not separator:
raise ValueError(f"Ungültige .env-Angabe in Zeile {number}.")
try:
settings[key.strip()] = " ".join(shlex.split(value, comments=True))
except ValueError as error:
raise ValueError(f"Ungültige .env-Anführungszeichen in Zeile {number}.") from error
data_dir = os.environ.get("DATA_DIR", settings.get("DATA_DIR", "")) or "data"
return (project_root / data_dir / "wegwichtel.sqlite").resolve()