From e496d8682849f10a37e1decd3118be94e3beaceb Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 20 Dec 2022 07:18:48 +0100 Subject: [PATCH] Feat: first step in assessment aggregate --- backend/model/assessment.py | 68 ++++++++++++++++++++++++++++++++++ tests/model/test_assessment.py | 56 ++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 backend/model/assessment.py create mode 100644 tests/model/test_assessment.py diff --git a/backend/model/assessment.py b/backend/model/assessment.py new file mode 100644 index 0000000..27d0bc1 --- /dev/null +++ b/backend/model/assessment.py @@ -0,0 +1,68 @@ +from __future__ import annotations + +from dataclasses import dataclass +from datetime import date +from typing import Optional + +from backend.model.student import Tribe + + +class Assessment: + def __init__(self, name: str, tribe: Tribe, term: int) -> None: + self.tribe = tribe + self.term = term + self.name = name + self.exercises = [] + + def register_exercise(self, exercise: Exercise): + self.exercises.append(exercise) + + @property + def questions(self): + return sum([exercise.questions for exercise in self.exercises]) + + +class Exercise: + def __init__(self, name: str, assessment: Assessment, date: Optional[date]) -> None: + self.name = name + self.assessment = assessment + self.date = date + self.questions = [] + + self.assessment.register_exercise(self) + + def register_question(self, question: Question): + self.questions.append(question) + + +@dataclass(frozen=True) +class Domain: + name: str + description: str + + +@dataclass(frozen=True) +class Skill: + name: str + description: str + + +class Question: + def __init__( + self, + name: str, + exercise: Exercise, + description: str, + skill: Skill, + domain: Domain, + is_leveled: bool, + scale: int, + ) -> None: + self.name = name + self.exercise = exercise + self.exercise.register_question(self) + self.description = description + self.skill = skill + self.domain = domain + self.is_leveled = is_leveled + self.scale = scale diff --git a/tests/model/test_assessment.py b/tests/model/test_assessment.py new file mode 100644 index 0000000..59b4368 --- /dev/null +++ b/tests/model/test_assessment.py @@ -0,0 +1,56 @@ +from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill +from backend.model.student import Tribe + + +def build_tribe(): + return Tribe("plop", "2nd") + + +def build_tribe_assessment(): + tribe = build_tribe() + assessment = Assessment("DS1", tribe, 1) + return tribe, assessment + + +def build_tribe_assessment_exercise(): + tribe, assessment = build_tribe_assessment() + exercise = Exercise("ex1", assessment, "today") + return tribe, assessment, exercise + + +def build_skills(): + return [Skill("search", "Searching and finding")] + + +def build_domains(): + return [Domain("function", "Functions are great")] + + +def build_tribe_assessment_exercise_question(): + tribe, assessment, exercise = build_tribe_assessment_exercise() + skills = build_skills() + domains = build_domains() + question = Question( + "a", + exercise, + description="desc", + skill=skills[0], + domain=domains[0], + is_leveled=True, + scale=1, + ) + return tribe, assessment, exercise, question + + +def test_assessement_register_exercise(): + tribe, assessment, exercise = build_tribe_assessment_exercise() + + assert len(assessment.exercises) == 1 + assert assessment.exercises[0] == exercise + + +def test_exercise_register_question(): + tribe, assessment, exercise, question = build_tribe_assessment_exercise_question() + + assert len(exercise.questions) == 1 + assert exercise.questions[0] == question