39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Unit tests for canonical flow files (export.py). No DB or LFX needed."""
|
|
|
|
import json
|
|
|
|
from app.flows import export
|
|
|
|
|
|
def test_slugify():
|
|
assert export.slugify("Dachsanierung 200k") == "dachsanierung-200k"
|
|
assert export.slugify(" A/B\\C ") == "a-b-c"
|
|
assert export.slugify("simple_rule") == "simple-rule"
|
|
assert export.slugify("") == "flow"
|
|
|
|
|
|
def test_canonical_bytes_stable_under_key_reorder():
|
|
doc = {"name": "x", "data": {"nodes": [], "edges": []}, "tags": ["b", "a"]}
|
|
shuffled = {"tags": ["b", "a"], "data": {"edges": [], "nodes": []}, "name": "x"}
|
|
assert export.canonical_bytes(shuffled) == export.canonical_bytes(doc)
|
|
assert export.content_hash(doc) == export.content_hash(shuffled)
|
|
|
|
|
|
def test_write_and_read_roundtrip_is_byte_stable(tmp_path):
|
|
doc = {"name": "My Flow", "data": {"nodes": [], "edges": []}}
|
|
path = export.write_flow_file(tmp_path, doc)
|
|
assert path == tmp_path / "my-flow.json"
|
|
assert json.loads(path.read_text()) == doc
|
|
# Rewriting identical content is byte-identical (no phantom git diffs).
|
|
before = path.read_bytes()
|
|
export.write_flow_file(tmp_path, doc)
|
|
assert path.read_bytes() == before
|
|
|
|
|
|
def test_iter_flow_files_only_top_level_json(tmp_path):
|
|
(tmp_path / "a.json").write_text("{}")
|
|
(tmp_path / "b.txt").write_text("{}")
|
|
sub = tmp_path / "sub"
|
|
sub.mkdir()
|
|
(sub / "c.json").write_text("{}")
|
|
assert export.iter_flow_files(tmp_path) == [tmp_path / "a.json"]
|