diff options
| author | Dennis Fink | 2026-08-19 19:49:55 +0200 |
|---|---|---|
| committer | Dennis Fink | 2026-08-19 19:49:55 +0200 |
| commit | d0e245d63e014d268310976fc45429f08d2cbbe9 (patch) | |
| tree | ef2e96570723190baf02f05c2c4644a19ff1af78 /webmentions_ssg/models.py | |
| parent | d4a03623544aac0ce911d8471ff4b033bc3255e1 (diff) | |
| download | webmentions-ssg-d0e245d63e014d268310976fc45429f08d2cbbe9.tar.gz webmentions-ssg-d0e245d63e014d268310976fc45429f08d2cbbe9.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/models.py | 15 |
1 files changed, 10 insertions, 5 deletions
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"<User {self.username}>" - 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) |
