Files
mtusi2026lab2/src/messenger/identity/domain/values.py
T
ArtyomandClaude Opus 5.5 540fcb35ba Carry over the lab 4 solution
Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6 and RustFS configuration, migrations, hooks, evidence and
scenario scripts and the CI job from the lab 4 solution commit d2744bc,
merge the lab 4 Makefile targets into the lab 5 skeleton Makefile
without touching its targets, and append the lab 4 solution variables
to the skeleton .env.example. The package and the application follow
the contract version 1.5.0, and the image and the throwaway test
containers are tagged lab5 so they do not collide with a lab 4 stand on
the same host.

This is the starting point of the lab 5 cycle: lint, own tests and the
offline skeleton check pass before any lab 5 change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 00:34:03 +03:00

55 lines
1.9 KiB
Python

import re
from dataclasses import dataclass, field
from messenger.identity.domain.errors import InvalidUserData
USERNAME_PATTERN = re.compile(r"\A[a-z0-9_]{3,32}\Z")
DISPLAY_NAME_MAX = 100
PASSWORD_MIN = 12
PASSWORD_MAX = 128
@dataclass(frozen=True, slots=True)
class Username:
value: str
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidUserData("поле username должно быть строкой")
if USERNAME_PATTERN.match(self.value) is None:
raise InvalidUserData("поле username должно соответствовать [a-z0-9_]{3,32}")
def __str__(self) -> str:
return self.value
@dataclass(frozen=True, slots=True)
class DisplayName:
value: str
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidUserData("поле display_name должно быть строкой")
if not self.value.strip():
raise InvalidUserData("поле display_name не может быть пустым или состоять из пробелов")
if len(self.value) > DISPLAY_NAME_MAX:
raise InvalidUserData(f"поле display_name длиннее {DISPLAY_NAME_MAX} символов Unicode")
def __str__(self) -> str:
return self.value
@dataclass(frozen=True, slots=True)
class Password:
value: str = field(repr=False)
def __post_init__(self) -> None:
if not isinstance(self.value, str):
raise InvalidUserData("поле password должно быть строкой")
if not self.value.strip():
raise InvalidUserData("поле password не может состоять из пробелов")
if not PASSWORD_MIN <= len(self.value) <= PASSWORD_MAX:
raise InvalidUserData(
f"поле password: от {PASSWORD_MIN} до {PASSWORD_MAX} символов Unicode"
)