Feat: autogenerate id for student if none is given
This commit is contained in:
parent
2444bf38a1
commit
566ba8e2f5
@ -1,7 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from backend.model.tribe import Tribe
|
from backend.model.tribe import Tribe
|
||||||
@ -9,9 +12,9 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Student:
|
class Student:
|
||||||
id: str
|
|
||||||
name: str
|
name: str
|
||||||
tribe: Tribe
|
tribe: Tribe
|
||||||
|
id: Optional[str] = Field(default_factory=lambda: str(uuid.uuid1()))
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
self.tribe.register_student(self)
|
self.tribe.register_student(self)
|
||||||
|
@ -16,7 +16,7 @@ def test_tribe_register_assessment():
|
|||||||
|
|
||||||
def test_tribe_register_student():
|
def test_tribe_register_student():
|
||||||
tribe = Tribe("foo", "2nd")
|
tribe = Tribe("foo", "2nd")
|
||||||
student = Student("1", "Bob", tribe)
|
student = Student(id="1", name="Bob", tribe=tribe)
|
||||||
|
|
||||||
assert len(tribe.students) == 1
|
assert len(tribe.students) == 1
|
||||||
assert tribe.students[0] == student
|
assert tribe.students[0] == student
|
||||||
|
Loading…
Reference in New Issue
Block a user