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 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import asyncio
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -59,6 +60,14 @@ def _prom(sub):
|
|||||||
return importlib.import_module(f"{loaded.__name__ if loaded else 'plugins.prometheus'}.{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:
|
def _text(page: str) -> str:
|
||||||
return " ".join(page.split())
|
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.
|
# A template with a problem isn't saved, and says where.
|
||||||
bad = await admin.post("/plugins/prometheus/templates/new", headers=CSRF,
|
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)))
|
out["bad"] = (bad.status_code, "Not saved." in _text(await bad.get_data(as_text=True)))
|
||||||
# The bundled template's name is taken.
|
# The bundled template's name is taken.
|
||||||
clash = await admin.post("/plugins/prometheus/templates/new", headers=CSRF,
|
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))
|
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
|
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})
|
edit = await admin.post(f"/plugins/prometheus/templates/{key}/edit", headers=CSRF, form={"text": renamed})
|
||||||
out["edited"] = edit.status_code
|
out["edited"] = edit.status_code
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user