Don't include staff-only sections in due date calculations for self-paced courses
This commit is contained in:
42
openedx/core/djangoapps/course_date_signals/tests.py
Normal file
42
openedx/core/djangoapps/course_date_signals/tests.py
Normal file
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user