示例#1
0
def course_section_post_save_receiver(sender, instance: CourseSection, created,
                                      *args, **kwargs):
    if created:
        CourseToolkit.create_course_section_duration_time(
            course_section=instance)
        CourseToolkit.recalculate_course_content_tree_by_section(
            instance=instance)
示例#2
0
def test_recalculating_course_duration_time_tree_by_lecture(
        duration_times, course):
    c_duration_time = course.content.duration_time
    sections = course.content.sections.all()

    for section, i in zip(sections, range(1, sections.count() + 1)):
        for lecture, j in zip(section.lectures.all(),
                              range(1,
                                    section.lectures.count() + 1)):
            lecture.duration_time.hours = duration_times[f"section{i}"][
                f"lecture{j}"]["hours"]
            lecture.duration_time.minutes = duration_times[f"section{i}"][
                f"lecture{j}"]["minutes"]
            lecture.duration_time.seconds = duration_times[f"section{i}"][
                f"lecture{j}"]["seconds"]
            lecture.duration_time.save()

    reset_main_duration_times(course)

    for section in sections:
        for lecture in section.lectures.all():
            CourseToolkit.recalculate_course_duration_time_tree_by_lecture(
                instance=lecture)

    c_duration_time.refresh_from_db()
    assert c_duration_time.hours == duration_times["hours"]
    assert c_duration_time.minutes == duration_times["minutes"]

    for section, i in zip(sections, range(1, sections.count())):
        section.duration_time.refresh_from_db()
        assert section.duration_time.hours == duration_times[f"section{i}"][
            "hours"]
        assert section.duration_time.minutes == duration_times[f"section{i}"][
            "minutes"]
def test_recalculation_course_content_tree_by_section_call_method(
        mocker, course):
    recalculate_sections = mocker.patch(
        "courses.models.CourseContent.recalculate_sections")
    section = course.content.sections.first()

    CourseToolkit.recalculate_course_content_tree_by_section(instance=section)

    recalculate_sections.assert_called_once()
def test_recalculate_course_content_tree_by_lecture(course):
    lecture1 = course.content.sections.first().lectures.first()
    lecture2 = course.content.sections.last().lectures.first()

    CourseToolkit.recalculate_course_content_tree_by_lecture(instance=lecture1)
    CourseToolkit.recalculate_course_content_tree_by_lecture(instance=lecture2)

    for section in course.content.sections.all():
        assert section.lectures_count == 2

    assert course.content.lectures_count == 4
def test_recalculate_course_content_tree_by_lecture_call_method(
        mocker, course):
    recalculate_section = mocker.patch(
        "courses.models.CourseSection.recalculate_lectures")
    recalculate_content = mocker.patch(
        "courses.models.CourseContent.recalculate_lectures")

    lecture = course.content.sections.first().lectures.first()

    CourseToolkit.recalculate_course_content_tree_by_lecture(instance=lecture)

    recalculate_section.assert_called_once()
    recalculate_content.assert_called_once()
示例#6
0
def course_lecture_duration_time_post_save_and_delete_receiver(
        sender, instance: CourseLectureDurationTime, *args, **kwargs):
    course_lecture = instance.course_lecture
    CourseToolkit.recalculate_course_duration_time_tree_by_lecture(
        course_lecture)
示例#7
0
def course_lecture_post_delete_receiver(sender, instance: CourseLecture, *args,
                                        **kwargs):
    CourseToolkit.recalculate_course_content_tree_by_lecture(instance)
示例#8
0
def course_lecture_post_save_receiver(sender, instance: CourseLecture, created,
                                      *args, **kwargs):
    if created:
        CourseToolkit.create_course_lecture_duration_time(
            course_lecture=instance)
        CourseToolkit.recalculate_course_content_tree_by_lecture(instance)
示例#9
0
def course_section_post_delete_receiver(sender, instance: CourseSection, *args,
                                        **kwargs):
    CourseToolkit.recalculate_course_content_tree_by_section(instance=instance)
示例#10
0
def course_content_post_save_receiver(sender, instance: CourseContent, created,
                                      *args, **kwargs):
    if created:
        CourseToolkit.create_course_duration_time(course_content=instance)
示例#11
0
def course_post_save_receiver(sender, instance: Course, created, *args,
                              **kwargs):
    if created:
        CourseToolkit.create_course_content(course=instance)
def test_recalculation_course_content_tree_by_section(course):
    section = course.content.sections.first()

    CourseToolkit.recalculate_course_content_tree_by_section(instance=section)

    assert course.content.sections_count == 2