From aaa8ffdcf1281511b1b42405dd3a17cfebbb9d8d Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 14 May 2020 14:09:20 -0400 Subject: [PATCH] Don't include staff-only sections in due date calculations for self-paced courses --- .../djangoapps/course_date_signals/tests.py | 42 +++++++++++++++++++ .../djangoapps/course_date_signals/utils.py | 7 +++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 openedx/core/djangoapps/course_date_signals/tests.py diff --git a/openedx/core/djangoapps/course_date_signals/tests.py b/openedx/core/djangoapps/course_date_signals/tests.py new file mode 100644 index 0000000000..5001d11bd2 --- /dev/null +++ b/openedx/core/djangoapps/course_date_signals/tests.py @@ -0,0 +1,42 @@ +from datetime import timedelta +import ddt +from unittest.mock import patch + +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from . import utils + + +@ddt.ddt +class SelfPacedDueDatesTests(ModuleStoreTestCase): + def setUp(self): + super().setUp() + self.course = CourseFactory.create() + for i in range(4): + ItemFactory(parent=self.course, category="sequential", display_name="Section {}".format(i)) + + def test_basic_spacing(self): + expected_sections = [ + (0, 'Section 0', timedelta(days=7)), + (1, 'Section 1', timedelta(days=14)), + (2, 'Section 2', timedelta(days=21)), + (3, 'Section 3', timedelta(days=28)), + ] + with patch.object(utils, 'get_expected_duration', return_value=timedelta(weeks=4)): + actual = [(idx, section.display_name, offset) for (idx, section, offset) in utils.spaced_out_sections(self.course)] + + self.assertEqual(actual, expected_sections) + + def test_hidden_sections(self): + for _ in range(2): + ItemFactory(parent=self.course, category="sequential", visible_to_staff_only=True) + expected_sections = [ + (0, 'Section 0', timedelta(days=7)), + (1, 'Section 1', timedelta(days=14)), + (2, 'Section 2', timedelta(days=21)), + (3, 'Section 3', timedelta(days=28)), + ] + with patch.object(utils, 'get_expected_duration', return_value=timedelta(weeks=4)): + actual = [(idx, section.display_name, offset) for (idx, section, offset) in utils.spaced_out_sections(self.course)] + + self.assertEqual(actual, expected_sections) diff --git a/openedx/core/djangoapps/course_date_signals/utils.py b/openedx/core/djangoapps/course_date_signals/utils.py index 4ff133f21e..823e590f92 100644 --- a/openedx/core/djangoapps/course_date_signals/utils.py +++ b/openedx/core/djangoapps/course_date_signals/utils.py @@ -43,7 +43,12 @@ def spaced_out_sections(course): relative time (timedelta): the amount of weeks to complete the section, since start of course """ duration = get_expected_duration(course) - sections = course.get_children() + sections = [ + section + for section + in course.get_children() + if not section.visible_to_staff_only + ] weeks_per_section = duration / len(sections) for idx, section in enumerate(sections): yield idx, section, weeks_per_section * (idx + 1)