aboutsummaryrefslogtreecommitdiff
path: root/tests/test_forms.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 07:44:10 +0100
committerDennis Fink2026-11-13 07:44:10 +0100
commitab018f5e4405dc6a3ee214744344ffda73c1fc6f (patch)
tree06390ada60e632b9ac6324ea4b7015a40d3360e7 /tests/test_forms.py
parent52fc66cb5ff19bf0def001ae50acc1b465a0b977 (diff)
downloadwebmentions-ssg-ab018f5e4405dc6a3ee214744344ffda73c1fc6f.tar.gz
webmentions-ssg-ab018f5e4405dc6a3ee214744344ffda73c1fc6f.zip
refactor(core): inline endpoint source comparison
Remove the generic cross-field equality validator and keep the source-versus-target check directly on `EndpointForm`, where the validation rule is actually used.
Diffstat (limited to 'tests/test_forms.py')
-rw-r--r--tests/test_forms.py34
1 files changed, 8 insertions, 26 deletions
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 03789da..87b02cd 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -12,7 +12,6 @@ from webmentions_ssg.forms import (
AllowedHostname,
EndpointForm,
LoginForm,
- NotEqualTo,
PublicIPLiteral,
URLMaxBytes,
)
@@ -21,11 +20,6 @@ VALID_SOURCE = "https://source.example/post"
VALID_TARGET = "https://dennisfink.me/blog/example/"
-class ComparisonForm(Form):
- source = StringField("Source")
- target = StringField("Target")
-
-
class URLForm(Form):
url = StringField("URL")
@@ -223,27 +217,15 @@ def test_endpoint_accepts_encoded_path_space(app: Flask) -> None:
assert form.validate()
-def test_not_equal_to_accepts_different_values() -> None:
- form = ComparisonForm(MultiDict({"source": "source", "target": "target"}))
- NotEqualTo("target")(form, form.source)
-
-
-def test_not_equal_to_rejects_equal_values() -> None:
- form = ComparisonForm(MultiDict({"source": "same", "target": "same"}))
- with pytest.raises(ValidationError, match="Field must not be equal to target"):
- NotEqualTo("target")(form, form.source)
-
-
-def test_not_equal_to_uses_custom_message() -> None:
- form = ComparisonForm(MultiDict({"source": "same", "target": "same"}))
- with pytest.raises(ValidationError, match="Must differ from Target"):
- NotEqualTo("target", "Must differ from %(other_label)s")(form, form.source)
-
+def test_endpoint_form_rejects_matching_source_and_target(app: Flask) -> None:
+ with app.test_request_context("/endpoint", method="POST"):
+ form = EndpointForm(
+ formdata=MultiDict({"source": VALID_TARGET, "target": VALID_TARGET}),
+ meta={"csrf": False},
+ )
-def test_not_equal_to_rejects_unknown_field() -> None:
- form = ComparisonForm(MultiDict({"source": "source", "target": "target"}))
- with pytest.raises(ValidationError, match="Invalid field name 'missing'"):
- NotEqualTo("missing")(form, form.source)
+ assert not form.validate()
+ assert "Field must not be equal to target." in form.errors["source"]
def test_allowed_hostname_accepts_configured_hostname(app: Flask) -> None: