Skip to content

Commit

Permalink
fix: register exams without due date or course end date (openedx#34421)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Mar 25, 2024
1 parent fc63719 commit f944e67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cms/djangoapps/contentstore/exams.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def register_exams(course_key):
timed_exam.is_onboarding_exam
)

due_date = timed_exam.due.isoformat() if timed_exam.due else (course.end.isoformat() if course.end else None)

exams_list.append({
'course_id': str(course_key),
'content_id': str(timed_exam.location),
Expand All @@ -83,7 +85,7 @@ def register_exams(course_key):
# exam service. Also note that we no longer consider the pacing type of the course - this applies to both
# self-paced and indstructor-paced courses. Therefore, this effectively opts out exams powered by edx-exams
# from personalized learner schedules/relative dates.
'due_date': timed_exam.due.isoformat() if timed_exam.due else course.end.isoformat(),
'due_date': due_date,
'exam_type': exam_type,
'is_active': True,
'hide_after_due': timed_exam.hide_after_due,
Expand Down
16 changes: 11 additions & 5 deletions cms/djangoapps/contentstore/tests/test_exams.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,21 @@ def test_feature_flag_off(self, mock_patch_course_exams):
listen_for_course_publish(self, self.course.id)
mock_patch_course_exams.assert_not_called()

@ddt.data(True, False)
def test_no_due_dates(self, is_self_paced, mock_patch_course_exams):
# MODIFY DUE DATE HERE
@ddt.data(
(True, datetime(2035, 1, 1, 0, 0, tzinfo=timezone.utc)),
(False, datetime(2035, 1, 1, 0, 0, tzinfo=timezone.utc)),
(True, None),
(False, None),
)
@ddt.unpack
def test_no_due_dates(self, is_self_paced, course_end_date, mock_patch_course_exams):
"""
Test that the coures end date is registered as the due date when the subsection does not have a due date for
both self-paced and instructor-paced exams.
"""
self.course.self_paced = is_self_paced
end_date = datetime(2035, 1, 1, 0, 0, tzinfo=timezone.utc)
self.course.end = end_date
self.course.end = course_end_date
self.course = self.update_course(self.course, 1)
BlockFactory.create(
parent=self.chapter,
Expand All @@ -173,7 +179,7 @@ def test_no_due_dates(self, is_self_paced, mock_patch_course_exams):

listen_for_course_publish(self, self.course.id)
called_exams, called_course = mock_patch_course_exams.call_args[0]
assert called_exams[0]['due_date'] == end_date.isoformat()
assert called_exams[0]['due_date'] == (course_end_date.isoformat() if course_end_date else None)

@ddt.data(True, False)
def test_subsection_due_date_prioritized(self, is_self_paced, mock_patch_course_exams):
Expand Down

0 comments on commit f944e67

Please sign in to comment.