Commit 9009a5b0 by Alex Dusenbery Committed by Alex Dusenbery

may_certify_for_course checks if course is self_paced.

parent 010d251d
...@@ -97,11 +97,12 @@ def may_certify_for_course( ...@@ -97,11 +97,12 @@ def may_certify_for_course(
certificates_display_behavior, certificates_display_behavior,
certificates_show_before_end, certificates_show_before_end,
has_ended, has_ended,
certificate_available_date certificate_available_date,
self_paced
): ):
""" """
Returns whether it is acceptable to show the student a certificate download Returns whether it is acceptable to show the student a certificate download
link for a course. link for a course, based on provided attributes of the course.
Arguments: Arguments:
certificates_display_behavior (str): string describing the course's certificates_display_behavior (str): string describing the course's
...@@ -111,23 +112,19 @@ def may_certify_for_course( ...@@ -111,23 +112,19 @@ def may_certify_for_course(
course's certificates before the course has ended. course's certificates before the course has ended.
has_ended (bool): Whether the course has ended. has_ended (bool): Whether the course has ended.
certificate_available_date (datetime): the date the certificate is available on for the course. certificate_available_date (datetime): the date the certificate is available on for the course.
self_paced (bool): Whether the course is self-paced.
""" """
show_early = ( show_early = (
certificates_display_behavior in ('early_with_info', 'early_no_info') certificates_display_behavior in ('early_with_info', 'early_no_info')
or certificates_show_before_end or certificates_show_before_end
) )
past_availability_date = ( past_available_date = (
certificate_available_date certificate_available_date
and certificate_available_date < datetime.now(utc) and certificate_available_date < datetime.now(utc)
) )
ended_without_available_date = (certificate_available_date is None) and has_ended
if show_early: return any((self_paced, show_early, past_available_date, ended_without_available_date))
return True
if past_availability_date:
return True
if (certificate_available_date is None) and has_ended:
return True
return False
def sorting_score(start, advertised_start, announcement): def sorting_score(start, advertised_start, announcement):
......
...@@ -1067,7 +1067,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor, LicenseMixin): ...@@ -1067,7 +1067,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor, LicenseMixin):
self.certificates_display_behavior, self.certificates_display_behavior,
self.certificates_show_before_end, self.certificates_show_before_end,
self.has_ended(), self.has_ended(),
self.certificate_available_date self.certificate_available_date,
self.self_paced
) )
def has_started(self): def has_started(self):
......
...@@ -161,14 +161,16 @@ class CourseMetadataUtilsTestCase(TestCase): ...@@ -161,14 +161,16 @@ class CourseMetadataUtilsTestCase(TestCase):
TestScenario((DEFAULT_START_DATE, None), True), TestScenario((DEFAULT_START_DATE, None), True),
]), ]),
FunctionTest(may_certify_for_course, [ FunctionTest(may_certify_for_course, [
TestScenario(('early_with_info', True, True, test_datetime), True), TestScenario(('early_with_info', True, True, test_datetime, False), True),
TestScenario(('early_no_info', False, False, test_datetime), True), TestScenario(('early_no_info', False, False, test_datetime, False), True),
TestScenario(('end', True, False, test_datetime), True), TestScenario(('end', True, False, test_datetime, False), True),
TestScenario(('end', False, True, test_datetime), True), TestScenario(('end', False, True, test_datetime, False), True),
TestScenario(('end', False, False, _NEXT_WEEK), False), TestScenario(('end', False, False, _NEXT_WEEK, False), False),
TestScenario(('end', False, False, _LAST_WEEK), True), TestScenario(('end', False, False, _LAST_WEEK, False), True),
TestScenario(('end', False, False, None), False), TestScenario(('end', False, False, None, False), False),
TestScenario(('early_with_info', False, False, None), True), TestScenario(('early_with_info', False, False, None, False), True),
TestScenario(('end', False, False, _NEXT_WEEK, False), False),
TestScenario(('end', False, False, _NEXT_WEEK, True), True),
]), ]),
] ]
......
...@@ -930,12 +930,8 @@ def _get_cert_data(student, course, course_key, is_active, enrollment_mode): ...@@ -930,12 +930,8 @@ def _get_cert_data(student, course, course_key, is_active, enrollment_mode):
) )
may_view_certificate = False may_view_certificate = False
# https://openedx.atlassian.net/browse/EDUCATOR-1204: historically,
# certificates for self-paced courses are displayed no matter the
# state of advanced course settings regarding certificates.
if course_key: if course_key:
course = get_course_by_id(course_key) may_view_certificate = get_course_by_id(course_key).may_certify()
may_view_certificate = course.self_paced or course.may_certify()
show_message = all([ show_message = all([
is_active, is_active,
......
...@@ -479,7 +479,8 @@ class CourseOverview(TimeStampedModel): ...@@ -479,7 +479,8 @@ class CourseOverview(TimeStampedModel):
self.certificates_display_behavior, self.certificates_display_behavior,
self.certificates_show_before_end, self.certificates_show_before_end,
self.has_ended(), self.has_ended(),
self.certificate_available_date self.certificate_available_date,
self.self_paced
) )
@property @property
......
...@@ -732,6 +732,20 @@ class TestProgramDataExtender(ModuleStoreTestCase): ...@@ -732,6 +732,20 @@ class TestProgramDataExtender(ModuleStoreTestCase):
self._assert_supplemented(data, certificate_url=expected_url) self._assert_supplemented(data, certificate_url=expected_url)
@ddt.data(True, False)
def test_may_certify_attached(self, may_certify):
"""
Verify that the `may_certify` is included during data extension.
"""
self.course.certificates_show_before_end = may_certify
self.course = self.update_course(self.course, self.user.id)
data = ProgramDataExtender(self.program, self.user).extend()
self.assertEqual(may_certify, data['courses'][0]['course_runs'][0]['may_certify'])
self._assert_supplemented(data)
@skip_unless_lms @skip_unless_lms
@mock.patch(UTILS_MODULE + '.get_credentials') @mock.patch(UTILS_MODULE + '.get_credentials')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment