Feat: add register_assessment for tribe

This commit is contained in:
Bertrand Benjamin 2022-12-20 08:23:52 +01:00
parent a3c44321bf
commit 67b9a1e8a0
6 changed files with 108 additions and 80 deletions

View File

@ -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)

View File

@ -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)

0
tests/model/__init__.py Normal file
View File

View File

@ -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():

View File

@ -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():

79
tests/model/tools.py Normal file
View File

@ -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