diff --git a/backend/model/assessment.py b/backend/model/assessment.py index 27d0bc1..e588544 100644 --- a/backend/model/assessment.py +++ b/backend/model/assessment.py @@ -2,9 +2,10 @@ from __future__ import annotations from dataclasses import dataclass from datetime import date -from typing import Optional +from typing import TYPE_CHECKING, Optional -from backend.model.student import Tribe +if TYPE_CHECKING: + from backend.model.student import Tribe class Assessment: @@ -14,6 +15,8 @@ class Assessment: self.name = name self.exercises = [] + self.tribe.register_assessment(self) + def register_exercise(self, exercise: Exercise): self.exercises.append(exercise) diff --git a/backend/model/student.py b/backend/model/student.py index 8a18aa4..099cf08 100644 --- a/backend/model/student.py +++ b/backend/model/student.py @@ -1,6 +1,10 @@ from __future__ import annotations from dataclasses import dataclass, field +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from backend.model.assessment import Assessment @dataclass @@ -8,8 +12,12 @@ class Tribe: name: str level: str students: list[Student] = field(default_factory=list) + assessments: list[Assessment] = field(default_factory=list) - def register_student(self, student: Student): + def register_assessment(self, assessment: Assessment) -> None: + self.assessments.append(assessment) + + def register_student(self, student: Student) -> None: self.students.append(student) diff --git a/tests/model/__init__.py b/tests/model/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/model/test_assessment.py b/tests/model/test_assessment.py index 7e3dd94..d66d016 100644 --- a/tests/model/test_assessment.py +++ b/tests/model/test_assessment.py @@ -1,82 +1,9 @@ from random import choice, randint -from faker import Faker - -from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill -from backend.model.student import Tribe - -faker = Faker() - - -def build_tribes(quantity=1): - return [Tribe(name=faker.words(5), level=faker.words(5)) for _ in range(quantity)] - - -def build_tribe_assessment(tribe_qty=1, assessment_per_tribe=1): - tribes = build_tribes(tribe_qty) - - assessments = [] - for t in tribes: - assessments += [ - Assessment("faker.words(5)", t, randint(1, 3)) - for _ in range(assessment_per_tribe) - ] - - return tribes, assessments - - -def build_tribe_assessment_exercise( - tribe_qty=1, assessment_per_tribe=1, exercise_per_assessment=1 -): - tribes, assessments = build_tribe_assessment(tribe_qty, assessment_per_tribe) - - exercises = [] - for assessment in assessments: - exercises += [ - Exercise("faker.words(4)", assessment, "today") - for _ in range(exercise_per_assessment) - ] - - return tribes, assessments, exercises - - -def build_skills(quantity=1): - return [Skill(faker.words(6), faker.text()) for _ in range(quantity)] - - -def build_domains(quantity=1): - return [Domain(faker.words(6), faker.text()) for _ in range(quantity)] - - -def build_tribe_assessment_exercise_question( - tribe_qty=1, - assessment_per_tribe=1, - exercise_per_assessment=1, - question_per_exercise=1, -): - tribes, assessments, exercises = build_tribe_assessment_exercise( - tribe_qty, assessment_per_tribe, exercise_per_assessment - ) - - skills = build_skills() - domains = build_domains() - - questions = [] - for exercise in exercises: - questions += [ - Question( - faker.words(2), - exercise, - description="desc", - skill=choice(skills), - domain=choice(domains), - is_leveled=choice([True, False]), - scale=randint(1, 20), - ) - for _ in range(question_per_exercise) - ] - - return tribes, assessments, exercises, questions +from .tools import ( + build_tribe_assessment_exercise, + build_tribe_assessment_exercise_question, +) def test_assessement_register_exercise(): diff --git a/tests/model/test_student.py b/tests/model/test_student.py index d68720b..b31bc9e 100644 --- a/tests/model/test_student.py +++ b/tests/model/test_student.py @@ -1,4 +1,15 @@ +from random import randint + from backend.model.student import Student, Tribe +from tests.model.tools import build_tribe_assessment + + +def test_tribe_register_assessment(): + assessments_qty = randint(1, 10) + tribes, assessments = build_tribe_assessment(assessment_per_tribe=assessments_qty) + + assert len(tribes[0].assessments) == assessments_qty + assert tribes[0].assessments == assessments def test_tribe_register_student(): diff --git a/tests/model/tools.py b/tests/model/tools.py new file mode 100644 index 0000000..611be09 --- /dev/null +++ b/tests/model/tools.py @@ -0,0 +1,79 @@ +from random import choice, randint + +from faker import Faker + +from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill +from backend.model.student import Tribe + +faker = Faker() + + +def build_tribes(quantity=1): + return [Tribe(name=faker.words(5), level=faker.words(5)) for _ in range(quantity)] + + +def build_tribe_assessment(tribe_qty=1, assessment_per_tribe=1): + tribes = build_tribes(tribe_qty) + + assessments = [] + for t in tribes: + assessments += [ + Assessment("faker.words(5)", t, randint(1, 3)) + for _ in range(assessment_per_tribe) + ] + + return tribes, assessments + + +def build_tribe_assessment_exercise( + tribe_qty=1, assessment_per_tribe=1, exercise_per_assessment=1 +): + tribes, assessments = build_tribe_assessment(tribe_qty, assessment_per_tribe) + + exercises = [] + for assessment in assessments: + exercises += [ + Exercise("faker.words(4)", assessment, "today") + for _ in range(exercise_per_assessment) + ] + + return tribes, assessments, exercises + + +def build_skills(quantity=1): + return [Skill(faker.words(6), faker.text()) for _ in range(quantity)] + + +def build_domains(quantity=1): + return [Domain(faker.words(6), faker.text()) for _ in range(quantity)] + + +def build_tribe_assessment_exercise_question( + tribe_qty=1, + assessment_per_tribe=1, + exercise_per_assessment=1, + question_per_exercise=1, +): + tribes, assessments, exercises = build_tribe_assessment_exercise( + tribe_qty, assessment_per_tribe, exercise_per_assessment + ) + + skills = build_skills() + domains = build_domains() + + questions = [] + for exercise in exercises: + questions += [ + Question( + faker.words(2), + exercise, + description="desc", + skill=choice(skills), + domain=choice(domains), + is_leveled=choice([True, False]), + scale=randint(1, 20), + ) + for _ in range(question_per_exercise) + ] + + return tribes, assessments, exercises, questions