vbv/server/vbv_lernwelt/dashboard/tests/graphql/utils.py

151 lines
4.3 KiB
Python

from datetime import datetime, timedelta
from typing import List, Tuple
from django.contrib.auth.hashers import make_password
from django.utils import timezone
from vbv_lernwelt.competence.factories import (
ActionCompetenceFactory,
ActionCompetenceListPageFactory,
CompetenceNaviPageFactory,
PerformanceCriteriaFactory,
)
from vbv_lernwelt.competence.models import PerformanceCriteria
from vbv_lernwelt.core.models import User
from vbv_lernwelt.course.factories import CoursePageFactory
from vbv_lernwelt.course.models import (
Course,
CourseCategory,
CoursePage,
CourseSession,
CourseSessionUser,
)
from vbv_lernwelt.course.utils import get_wagtail_default_site
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
from vbv_lernwelt.duedate.models import DueDate
from vbv_lernwelt.learnpath.models import Circle, LearningPath
from vbv_lernwelt.learnpath.tests.learning_path_factories import (
CircleFactory,
LearningContentAttendanceCourseFactory,
LearningPathFactory,
LearningUnitFactory,
TopicFactory,
)
def create_course(title: str) -> Tuple[Course, CoursePage]:
course = Course.objects.create(title=title, category_name="Handlungsfeld")
course_page = CoursePageFactory(
title="Test Lehrgang",
parent=get_wagtail_default_site().root_page,
course=course,
)
course.slug = course_page.slug
course.save()
return course, course_page
def create_user(username: str) -> User:
return User.objects.create_user(
username=username,
password=make_password("test"),
email=f"{username}@example.com",
language="de",
first_name="Test",
last_name=username.capitalize(),
)
def create_course_session(course: Course, title: str) -> CourseSession:
return CourseSession.objects.create(
course=course,
title=title,
import_id=title,
generation="2023",
start_date=timezone.now(),
)
def add_course_session_user(
course_session: CourseSession, user: User, role: CourseSessionUser.Role
) -> CourseSessionUser:
return CourseSessionUser.objects.create(
course_session=course_session,
user=user,
role=role,
)
def create_circle(
title: str, course_page: CoursePage, learning_path: LearningPath | None = None
) -> Tuple[Circle, LearningPath]:
if not learning_path:
learning_path = LearningPathFactory(title="Test Lernpfad", parent=course_page)
TopicFactory(title="Circle Test Topic", is_visible=False, parent=learning_path)
circle = CircleFactory(
title=title, parent=learning_path, description="Circle Description"
)
return circle, learning_path
def create_attendance_course(
course_session: CourseSession,
circle: Circle,
attendance_user_list: List,
due_date_end: datetime,
) -> CourseSessionAttendanceCourse:
learning_content_dummy = LearningContentAttendanceCourseFactory(
title="Lerninhalt Dummy",
parent=circle,
)
return CourseSessionAttendanceCourse.objects.create(
course_session=course_session,
learning_content=learning_content_dummy,
attendance_user_list=attendance_user_list,
due_date=DueDate.objects.create(
course_session=course_session,
start=due_date_end - timedelta(hours=8),
end=due_date_end,
),
)
def create_performance_criteria_page(
course: Course, course_page: CoursePage, circle: Circle
) -> PerformanceCriteria:
competence_navi_page = CompetenceNaviPageFactory(
title="Competence Navi",
parent=course_page,
)
competence_profile_page = ActionCompetenceListPageFactory(
title="Action Competence Page",
parent=competence_navi_page,
)
action_competence = ActionCompetenceFactory(
parent=competence_profile_page,
competence_id="X1",
title="Action Competence",
items=[("item", "Action Competence Item")],
)
cat, _ = CourseCategory.objects.get_or_create(
course=course, title="Course Category"
)
lu = LearningUnitFactory(title="Learning Unit", parent=circle, course_category=cat)
return PerformanceCriteriaFactory(
parent=action_competence,
competence_id="X1.1",
title="Performance Criteria",
learning_unit=lu,
)