Fix version display, deterministic sort, remove duplicate sort
get_version() now returns version.name instead of str(version), which returned the numeric ID from redminelib.resources.Version. Falls back to str() when .name is absent (#14). Add issue.id as tertiary sort key in build_grouped_report so tasks within the same project+version group always appear in the same order regardless of API response ordering (#33). Remove redundant sort from client.fetch_issues_with_spent_time — the sort already runs in report_builder.build_grouped_report, so doing it twice wastes CPU. Also remove the now-unused get_version import (#32). Closes #14, closes #32, closes #33
This commit is contained in:
@@ -105,3 +105,15 @@ def test_build_grouped_report_preserves_issue_id_and_subject():
|
||||
rows = build_grouped_report(issues)
|
||||
assert rows[0]["issue_id"] == 42
|
||||
assert rows[0]["subject"] == "Моя задача"
|
||||
|
||||
|
||||
def test_build_grouped_report_deterministic_order_within_group():
|
||||
"""Задачи в одной группе проект+версия упорядочены по issue.id
|
||||
независимо от порядка на входе (#33)."""
|
||||
issues = [
|
||||
(MockIssue("P", "Task C", "New", "v1.0", 103), 1.0),
|
||||
(MockIssue("P", "Task A", "New", "v1.0", 101), 1.0),
|
||||
(MockIssue("P", "Task B", "New", "v1.0", 102), 1.0),
|
||||
]
|
||||
rows = build_grouped_report(issues)
|
||||
assert [r["issue_id"] for r in rows] == [101, 102, 103]
|
||||
|
||||
@@ -78,3 +78,35 @@ def test_get_version_none_attribute():
|
||||
fixed_version = None
|
||||
|
||||
assert get_version(MockIssue()) == "<N/A>"
|
||||
|
||||
|
||||
def test_get_version_with_redminelib_version_object():
|
||||
"""redminelib Version: str() возвращает ID, .name — человекочитаемое имя."""
|
||||
|
||||
class MockVersion:
|
||||
"""Имитирует redminelib.resources.Version — str() даёт ID."""
|
||||
|
||||
def __init__(self, vid, name):
|
||||
self.id = vid
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
return str(self.id)
|
||||
|
||||
class MockIssue:
|
||||
fixed_version = MockVersion(42, "v2.5.0")
|
||||
|
||||
assert get_version(MockIssue()) == "v2.5.0"
|
||||
|
||||
|
||||
def test_get_version_falls_back_to_str_when_no_name():
|
||||
"""Если у объекта версии нет .name — fallback на str()."""
|
||||
|
||||
class MockVersionNoName:
|
||||
def __str__(self):
|
||||
return "fallback-id"
|
||||
|
||||
class MockIssue:
|
||||
fixed_version = MockVersionNoName()
|
||||
|
||||
assert get_version(MockIssue()) == "fallback-id"
|
||||
|
||||
Reference in New Issue
Block a user