From ab018f5e4405dc6a3ee214744344ffda73c1fc6f Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 07:44:10 +0100 Subject: 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. --- tests/test_forms.py | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'tests') 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: -- cgit v1.3.1