60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
from accept import (
|
|
AcceptanceReport,
|
|
accept_log_path,
|
|
artifact_dir,
|
|
evidence_shot,
|
|
field_match,
|
|
)
|
|
from errors import NodeError
|
|
import pytest
|
|
|
|
|
|
def test_each_flow_writes_its_own_accept_file(tmp_path, monkeypatch):
|
|
monkeypatch.delenv("RPA_ACCEPT_LOG", raising=False)
|
|
monkeypatch.setattr(
|
|
"accept.SCREENSHOT_ROOT",
|
|
tmp_path,
|
|
)
|
|
report = AcceptanceReport(flow="ORDER_FETCH")
|
|
report.note("S01", "登录", {"user": "u1"}, ok=True)
|
|
path = accept_log_path("ORDER_FETCH")
|
|
assert path == tmp_path / "ORDER_FETCH" / "ACCEPT.txt"
|
|
text = path.read_text(encoding="utf-8")
|
|
assert "ACCEPT SUMMARY ORDER_FETCH 1/1 ok" in text
|
|
assert "ACCEPT S01 ok 登录 user=u1" in text
|
|
|
|
|
|
def test_artifact_dir_is_per_flow():
|
|
assert artifact_dir("REBATE_HEADER").name == "REBATE_HEADER"
|
|
assert artifact_dir("M5_CREATE_ORDER").name == "M5_CREATE_ORDER"
|
|
assert artifact_dir("CONTRACT_CREATE") != artifact_dir("ORDER_FETCH")
|
|
|
|
|
|
def test_check_fails_on_mismatch_without_reading_images():
|
|
report = AcceptanceReport(flow="REBATE_HEADER")
|
|
with pytest.raises(NodeError, match="ACCEPT S02 FAIL"):
|
|
report.check("S02", "总单号", [("rebateOrderNo", "RB-1", "RB-2")])
|
|
|
|
|
|
def test_evidence_shot_skips_success_and_keeps_failure():
|
|
class Fake:
|
|
def __init__(self):
|
|
self.names = []
|
|
|
|
def screenshot(self, name):
|
|
self.names.append(name)
|
|
return name
|
|
|
|
browser = Fake()
|
|
assert evidence_shot(browser, "ok") == ""
|
|
assert browser.names == []
|
|
assert evidence_shot(browser, "bad", failed=True) == "bad"
|
|
assert browser.names == ["bad"]
|
|
|
|
|
|
def test_field_match_accepts_numeric_and_yes_no():
|
|
assert field_match("12.0", "12")
|
|
assert field_match("是", "1")
|
|
assert field_match("2026-08-11", "20260811")
|
|
assert not field_match("重庆其他", "重庆亿昊药业有限公司")
|