recopytex/tests/model/fakes.py

69 lines
1.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.tribe import Tribe
faker = Faker()
def build_tribes(quantity: int = 1):
return [Tribe(name=faker.words(5), level=faker.words(5)) for _ in range(quantity)]
def build_assessments(tribes: list[Tribe], assessment_per_tribe: int = 1):
assessments = []
for t in tribes:
assessments += [
Assessment("faker.words(5)", t, randint(1, 3))
for _ in range(assessment_per_tribe)
]
return assessments
def build_exercises(assessments: list[Assessment], exercise_per_assessment=1):
exercises = []
for assessment in assessments:
exercises += [
Exercise("faker.words(4)", assessment, "today")
for _ in range(exercise_per_assessment)
]
return 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_questions(
exercises: list[Exercise],
question_per_exercise=1,
):
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 questions