Feat: build tribe and student model
This commit is contained in:
parent
a2a0269f39
commit
c4fcb6a0ef
28
backend/model/student.py
Normal file
28
backend/model/student.py
Normal file
@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
@dataclass
|
||||
class Tribe:
|
||||
name: str
|
||||
level: str
|
||||
students: list[Student] = field(default_factory=list)
|
||||
|
||||
def register_student(self, student: Student):
|
||||
self.students.append(student)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Student:
|
||||
def __init__(self, id: str, name: str, tribe: Tribe) -> None:
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.tribe = tribe
|
||||
|
||||
self.tribe.register_student(self)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, Student):
|
||||
return self.id == other.id
|
||||
return False
|
9
tests/model/test_student.py
Normal file
9
tests/model/test_student.py
Normal file
@ -0,0 +1,9 @@
|
||||
from backend.model.student import Student, Tribe
|
||||
|
||||
|
||||
def test_tribe_register_student():
|
||||
tribe = Tribe("foo", "2nd")
|
||||
student = Student("1", "Bob", tribe)
|
||||
|
||||
assert len(tribe.students) == 1
|
||||
assert tribe.students[0] == student
|
Loading…
Reference in New Issue
Block a user