Feat: autogenerate id for student if none is given

This commit is contained in:
Bertrand Benjamin 2022-12-26 11:46:29 +01:00
parent 2444bf38a1
commit 566ba8e2f5
2 changed files with 6 additions and 3 deletions

View File

@ -1,7 +1,10 @@
from __future__ import annotations
import uuid
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from pydantic import Field
if TYPE_CHECKING:
from backend.model.tribe import Tribe
@ -9,9 +12,9 @@ if TYPE_CHECKING:
@dataclass
class Student:
id: str
name: str
tribe: Tribe
id: Optional[str] = Field(default_factory=lambda: str(uuid.uuid1()))
def __post_init__(self) -> None:
self.tribe.register_student(self)

View File

@ -16,7 +16,7 @@ def test_tribe_register_assessment():
def test_tribe_register_student():
tribe = Tribe("foo", "2nd")
student = Student("1", "Bob", tribe)
student = Student(id="1", name="Bob", tribe=tribe)
assert len(tribe.students) == 1
assert tribe.students[0] == student