ODT table support
This commit is contained in:
73
tests/test_formatter_odt.py
Normal file
73
tests/test_formatter_odt.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
from redmine_reporter.formatter_odt import format_odt
|
||||
|
||||
|
||||
def make_mock_issue(id_, project, subject, status, fixed_version=None):
|
||||
"""Создаёт лёгкий mock-объект, имитирующий Issue из redminelib."""
|
||||
|
||||
issue = SimpleNamespace()
|
||||
issue.id = id_
|
||||
issue.project = project
|
||||
issue.subject = subject
|
||||
issue.status = status
|
||||
|
||||
if fixed_version is not None:
|
||||
issue.fixed_version = fixed_version
|
||||
return issue
|
||||
|
||||
|
||||
def test_format_odt_basic():
|
||||
issues = [
|
||||
(make_mock_issue(101, "Камеры", "Поддержка нового датчика", "In Progress", "v2.5.0"), 2.5),
|
||||
(make_mock_issue(102, "Камеры", "Исправить утечку памяти", "Resolved", "v2.5.0"), 4.0),
|
||||
(make_mock_issue(103, "ПО", "Обновить документацию", "Pending", None), 12.0),
|
||||
]
|
||||
|
||||
doc = format_odt(issues)
|
||||
|
||||
# Сохраняем и проверяем содержимое
|
||||
with tempfile.NamedTemporaryFile(suffix=".odt") as tmp:
|
||||
doc.save(tmp.name)
|
||||
|
||||
# Проверяем, что файл - это ZIP (ODT основан на ZIP)
|
||||
with open(tmp.name, "rb") as f:
|
||||
assert f.read(2) == b"PK"
|
||||
|
||||
# Извлекаем content.xml
|
||||
import zipfile
|
||||
with zipfile.ZipFile(tmp.name) as zf:
|
||||
content_xml = zf.read("content.xml").decode("utf-8")
|
||||
|
||||
# Проверяем заголовки
|
||||
assert "Проект" in content_xml
|
||||
assert "Версия" in content_xml
|
||||
assert "Задача" in content_xml
|
||||
assert "Статус" in content_xml
|
||||
assert "Затрачено" in content_xml
|
||||
|
||||
# Проверяем данные задач
|
||||
assert "101. Поддержка нового датчика" in content_xml
|
||||
assert "102. Исправить утечку памяти" in content_xml
|
||||
assert "103. Обновить документацию" in content_xml
|
||||
|
||||
# Проверяем проекты и версии
|
||||
assert "Камеры" in content_xml
|
||||
assert "ПО" in content_xml
|
||||
assert "v2.5.0" in content_xml
|
||||
assert "<N/A>" in content_xml or "<N/A>" in content_xml # зависит от экранирования
|
||||
|
||||
# Проверяем перевод статусов
|
||||
assert "В работе" in content_xml # In Progress
|
||||
assert "Решена" in content_xml # Resolved
|
||||
assert "Ожидание" in content_xml # Pending
|
||||
|
||||
# Проверяем формат времени
|
||||
assert "2ч 30м" in content_xml
|
||||
assert "4ч" in content_xml
|
||||
assert "12ч" in content_xml
|
||||
|
||||
# Проверяем группировку: "Камеры" должен встречаться только один раз явно
|
||||
# (вторая строка — пустая ячейка)
|
||||
cam_occurrences = content_xml.count(">Камеры<")
|
||||
assert cam_occurrences == 1
|
||||
Reference in New Issue
Block a user