runbook-tutorials/tests/test_feedback.py

42 lines
1.3 KiB
Python
Raw Normal View History

import shutil
from pathlib import Path
import pytest
from rtut import pack as P, run as R
ROOT = Path(__file__).resolve().parent.parent
@pytest.fixture
def pk(tmp_path):
d = tmp_path / "runbooks" / "hello"; d.mkdir(parents=True)
shutil.copy(ROOT / "runbooks/example-hello/pack.yaml", d / "pack.yaml")
return P.load(d / "pack.yaml")
def test_feedback_latest_wins_and_history_kept(pk):
r = R.create(pk, "bernd")
R.add_feedback(r, "poor", "confusing start")
R.add_feedback(r, "good", "fine after a second look")
r2 = R.load(pk, r.data["run_id"])
assert len(r2.data["feedback"]) == 2
assert R.latest_feedback(r2)["rating"] == "good"
def test_feedback_rejects_bad_rating_and_secrets(pk):
r = R.create(pk, "bernd")
with pytest.raises(R.RunError):
R.add_feedback(r, "great")
with pytest.raises(R.RunError):
R.add_feedback(r, "good", "-----BEGIN RSA PRIVATE KEY-----")
assert "feedback" not in R.load(pk, r.data["run_id"]).data
def test_all_feedback_lists_newest_first(pk):
a = R.create(pk, "ann"); b = R.create(pk, "bob"); R.create(pk, "cy") # cy gives none
R.add_feedback(a, "good", "one")
R.add_feedback(b, "poor", "two")
got = R.all_feedback(pk)
assert [g["operator"] for g in got] == ["bob", "ann"]