Organized
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""NMI runtime-profile contract for the Redmine CLI/TUI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import redmine_ticket_nmi
|
||||
|
||||
|
||||
def test_runtime_profile_honors_explicit_production_mode_and_env_file(tmp_path):
|
||||
production_env = tmp_path / "production.env"
|
||||
production_env.write_text("NMI_ENDPOINT_PRODUCTION=https://app.ldrprep.com/api.php\n")
|
||||
|
||||
profile = redmine_ticket_nmi.resolve_runtime_profile(
|
||||
environ={
|
||||
"NMI_MODE": "production",
|
||||
"NMI_ENV_FILE": str(production_env),
|
||||
}
|
||||
)
|
||||
|
||||
assert profile.mode == "production"
|
||||
assert profile.env_file == production_env
|
||||
assert profile.ready is True
|
||||
assert profile.problem is None
|
||||
|
||||
|
||||
def test_runtime_profile_rejects_empty_env_file(tmp_path):
|
||||
empty_env = tmp_path / "empty.env"
|
||||
empty_env.touch()
|
||||
|
||||
profile = redmine_ticket_nmi.resolve_runtime_profile(
|
||||
environ={
|
||||
"NMI_MODE": "production",
|
||||
"NMI_ENV_FILE": str(empty_env),
|
||||
}
|
||||
)
|
||||
|
||||
assert profile.mode == "production"
|
||||
assert profile.ready is False
|
||||
assert "empty" in profile.problem.lower()
|
||||
|
||||
|
||||
def test_brief_refuses_unready_runtime_profile(monkeypatch, tmp_path):
|
||||
empty_env = tmp_path / "empty.env"
|
||||
empty_env.touch()
|
||||
|
||||
monkeypatch.setattr(
|
||||
redmine_ticket_nmi,
|
||||
"resolve_runtime_profile",
|
||||
lambda **_kwargs: redmine_ticket_nmi.NmiRuntimeProfile(
|
||||
mode="production",
|
||||
env_file=empty_env,
|
||||
nmi_bin=Path("/tmp/nmi"),
|
||||
endpoint=None,
|
||||
ready=False,
|
||||
problem="NMI env file is empty",
|
||||
),
|
||||
)
|
||||
|
||||
payload = redmine_ticket_nmi.brief_for_issue(
|
||||
{"id": 123, "subject": "item 200000001"},
|
||||
[{"type": "item_no", "value": "200000001", "confidence": "high"}],
|
||||
mode="production",
|
||||
env_file=str(empty_env),
|
||||
)
|
||||
|
||||
assert payload["ok"] is False
|
||||
assert payload["error"] == "nmi_runtime_not_ready"
|
||||
assert "empty" in payload["runtime"]["problem"].lower()
|
||||
Reference in New Issue
Block a user