Skip to content

Commit 61879b8

Browse files
authored
fix: ensure we are selecting the correct date for self-paced courses (#36465)
It is possible for self-paced courses to be configured with a display behavior of "END" even though this configuration option should be invalid. The fix to this problem is beyond the scope of this PR. However, we can ensure we are selecting the correct display date for the certificate with a little bit of defensive coding. I've added a check to ensure that we only use the end date of the course when the course is instructor-paced and configured with a display behavior of "END".
1 parent 1c14c3a commit 61879b8

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

lms/djangoapps/certificates/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,14 @@ def display_date_for_certificate(course, certificate):
880880

881881
if _course_uses_available_date(course) and course.certificate_available_date < datetime.now(UTC):
882882
return course.certificate_available_date
883-
elif course.certificates_display_behavior == CertificatesDisplayBehaviors.END and course.end:
883+
# It is possible for a self-paced course run to end up configured with a display behavior of "END" even though it
884+
# shouldn't be a valid option. We must check if the course is instructor-paced here to ensure that we are selecting
885+
# the correct date to display.
886+
elif (
887+
not course.self_paced
888+
and course.certificates_display_behavior == CertificatesDisplayBehaviors.END
889+
and course.end
890+
):
884891
return course.end
885892
else:
886893
return certificate.modified_date

lms/djangoapps/certificates/tests/test_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ def test_display_date_for_certificate_cdb_early_no_info(self):
11411141
certificate instance when the display behavior is set to EARLY_NO_INFO.
11421142
"""
11431143
with configure_waffle_namespace(True):
1144+
self.course.self_paced = False
11441145
self.course.certificates_display_behavior = CertificatesDisplayBehaviors.EARLY_NO_INFO
11451146
assert display_date_for_certificate(self.course, self.certificate) == self.certificate.modified_date
11461147

@@ -1150,6 +1151,7 @@ def test_display_date_for_certificate_cdb_end_with_date(self):
11501151
associated with the course when the display behavior is set to END_WITH_DATE.
11511152
"""
11521153
with configure_waffle_namespace(True):
1154+
self.course.self_paced = False
11531155
self.course.certificates_display_behavior = CertificatesDisplayBehaviors.END_WITH_DATE
11541156
self.course.certificate_available_date = datetime(2017, 2, 1, tzinfo=pytz.UTC)
11551157
assert display_date_for_certificate(self.course, self.certificate) == self.course.certificate_available_date
@@ -1160,6 +1162,7 @@ def test_display_date_for_certificate_cdb_end(self):
11601162
when the display behavior is set to END.
11611163
"""
11621164
with configure_waffle_namespace(True):
1165+
self.course.self_paced = False
11631166
self.course.certificates_display_behavior = CertificatesDisplayBehaviors.END
11641167
assert display_date_for_certificate(self.course, self.certificate) == self.course.end
11651168

@@ -1172,6 +1175,27 @@ def test_display_date_for_certificate_date_override(self):
11721175
self.certificate.date_override = datetime(2016, 1, 1, tzinfo=pytz.UTC)
11731176
assert display_date_for_certificate(self.course, self.certificate) == self.certificate.date_override.date
11741177

1178+
def test_display_date_for_self_paced_course_run(self):
1179+
"""
1180+
Test to verify that the "earned date" displayed on a course certificate is the last modified date of a
1181+
certificate instance when the display behavior is set to EARLY_NO_INFO and the course run is self-paced.
1182+
"""
1183+
with configure_waffle_namespace(True):
1184+
self.course.self_paced = True
1185+
self.course.certificates_display_behavior = CertificatesDisplayBehaviors.EARLY_NO_INFO
1186+
assert display_date_for_certificate(self.course, self.certificate) == self.certificate.modified_date
1187+
1188+
def test_display_date_for_self_paced_course_run_with_cdb_end(self):
1189+
"""
1190+
Test for a bug fix and some defensive coding. It is possible for self-paced course runs to end up with a display
1191+
behavior of END. This test ensures that we select the correct issue date even when the course run's
1192+
configuration is unexpected.
1193+
"""
1194+
with configure_waffle_namespace(True):
1195+
self.course.self_paced = True
1196+
self.course.certificates_display_behavior = CertificatesDisplayBehaviors.END
1197+
assert display_date_for_certificate(self.course, self.certificate) == self.certificate.modified_date
1198+
11751199

11761200
@ddt.ddt
11771201
class CertificatesMessagingTestCase(ModuleStoreTestCase):

0 commit comments

Comments
 (0)