recopytex/tests/model/test_assessment.py

103 lines
2.7 KiB
Python
Raw Normal View History

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
def test_assessement_register_exercise():
exercise_qty = randint(1, 10)
tribes, assessments, exercises = build_tribe_assessment_exercise(
exercise_per_assessment=exercise_qty
)
assert len(assessments[0].exercises) == exercise_qty
assert assessments[0].exercises == exercises
def test_exercise_register_question():
question_qty = randint(1, 10)
(
tribes,
assessments,
exercises,
questions,
) = build_tribe_assessment_exercise_question(question_per_exercise=question_qty)
assert len(exercises[0].questions) == question_qty
assert exercises[0].questions == questions