From d0e245d63e014d268310976fc45429f08d2cbbe9 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Wed, 19 Aug 2026 19:49:55 +0200 Subject: refactor(core): improve typing and test coverage Restructure database and user CLI commands, make passwords write-only model properties, and use the UTC datetime constant throughout the application. Add PEP 287-style documentation and expand receiver, scanner, sender, and URL security tests to cover error paths and edge cases. --- webmentions_ssg/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'webmentions_ssg/models.py') diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py index b6679e8..f89e587 100644 --- a/webmentions_ssg/models.py +++ b/webmentions_ssg/models.py @@ -1,7 +1,7 @@ from __future__ import annotations import uuid -from datetime import datetime, timezone +from datetime import UTC, datetime from enum import StrEnum from flask_login import UserMixin @@ -38,7 +38,12 @@ class User(UserMixin, Base): def __repr__(self) -> str: return f"" - def set_password(self, password: str) -> None: + @property + def password(self) -> None: + raise AttributeError("Password is write-only") + + @password.setter + def password(self, password: str) -> None: self.password_hash = generate_password_hash(password) def check_password(self, password: str) -> bool: @@ -60,8 +65,8 @@ class ReceivedWebmention(Base): updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=lambda: datetime.now(timezone.utc), - onupdate=lambda: datetime.now(timezone.utc), + default=lambda: datetime.now(UTC), + onupdate=lambda: datetime.now(UTC), nullable=False, ) @@ -185,4 +190,4 @@ class SentWebmention(Base): def uuid7_to_datetime(identifier: uuid.UUID) -> datetime: - return datetime.fromtimestamp(identifier.time / 1000, tz=timezone.utc) + return datetime.fromtimestamp(identifier.time / 1000, tz=UTC) -- cgit v1.3.1