fix(domain): validate participant name types
This commit is contained in:
1 parent
9dbf98fee1
commit
f435b64d3c
3 files changed
+13
-2
No files matched your search
+3
-2
@@ -103,7 +103,7 @@ class CoachingSession:
|
|||||||
if self.kitten_independence not in ("самостоятельно", "несамостоятельно"):
|
if self.kitten_independence not in ("самостоятельно", "несамостоятельно"):
|
||||||
raise ValueError("Некорректный статус самостоятельности")
|
raise ValueError("Некорректный статус самостоятельности")
|
||||||
for name, kitten_id, independence in self.extra_kittens:
|
for name, kitten_id, independence in self.extra_kittens:
|
||||||
if not name.strip():
|
if not isinstance(name, str) or not name.strip():
|
||||||
raise ValueError("Имя дополнительного котёнка не может быть пустым")
|
raise ValueError("Имя дополнительного котёнка не может быть пустым")
|
||||||
_positive_id(kitten_id, "ID дополнительного котёнка")
|
_positive_id(kitten_id, "ID дополнительного котёнка")
|
||||||
if independence not in ("самостоятельно", "несамостоятельно"):
|
if independence not in ("самостоятельно", "несамостоятельно"):
|
||||||
@@ -239,7 +239,8 @@ class TrainingSession:
|
|||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Валидирует данные сессии тренировки."""
|
"""Валидирует данные сессии тренировки."""
|
||||||
if not self.escort_name.strip() or not self.kitten_name.strip():
|
if (not isinstance(self.escort_name, str) or not self.escort_name.strip()
|
||||||
|
or not isinstance(self.kitten_name, str) or not self.kitten_name.strip()):
|
||||||
raise ValueError("Имена участников не могут быть пустыми")
|
raise ValueError("Имена участников не могут быть пустыми")
|
||||||
_positive_id(self.escort_id, "ID сопровождающего")
|
_positive_id(self.escort_id, "ID сопровождающего")
|
||||||
_positive_id(self.kitten_id, "ID котёнка")
|
_positive_id(self.kitten_id, "ID котёнка")
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
- 2026-08-25: admin history sorting now tolerates legacy records whose IDs were stored as strings, preserving numeric order for valid IDs instead of failing the complete history view.
|
- 2026-08-25: admin history sorting now tolerates legacy records whose IDs were stored as strings, preserving numeric order for valid IDs instead of failing the complete history view.
|
||||||
- 2026-08-25: coaching sessions now validate a real calendar date in `ДД.ММ` form before any calculation or persistence; free-form dates remain accepted after parser normalization.
|
- 2026-08-25: coaching sessions now validate a real calendar date in `ДД.ММ` form before any calculation or persistence; free-form dates remain accepted after parser normalization.
|
||||||
- 2026-08-25: coaching and training reports reject a repeated participant ID, including an escort submitted as their own kitten, so duplicate input cannot inflate a result.
|
- 2026-08-25: coaching and training reports reject a repeated participant ID, including an escort submitted as their own kitten, so duplicate input cannot inflate a result.
|
||||||
|
- 2026-08-25: direct domain calls with non-text participant names now return the same clear validation errors as API and VK input, rather than an implementation-level attribute error.
|
||||||
- 2026-08-25: one-line VK/web recognition now gives explicit role labels priority over position. `сопровождающий`/`наставник`/`учитель` identify the escort, while `ученик`/`котёнок`/`бельчонок`/`подопечный` identify the ward; unlabeled pairs retain the original order-based fallback.
|
- 2026-08-25: one-line VK/web recognition now gives explicit role labels priority over position. `сопровождающий`/`наставник`/`учитель` identify the escort, while `ученик`/`котёнок`/`бельчонок`/`подопечный` identify the ward; unlabeled pairs retain the original order-based fallback.
|
||||||
- 2026-08-25: a self-sufficiency marker directly beside a labelled ward now belongs to that ward, so one natural line can describe different statuses for several kittens.
|
- 2026-08-25: a self-sufficiency marker directly beside a labelled ward now belongs to that ward, so one natural line can describe different statuses for several kittens.
|
||||||
- 2026-08-25: corrected Russian UX copy in the VK help and attachment flow; the web identity hint now accurately says that a manually completed pair applies only to the current calculation.
|
- 2026-08-25: corrected Russian UX copy in the VK help and attachment flow; the web identity hint now accurately says that a manually completed pair applies only to the current calculation.
|
||||||
|
|||||||
@@ -102,6 +102,15 @@ class CalculationTests(unittest.TestCase):
|
|||||||
with self.assertRaisesRegex(ValueError, "разными персонажами"):
|
with self.assertRaisesRegex(ValueError, "разными персонажами"):
|
||||||
TrainingSession("Белка", 1, "Белка", 1)
|
TrainingSession("Белка", 1, "Белка", 1)
|
||||||
|
|
||||||
|
def test_sessions_reject_non_text_participant_names_with_a_domain_error(self):
|
||||||
|
with self.assertRaisesRegex(ValueError, "Имена участников"):
|
||||||
|
TrainingSession("Белка", 1, None, 2) # type: ignore[arg-type]
|
||||||
|
with self.assertRaisesRegex(ValueError, "дополнительного котёнка"):
|
||||||
|
CoachingSession(
|
||||||
|
"15.08", "ЛУ", "11:00", "12:00", "Белка", 1, "Первый", 2,
|
||||||
|
extra_kittens=((None, 3, "самостоятельно"),), # type: ignore[arg-type]
|
||||||
|
)
|
||||||
|
|
||||||
def test_zu_rejects_non_self_kitten(self):
|
def test_zu_rejects_non_self_kitten(self):
|
||||||
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
|
with self.assertRaisesRegex(ValueError, "Для ЗУ все котята должны быть самостоятельными"):
|
||||||
CoachingSession(
|
CoachingSession(
|
||||||
|
|||||||
Reference in new issue
Block a user