From 0bf9a0e0cebbe5e6b14d6deedb7d319082c18ba1 Mon Sep 17 00:00:00 2001 From: Chris Deery <3932645+cdeery@users.noreply.github.com> Date: Tue, 23 Nov 2021 14:33:50 -0500 Subject: [PATCH] fix: [AA-1106] completed status for unreleased (#29408) Modify get_course_assignments so it does not mark unreleased content as completed Add unit test --- lms/djangoapps/courseware/courses.py | 4 +++- .../courseware/tests/test_courses.py | 22 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index c46c446fcd..145a4b3186 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -570,8 +570,10 @@ def get_course_assignments(course_key, user, include_access=False): # lint-amne assignment_released = not start or start < now if assignment_released: url = reverse('jump_to', args=[course_key, subsection_key]) + complete = is_block_structure_complete_for_assignments(block_data, subsection_key) + else: + complete = False - complete = is_block_structure_complete_for_assignments(block_data, subsection_key) past_due = not complete and due < now assignments.append(_Assignment( subsection_key, title, url, due, contains_gated_content, diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py index 199487db44..1d6590e1da 100644 --- a/lms/djangoapps/courseware/tests/test_courses.py +++ b/lms/djangoapps/courseware/tests/test_courses.py @@ -432,7 +432,8 @@ class TestGetCourseAssignments(CompletionWaffleTestMixin, ModuleStoreTestCase): Test that we treat a sequential with incomplete (but not scored) items (like a video maybe) as complete. """ course = CourseFactory() - chapter = ItemFactory(parent=course, category='chapter', graded=True, due=datetime.datetime.now()) + chapter = ItemFactory(parent=course, category='chapter', graded=True, due=datetime.datetime.now(), + start=datetime.datetime.now() - datetime.timedelta(hours=1)) sequential = ItemFactory(parent=chapter, category='sequential') problem = ItemFactory(parent=sequential, category='problem', has_score=True) ItemFactory(parent=sequential, category='video', has_score=False) @@ -457,3 +458,22 @@ class TestGetCourseAssignments(CompletionWaffleTestMixin, ModuleStoreTestCase): assignments = get_course_assignments(course.location.context_key, self.user, None) assert len(assignments) == 1 assert not assignments[0].complete + + def test_completion_does_not_treat_unreleased_as_complete(self): + """ + Test that unreleased assignments are not treated as complete. + """ + course = CourseFactory() + chapter = ItemFactory(parent=course, category='chapter', graded=True, + due=datetime.datetime.now() + datetime.timedelta(hours=2), + start=datetime.datetime.now() + datetime.timedelta(hours=1)) + sequential = ItemFactory(parent=chapter, category='sequential') + problem = ItemFactory(parent=sequential, category='problem', has_score=True) + ItemFactory(parent=sequential, category='video', has_score=False) + + self.override_waffle_switch(True) + BlockCompletion.objects.submit_completion(self.user, problem.location, 1) + + assignments = get_course_assignments(course.location.context_key, self.user, None) + assert len(assignments) == 1 + assert not assignments[0].complete