Organized
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
"""Regression: `rtl tui` must reach its TUI launcher instead of falling through to exit 1."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import redmine_tickets
|
||||
|
||||
|
||||
def test_tui_command_dispatches_to_tui_launcher(monkeypatch, tmp_path):
|
||||
called = {}
|
||||
|
||||
class DummyCache:
|
||||
def __init__(self, cache_dir, project):
|
||||
self.cache_dir = cache_dir
|
||||
self.project = project
|
||||
|
||||
def fake_tui_launcher(args, cache):
|
||||
called["command"] = args.command
|
||||
called["project"] = cache.project
|
||||
return 73
|
||||
|
||||
monkeypatch.setattr(redmine_tickets, "TicketCache", DummyCache)
|
||||
monkeypatch.setattr(redmine_tickets, "run_tui_cli", fake_tui_launcher)
|
||||
|
||||
config = tmp_path / "live.json"
|
||||
config.write_text(
|
||||
'{"base-url":"https://rm.ldrprep.com","project":"customer-service",'
|
||||
'"cache-dir":"/tmp/redmine-cache"}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
rc = redmine_tickets.main(
|
||||
["--config", str(config), "tui", "--open-only", "--max-tickets", "5"]
|
||||
)
|
||||
|
||||
assert rc == 73
|
||||
assert called == {"command": "tui", "project": "customer-service"}
|
||||
|
||||
|
||||
class DummyCache:
|
||||
def __init__(self, cache_dir, project):
|
||||
self.cache_dir = cache_dir
|
||||
self.project = project
|
||||
|
||||
|
||||
def test_ocr_rename_command_reaches_handler_not_silent_exit(monkeypatch, tmp_path):
|
||||
"""ocr-rename used to be nested under search after `return 0` and fell through."""
|
||||
called = {}
|
||||
|
||||
def fake_load(cache, issue_id):
|
||||
called["issue_id"] = issue_id
|
||||
raise RuntimeError("ocr-rename handler reached")
|
||||
|
||||
monkeypatch.setattr(redmine_tickets, "TicketCache", DummyCache)
|
||||
monkeypatch.setattr(redmine_tickets, "load_cached_issue", fake_load)
|
||||
|
||||
try:
|
||||
rc = redmine_tickets.main(
|
||||
[
|
||||
"--project",
|
||||
"hr",
|
||||
"--cache-dir",
|
||||
str(tmp_path),
|
||||
"ocr-rename",
|
||||
"--issue-id",
|
||||
"43476",
|
||||
"--json",
|
||||
]
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
assert "ocr-rename handler reached" in str(exc)
|
||||
assert called == {"issue_id": 43476}
|
||||
return
|
||||
raise AssertionError(f"ocr-rename fell through without reaching handler (rc={rc})")
|
||||
|
||||
|
||||
def test_attachments_list_reaches_handler_not_silent_exit(monkeypatch, tmp_path):
|
||||
called = {}
|
||||
|
||||
def fake_load(cache, issue_id):
|
||||
called["issue_id"] = issue_id
|
||||
raise RuntimeError("attachments handler reached")
|
||||
|
||||
monkeypatch.setattr(redmine_tickets, "TicketCache", DummyCache)
|
||||
monkeypatch.setattr(redmine_tickets, "load_cached_issue", fake_load)
|
||||
|
||||
try:
|
||||
rc = redmine_tickets.main(
|
||||
[
|
||||
"--project",
|
||||
"hr",
|
||||
"--cache-dir",
|
||||
str(tmp_path),
|
||||
"attachments",
|
||||
"list",
|
||||
"--issue-id",
|
||||
"43476",
|
||||
]
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
assert "attachments handler reached" in str(exc)
|
||||
assert called == {"issue_id": 43476}
|
||||
return
|
||||
raise AssertionError(f"attachments fell through without reaching handler (rc={rc})")
|
||||
|
||||
|
||||
def test_view_command_reaches_handler_not_silent_exit(monkeypatch, tmp_path):
|
||||
called = {}
|
||||
|
||||
def fake_load(cache, issue_id):
|
||||
called["issue_id"] = issue_id
|
||||
raise RuntimeError("view handler reached")
|
||||
|
||||
monkeypatch.setattr(redmine_tickets, "TicketCache", DummyCache)
|
||||
monkeypatch.setattr(redmine_tickets, "load_cached_issue", fake_load)
|
||||
|
||||
try:
|
||||
rc = redmine_tickets.main(
|
||||
[
|
||||
"--project",
|
||||
"hr",
|
||||
"--cache-dir",
|
||||
str(tmp_path),
|
||||
"view",
|
||||
"--issue-id",
|
||||
"43476",
|
||||
"--print",
|
||||
]
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
assert "view handler reached" in str(exc)
|
||||
assert called == {"issue_id": 43476}
|
||||
return
|
||||
raise AssertionError(f"view fell through without reaching handler (rc={rc})")
|
||||
Reference in New Issue
Block a user