From 3369288e1dfcd40c7b13d69d3b11e5f05e341ac8 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 14 Oct 2026 09:45:53 -0400 Subject: [PATCH] test(prometheus): set the template's version line whatever it is, not only version: 1 (#5693) 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 --- .../integration/test_prometheus_template_library.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_prometheus_template_library.py b/tests/integration/test_prometheus_template_library.py index 931520e..d1e26f6 100644 --- a/tests/integration/test_prometheus_template_library.py +++ b/tests/integration/test_prometheus_template_library.py @@ -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