test(prometheus): set the template's version line whatever it is, not only version: 1 (#5693)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m15s
CI / unit (push) Successful in 1m29s
CI / publish (push) Successful in 20s

Run 9095: with the Archives template at version 2, the library test's
"bad" copy no longer had a bad version, saved, and took the name the
real save then wanted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 09:45:53 -04:00
co-authored by Claude Opus 5.5
parent 41d9d00216
commit 3369288e1d
@@ -8,6 +8,7 @@ import asyncio
import io
import json
import os
import re
import time
import uuid
@@ -59,6 +60,14 @@ def _prom(sub):
return importlib.import_module(f"{loaded.__name__ if loaded else 'plugins.prometheus'}.{sub}")
def _version(text: str, value: str) -> str:
"""`text` with its top-level version: line set to `value`, whatever the
bundled template's own version is."""
changed, n = re.subn(r"(?m)^version:.*$", f"version: {value}", text, count=1)
assert n == 1
return changed
def _text(page: str) -> str:
return " ".join(page.split())
@@ -89,7 +98,7 @@ def test_an_admin_copies_edits_previews_exports_and_deletes_a_template(app):
# A template with a problem isn't saved, and says where.
bad = await admin.post("/plugins/prometheus/templates/new", headers=CSRF,
form={"text": text.replace("version: 1", "version: one")})
form={"text": _version(text, "one")})
out["bad"] = (bad.status_code, "Not saved." in _text(await bad.get_data(as_text=True)))
# The bundled template's name is taken.
clash = await admin.post("/plugins/prometheus/templates/new", headers=CSRF,
@@ -109,7 +118,7 @@ def test_an_admin_copies_edits_previews_exports_and_deletes_a_template(app):
page = _text(await (await admin.get(where)).get_data(as_text=True))
out["editable"] = f'action="/plugins/prometheus/templates/{key}/edit"' in page and "Your own" in page
renamed = library.renamed(text, f"{mine} v2").replace("version: 1", "version: 2")
renamed = _version(library.renamed(text, f"{mine} v2"), "9")
edit = await admin.post(f"/plugins/prometheus/templates/{key}/edit", headers=CSRF, form={"text": renamed})
out["edited"] = edit.status_code