Initial Commit: Status Testing
This commit is contained in:
1 parent
1eff675f05
commit
42dd1f2d4a
286 files changed
+64800
-369
No files matched your search
@@ -0,0 +1,52 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Eigene Mail-Vorlagen ohne Datenbank: Platzhalter, Prüfung, Anwenden."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
from surveybox.mail import custom, render
|
||||
|
||||
|
||||
def context(**extra: object) -> dict[str, object]:
|
||||
return {"app_name": "Feuerwehr", "origin": "https://x", "name": "Erika",
|
||||
"form": SimpleNamespace(title="Sommerfest"), "link": "https://x/f/abc",
|
||||
"guest": False, "links_url": "https://x/links", "unsubscribe_url": None,
|
||||
"settings_url": "https://x/s", **extra}
|
||||
|
||||
|
||||
def test_placeholders_follow_the_template() -> None:
|
||||
assert {"greeting", "details", "app", "title", "name", "link", "entry"} <= set(
|
||||
custom.placeholders("promoted"))
|
||||
assert "title" not in custom.placeholders("invite")
|
||||
assert custom.required("invite") == ["link"]
|
||||
assert custom.required("register_exists") == ["forgot_url", "login_url"]
|
||||
|
||||
|
||||
def test_validate() -> None:
|
||||
ok = custom.clean(" Platz für {name}\n ", "{greeting}\r\n\r\nSchön!\n\n{details}")
|
||||
assert ok.subject == "Platz für {name}" and "\r" not in ok.body
|
||||
assert custom.validate("promoted", ok) == []
|
||||
errors = dict(custom.validate("promoted", custom.Custom("", "Hallo {nope} ohne Link")))
|
||||
assert set(errors) == {"subject", "unknown", "missing"}
|
||||
assert errors["unknown"] == "{nope}" and errors["missing"] == "{link}"
|
||||
assert custom.validate("promoted", custom.Custom("x", "Hier: {link}")) == []
|
||||
|
||||
|
||||
def test_render_with_custom_text() -> None:
|
||||
own = custom.Custom("Platz frei bei {app}: {title}",
|
||||
"{greeting}\n\nWir freuen uns!\n\n{details}\n\nEure Feuerwehr")
|
||||
mail = render.render("promoted", "en", context(entry="Früh"), own)
|
||||
assert mail.subject == "Platz frei bei Feuerwehr: Sommerfest"
|
||||
assert mail.text.startswith("Hello Erika,\n\nWir freuen uns!\n\nA place")
|
||||
assert "https://x/f/abc" in mail.text and "Eure Feuerwehr" in mail.text
|
||||
assert mail.text.count("Hello Erika") == 1 # Anrede nicht doppelt
|
||||
assert '<a href="https://x/f/abc">' in mail.html and "-- \n" in mail.text
|
||||
# Ohne Namen: allgemeine Anrede
|
||||
plain = render.render("promoted", "en", context(name="", entry="Früh"), own)
|
||||
assert plain.text.startswith("Hello,\n\nWir")
|
||||
|
||||
|
||||
def test_preview_with_missing_values() -> None:
|
||||
mail = render.render("confirmed", "en", {"name": "A"}, strict=False)
|
||||
assert mail.subject and mail.text
|
||||
Reference in new issue
Block a user