Tighten configuration and export handling

This commit is contained in:
Кокос Артем Николаевич
2026-05-22 17:41:56 +07:00
parent 8bc8181ce3
commit 2db0ab1f0b
20 changed files with 423 additions and 350 deletions

View File

@@ -1,13 +1,16 @@
import pytest
import io
from typing import List
from unittest import mock
from redmine_reporter.types import ReportRow
from redmine_reporter.formatters.console import TableFormatter, CompactFormatter
import pytest
from odf.opendocument import OpenDocument, OpenDocumentText
from redmine_reporter.formatters.console import CompactFormatter, TableFormatter
from redmine_reporter.formatters.csv import CSVFormatter
from redmine_reporter.formatters.html import HTMLFormatter
from redmine_reporter.formatters.markdown import MarkdownFormatter
from redmine_reporter.formatters.odt import ODTFormatter
from odf.opendocument import OpenDocument, OpenDocumentText
from redmine_reporter.types import ReportRow
def _make_empty_odt_bytes() -> bytes:
@@ -122,9 +125,7 @@ def odt_formatter():
)
),
):
yield ODTFormatter(
author="Тест Автор", from_date="2026-01-01", to_date="2026-01-31"
)
yield ODTFormatter(author="Тест Автор", from_date="2026-01-01", to_date="2026-01-31")
# -- Параметризованные тесты текстовых форматтеров --
@@ -184,6 +185,31 @@ def test_compact_formatter_save_raises(fake_rows):
CompactFormatter().save(fake_rows, "/dev/null")
def test_markdown_formatter_escapes_table_cells():
rows = make_fake_report_rows()
rows[0]["project"] = "A|B"
rows[0]["display_project"] = "A|B"
rows[0]["subject"] = "Fix | split\nline"
output = MarkdownFormatter().format(rows)
assert "A\\|B" in output
assert "101. Fix \\| split<br>line" in output
def test_html_formatter_escapes_cells():
rows = make_fake_report_rows()
rows[0]["project"] = 'A&B "<Project>"'
rows[0]["display_project"] = rows[0]["project"]
rows[0]["subject"] = "Fix <tag> & attrs"
output = HTMLFormatter().format(rows)
assert "A&amp;B &quot;&lt;Project&gt;&quot;" in output
assert "101. Fix &lt;tag&gt; &amp; attrs" in output
assert "Fix <tag>" not in output
# -- Тесты ODT форматтера --
@@ -208,9 +234,7 @@ def test_odt_formatter_save_creates_valid_file(fake_rows, tmp_path):
)
),
):
formatter = ODTFormatter(
author="Тест", from_date="2026-01-01", to_date="2026-01-31"
)
formatter = ODTFormatter(author="Тест", from_date="2026-01-01", to_date="2026-01-31")
output_file = tmp_path / "report.odt"
formatter.save(fake_rows, str(output_file))