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
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user