feat: filename template expansion with {date} placeholder
- Add expand_filename_template() to yaml_config.py
- Supports {author}, {from}, {to}, {date}, {ext} placeholders
- {date} formats as DD_MM_YYYY (e.g. 31_03_2026)
- Spaces in author replaced with underscores for safe filenames
- Unknown placeholders left as-is
- Add comprehensive CONFIG.md documentation covering YAML setup, migration, and template syntax
This commit is contained in:
@@ -5,7 +5,7 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from redmine_reporter.config import AppConfig, Config, DEFAULT_REDMINE_VERIFY
|
||||
from redmine_reporter.config import DEFAULT_REDMINE_VERIFY, AppConfig, Config
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
|
||||
@@ -4,10 +4,10 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
|
||||
from redmine_reporter.yaml_config import (
|
||||
check_file_permissions,
|
||||
ensure_config_dir,
|
||||
expand_filename_template,
|
||||
resolve_env_vars,
|
||||
)
|
||||
|
||||
@@ -78,3 +78,47 @@ class TestCheckFilePermissions:
|
||||
f.chmod(0o600)
|
||||
warnings = check_file_permissions(f)
|
||||
assert warnings == []
|
||||
|
||||
|
||||
class TestExpandFilenameTemplate:
|
||||
"""Tests for filename template expansion."""
|
||||
|
||||
def test_expands_all_placeholders(self):
|
||||
result = expand_filename_template(
|
||||
"report_{author}_{from}_{to}.{ext}",
|
||||
author="Кокос А.А.",
|
||||
from_date="2026-06-01",
|
||||
to_date="2026-06-30",
|
||||
ext="xlsx",
|
||||
)
|
||||
assert result == "report_Кокос_А.А._2026-06-01_2026-06-30.xlsx"
|
||||
|
||||
def test_date_placeholder_dd_mm_yyyy(self):
|
||||
result = expand_filename_template(
|
||||
"отчёт_{date}.{ext}",
|
||||
author="Кокос А.А.",
|
||||
from_date="2026-03-01",
|
||||
to_date="2026-03-31",
|
||||
ext="odt",
|
||||
)
|
||||
assert result == "отчёт_31_03_2026.odt"
|
||||
|
||||
def test_no_placeholders_returns_unchanged(self):
|
||||
result = expand_filename_template(
|
||||
"report.odt",
|
||||
author="Кокос А.А.",
|
||||
from_date="2026-01-01",
|
||||
to_date="2026-01-31",
|
||||
ext="odt",
|
||||
)
|
||||
assert result == "report.odt"
|
||||
|
||||
def test_unknown_placeholder_left_as_is(self):
|
||||
result = expand_filename_template(
|
||||
"{author}_{unknown}.{ext}",
|
||||
author="Кокос А.А.",
|
||||
from_date="2026-01-01",
|
||||
to_date="2026-01-31",
|
||||
ext="xlsx",
|
||||
)
|
||||
assert result == "Кокос_А.А._{unknown}.xlsx"
|
||||
|
||||
Reference in New Issue
Block a user