Feat: introduce faker for testing assessment aggregate
This commit is contained in:
parent
e496d86828
commit
a3c44321bf
44
poetry.lock
generated
44
poetry.lock
generated
@ -69,6 +69,21 @@ files = [
|
||||
[package.extras]
|
||||
test = ["pytest (>=6)"]
|
||||
|
||||
[[package]]
|
||||
name = "faker"
|
||||
version = "15.3.4"
|
||||
description = "Faker is a Python package that generates fake data for you."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "Faker-15.3.4-py3-none-any.whl", hash = "sha256:c2a2ff9dd8dfd991109b517ab98d5cb465e857acb45f6b643a0e284a9eb2cc76"},
|
||||
{file = "Faker-15.3.4.tar.gz", hash = "sha256:2d5443724f640ce07658ca8ca8bbd40d26b58914e63eec6549727869aa67e2cc"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
python-dateutil = ">=2.4"
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.8.2"
|
||||
@ -215,6 +230,21 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}
|
||||
[package.extras]
|
||||
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.8.2"
|
||||
description = "Extensions to the standard Python datetime module"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
|
||||
files = [
|
||||
{file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"},
|
||||
{file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
six = ">=1.5"
|
||||
|
||||
[[package]]
|
||||
name = "pyyaml"
|
||||
version = "6.0"
|
||||
@ -282,6 +312,18 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-g
|
||||
testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
|
||||
testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"]
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
version = "1.16.0"
|
||||
description = "Python 2 and 3 compatibility utilities"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||
files = [
|
||||
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
|
||||
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.10.2"
|
||||
@ -330,4 +372,4 @@ testing = ["coverage (>=6.2)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "46fc924a6d163979f35786e51305f62c91698182566f412c7852b9af31d0a9fc"
|
||||
content-hash = "33109fe55cbdbeafcb5d27085623cd708a9d0ca362dc2838615970db2f6fc1ab"
|
||||
|
@ -12,6 +12,7 @@ python = "^3.10"
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pre-commit = "^2.20.0"
|
||||
pytest = "^7.2.0"
|
||||
faker = "^15.3.4"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
@ -1,56 +1,102 @@
|
||||
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
|
||||
|
||||
|
||||
def build_tribe():
|
||||
return Tribe("plop", "2nd")
|
||||
faker = Faker()
|
||||
|
||||
|
||||
def build_tribe_assessment():
|
||||
tribe = build_tribe()
|
||||
assessment = Assessment("DS1", tribe, 1)
|
||||
return tribe, assessment
|
||||
def build_tribes(quantity=1):
|
||||
return [Tribe(name=faker.words(5), level=faker.words(5)) for _ in range(quantity)]
|
||||
|
||||
|
||||
def build_tribe_assessment_exercise():
|
||||
tribe, assessment = build_tribe_assessment()
|
||||
exercise = Exercise("ex1", assessment, "today")
|
||||
return tribe, assessment, exercise
|
||||
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_skills():
|
||||
return [Skill("search", "Searching and finding")]
|
||||
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_domains():
|
||||
return [Domain("function", "Functions are great")]
|
||||
def build_skills(quantity=1):
|
||||
return [Skill(faker.words(6), faker.text()) for _ in range(quantity)]
|
||||
|
||||
|
||||
def build_tribe_assessment_exercise_question():
|
||||
tribe, assessment, exercise = build_tribe_assessment_exercise()
|
||||
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()
|
||||
question = Question(
|
||||
"a",
|
||||
exercise,
|
||||
description="desc",
|
||||
skill=skills[0],
|
||||
domain=domains[0],
|
||||
is_leveled=True,
|
||||
scale=1,
|
||||
)
|
||||
return tribe, assessment, exercise, question
|
||||
|
||||
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():
|
||||
tribe, assessment, exercise = build_tribe_assessment_exercise()
|
||||
exercise_qty = randint(1, 10)
|
||||
tribes, assessments, exercises = build_tribe_assessment_exercise(
|
||||
exercise_per_assessment=exercise_qty
|
||||
)
|
||||
|
||||
assert len(assessment.exercises) == 1
|
||||
assert assessment.exercises[0] == exercise
|
||||
assert len(assessments[0].exercises) == exercise_qty
|
||||
assert assessments[0].exercises == exercises
|
||||
|
||||
|
||||
def test_exercise_register_question():
|
||||
tribe, assessment, exercise, question = build_tribe_assessment_exercise_question()
|
||||
question_qty = randint(1, 10)
|
||||
(
|
||||
tribes,
|
||||
assessments,
|
||||
exercises,
|
||||
questions,
|
||||
) = build_tribe_assessment_exercise_question(question_per_exercise=question_qty)
|
||||
|
||||
assert len(exercise.questions) == 1
|
||||
assert exercise.questions[0] == question
|
||||
assert len(exercises[0].questions) == question_qty
|
||||
assert exercises[0].questions == questions
|
||||
|
Loading…
Reference in New Issue
Block a user