From c5492398f100ccb154fa557d657bae2322f95cf7 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 21 Aug 2026 10:37:56 +0200 Subject: test(core): align tests with module ownership Move direct validator, model, and Huey extension coverage into dedicated test modules and mock dependencies where behavior belongs to another module. Expand Huey extension typing and coverage while removing duplicate assertions from scanner, sender, form, and view tests. --- tests/test_forms.py | 96 ----------------------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 tests/test_forms.py (limited to 'tests/test_forms.py') diff --git a/tests/test_forms.py b/tests/test_forms.py deleted file mode 100644 index fc16858..0000000 --- a/tests/test_forms.py +++ /dev/null @@ -1,96 +0,0 @@ -# SPDX-FileCopyrightText: 2026 Dennis Fink -# -# SPDX-License-Identifier: BSD-3-Clause - -from unittest.mock import patch - -import pytest -from flask import Flask -from werkzeug.datastructures import MultiDict - -from webmentions_ssg.forms import EndpointForm - -VALID_SOURCE = "https://source.example/post" -VALID_TARGET = "https://dennisfink.me/blog/example/" - - -@patch("webmentions_ssg.forms.validators.is_public_url", new=lambda url: True) -@pytest.mark.parametrize( - ("form_data", "invalid_field", "expected_error"), - [ - pytest.param( - {"target": VALID_TARGET}, - "source", - "This field is required.", - id="source-required", - ), - pytest.param( - {"source": "not a URL", "target": VALID_TARGET}, - "source", - "Invalid URL.", - id="source-url", - ), - pytest.param( - {"source": "ftp://source.example/post", "target": VALID_TARGET}, - "source", - "source must begin with http or https", - id="source-scheme", - ), - pytest.param( - {"source": VALID_TARGET, "target": VALID_TARGET}, - "source", - None, - id="source-not-equal-to-target", - ), - pytest.param( - {"source": VALID_SOURCE}, - "target", - "This field is required.", - id="target-required", - ), - pytest.param( - {"source": VALID_SOURCE, "target": "not a URL"}, - "target", - "Invalid URL.", - id="target-url", - ), - pytest.param( - {"source": VALID_SOURCE, "target": "ftp://dennisfink.me/blog/example/"}, - "target", - "target must begin with http or https", - id="target-scheme", - ), - pytest.param( - {"source": VALID_SOURCE, "target": "https://example.com/post"}, - "target", - None, - id="target-allowed-hostname", - ), - ], -) -def test_endpoint_form_rejects_invalid_data( - app: Flask, - form_data: dict[str, str], - invalid_field: str, - expected_error: str | None, -) -> None: - with app.test_request_context("/endpoint", method="POST"): - form = EndpointForm(formdata=MultiDict(form_data), meta={"csrf": False}) - - assert not form.validate() - assert invalid_field in form.errors - - if expected_error is not None: - assert expected_error in form.errors[invalid_field] - - -@patch("webmentions_ssg.forms.validators.is_public_url", new=lambda url: True) -def test_endpoint_form_accepts_valid_data(app: Flask) -> None: - with app.test_request_context("/endpoint", method="POST"): - form = EndpointForm( - formdata=MultiDict({"source": VALID_SOURCE, "target": VALID_TARGET}), - meta={"csrf": False}, - ) - - assert form.validate() - assert form.errors == {} -- cgit v1.3.1