Feat: add overwrite when 2 students have the same id and split tests
This commit is contained in:
parent
e5a50e0be8
commit
9ec183c3a5
@ -8,6 +8,10 @@ if TYPE_CHECKING:
|
||||
from backend.model.student import Student
|
||||
|
||||
|
||||
class TribeError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Tribe:
|
||||
name: str
|
||||
@ -18,7 +22,22 @@ class Tribe:
|
||||
def register_assessment(self, assessment: Assessment) -> None:
|
||||
self.assessments.append(assessment)
|
||||
|
||||
@property
|
||||
def students_id(self) -> list[str]:
|
||||
return [s.id for s in self.students]
|
||||
|
||||
def register_student(self, student: Student) -> None:
|
||||
"""Register a student
|
||||
|
||||
If the student is already registered, it is modified.
|
||||
"""
|
||||
try:
|
||||
old_student = next(filter(lambda s: s.id == student.id, self.students))
|
||||
except StopIteration:
|
||||
pass
|
||||
else:
|
||||
self.students.remove(old_student)
|
||||
|
||||
self.students.append(student)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
|
@ -1,9 +1,6 @@
|
||||
from random import randint
|
||||
from uuid import UUID
|
||||
|
||||
from backend.model.student import Student
|
||||
from backend.model.tribe import Tribe
|
||||
from tests.model.fakes import build_assessments, build_tribes
|
||||
from tests.model.fakes import build_tribes
|
||||
|
||||
|
||||
def test_init_student():
|
||||
@ -17,20 +14,3 @@ def test_init_student():
|
||||
|
||||
student2 = Student(name="Hop", tribe=tribe)
|
||||
assert student.id != student2.id
|
||||
|
||||
|
||||
def test_tribe_register_assessment():
|
||||
assessments_qty = randint(1, 10)
|
||||
tribes = build_tribes(1)
|
||||
assessments = build_assessments(tribes, assessments_qty)
|
||||
|
||||
assert len(tribes[0].assessments) == assessments_qty
|
||||
assert tribes[0].assessments == assessments
|
||||
|
||||
|
||||
def test_tribe_register_student():
|
||||
tribe = Tribe("foo", "2nd")
|
||||
student = Student(id="1", name="Bob", tribe=tribe)
|
||||
|
||||
assert len(tribe.students) == 1
|
||||
assert tribe.students[0] == student
|
||||
|
33
tests/model/test_tribe.py
Normal file
33
tests/model/test_tribe.py
Normal file
@ -0,0 +1,33 @@
|
||||
from random import randint
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.model.student import Student
|
||||
from backend.model.tribe import Tribe, TribeError
|
||||
from tests.model.fakes import build_assessments, build_tribes
|
||||
|
||||
|
||||
def test_tribe_register_assessment():
|
||||
assessments_qty = randint(1, 10)
|
||||
tribes = build_tribes(1)
|
||||
assessments = build_assessments(tribes, assessments_qty)
|
||||
|
||||
assert len(tribes[0].assessments) == assessments_qty
|
||||
assert tribes[0].assessments == assessments
|
||||
|
||||
|
||||
def test_tribe_register_student():
|
||||
tribe = Tribe("foo", "2nd")
|
||||
student = Student(id="1", name="Bob", tribe=tribe)
|
||||
|
||||
assert len(tribe.students) == 1
|
||||
assert tribe.students[0] == student
|
||||
|
||||
|
||||
def test_tribe_register_student_already_exists_overwrite():
|
||||
tribe = Tribe("foo", "2nd")
|
||||
student = Student(id="1", name="Bob", tribe=tribe)
|
||||
changed_student = Student(id="1", name="Choupy", tribe=tribe)
|
||||
|
||||
assert tribe.students[0] == changed_student
|
||||
assert student.name not in [s.name for s in tribe.students]
|
Loading…
Reference in New Issue
Block a user