From a285fdf29e59c3b957247ea9241943c7202e9a28 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 21:20:40 +0100 Subject: refactor(core): consolidate repeated helper logic Centralize SQL row counts, hostname parsing, and content-type normalization so tasks, forms, and scanners share consistent implementations. Simplify periodic task registration and admin lookups with table-driven setup and Flask-SQLAlchemy's built-in 404 helper. --- tests/test_db_helpers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_db_helpers.py (limited to 'tests/test_db_helpers.py') diff --git a/tests/test_db_helpers.py b/tests/test_db_helpers.py new file mode 100644 index 0000000..ac97f2b --- /dev/null +++ b/tests/test_db_helpers.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Regression tests for shared SQLAlchemy row-count handling.""" + +from sqlalchemy import create_engine, text + +from webmentions_ssg.db_helpers import rows_affected + + +def test_rows_affected_for_update_and_delete() -> None: + engine = create_engine("sqlite://") + try: + with engine.begin() as connection: + connection.execute(text("CREATE TABLE entries (id INTEGER PRIMARY KEY)")) + connection.execute(text("INSERT INTO entries (id) VALUES (1)")) + + result = connection.execute(text("UPDATE entries SET id = 2 WHERE id = 1")) + assert rows_affected(result) == 1 + + result = connection.execute(text("DELETE FROM entries WHERE id = 1")) + assert rows_affected(result) == 0 + + result = connection.execute(text("DELETE FROM entries WHERE id = 2")) + assert rows_affected(result) == 1 + finally: + engine.dispose() -- cgit v1.3.1