Fix: name generation by not using words but word

This commit is contained in:
Bertrand Benjamin 2022-12-27 06:59:00 +01:00
parent dfd0bb2b81
commit 7d908775a9

View File

@ -1,53 +1,65 @@
from random import choice, randint
from faker import Faker
from faker.providers import DynamicProvider
from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill
from backend.model.student import Student
from backend.model.tribe import Tribe
from backend.repository.abstract_repository import AbstractRepository
faker = Faker()
level_provider = DynamicProvider(
provider_name="level",
elements=["2nd", "1ST", "SNT", "1G", "TG", "EnsSci"],
)
faker = Faker("fr_FR")
faker.add_provider(level_provider)
def build_tribes(quantity: int = 1):
return [Tribe(name=faker.words(5), level=faker.words(5)) for _ in range(quantity)]
def build_tribes(quantity: int = 1) -> list[Tribe]:
return [Tribe(name=faker.word(), level=faker.level()) for _ in range(quantity)]
def build_assessments(tribes: list[Tribe], assessment_per_tribe: int = 1):
def build_assessments(
tribes: list[Tribe], assessment_per_tribe: int = 1
) -> list[Assessment]:
assessments = []
for t in tribes:
assessments += [
Assessment("faker.words(5)", t, randint(1, 3))
Assessment("faker.word()", t, randint(1, 3))
for _ in range(assessment_per_tribe)
]
return assessments
def build_exercises(assessments: list[Assessment], exercise_per_assessment=1):
def build_exercises(
assessments: list[Assessment], exercise_per_assessment=1
) -> list[Exercise]:
exercises = []
for assessment in assessments:
exercises += [
Exercise("faker.words(4)", assessment, "today")
Exercise("faker.word()", 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_skills(quantity=1) -> list[Skill]:
return [Skill(faker.word(), faker.text()) for _ in range(quantity)]
def build_domains(quantity=1):
return [Domain(faker.words(6), faker.text()) for _ in range(quantity)]
def build_domains(quantity=1) -> list[Domain]:
return [Domain(faker.word(), faker.text()) for _ in range(quantity)]
def build_questions(
exercises: list[Exercise],
question_per_exercise=1,
):
) -> list[Question]:
skills = build_skills()
domains = build_domains()
@ -55,7 +67,7 @@ def build_questions(
for exercise in exercises:
questions += [
Question(
faker.words(2),
faker.word(),
exercise,
description="desc",
skill=choice(skills),
@ -69,6 +81,18 @@ def build_questions(
return questions
def build_student(
tribes: list[Tribe],
students_per_tribe=1,
) -> list[Student]:
students = []
for tribe in tribes:
students += [
Student(name=faker.name(), tribe=tribe) for _ in range(students_per_tribe)
]
return students
class FakeTribeRepository(AbstractRepository):
def __init__(self, tribes):
self._tribes = {t.name: t for t in tribes}