From 9009a5b0d33b4347f8129435988e7aeea1d67d20 Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Fri, 25 Aug 2017 11:53:13 -0400 Subject: [PATCH] may_certify_for_course checks if course is self_paced. --- .../xmodule/xmodule/course_metadata_utils.py | 17 +++++++---------- common/lib/xmodule/xmodule/course_module.py | 3 ++- .../tests/test_course_metadata_utils.py | 18 ++++++++++-------- lms/djangoapps/courseware/views/views.py | 6 +----- .../content/course_overviews/models.py | 3 ++- .../djangoapps/programs/tests/test_utils.py | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/common/lib/xmodule/xmodule/course_metadata_utils.py b/common/lib/xmodule/xmodule/course_metadata_utils.py index 9dfc499a4b..fee7a2d058 100644 --- a/common/lib/xmodule/xmodule/course_metadata_utils.py +++ b/common/lib/xmodule/xmodule/course_metadata_utils.py @@ -97,11 +97,12 @@ def may_certify_for_course( certificates_display_behavior, certificates_show_before_end, has_ended, - certificate_available_date + certificate_available_date, + self_paced ): """ 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: certificates_display_behavior (str): string describing the course's @@ -111,23 +112,19 @@ def may_certify_for_course( course's certificates before 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. + self_paced (bool): Whether the course is self-paced. """ show_early = ( certificates_display_behavior in ('early_with_info', 'early_no_info') or certificates_show_before_end ) - past_availability_date = ( + past_available_date = ( certificate_available_date and certificate_available_date < datetime.now(utc) ) + ended_without_available_date = (certificate_available_date is None) and has_ended - if show_early: - return True - if past_availability_date: - return True - if (certificate_available_date is None) and has_ended: - return True - return False + return any((self_paced, show_early, past_available_date, ended_without_available_date)) def sorting_score(start, advertised_start, announcement): diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index c70e380e21..0a02ad1f05 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -1067,7 +1067,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor, LicenseMixin): self.certificates_display_behavior, self.certificates_show_before_end, self.has_ended(), - self.certificate_available_date + self.certificate_available_date, + self.self_paced ) def has_started(self): diff --git a/common/lib/xmodule/xmodule/tests/test_course_metadata_utils.py b/common/lib/xmodule/xmodule/tests/test_course_metadata_utils.py index 9a3b8fd8c1..0cda86a606 100644 --- a/common/lib/xmodule/xmodule/tests/test_course_metadata_utils.py +++ b/common/lib/xmodule/xmodule/tests/test_course_metadata_utils.py @@ -161,14 +161,16 @@ class CourseMetadataUtilsTestCase(TestCase): TestScenario((DEFAULT_START_DATE, None), True), ]), FunctionTest(may_certify_for_course, [ - TestScenario(('early_with_info', True, True, test_datetime), True), - TestScenario(('early_no_info', False, False, test_datetime), True), - TestScenario(('end', True, False, test_datetime), True), - TestScenario(('end', False, True, test_datetime), True), - TestScenario(('end', False, False, _NEXT_WEEK), False), - TestScenario(('end', False, False, _LAST_WEEK), True), - TestScenario(('end', False, False, None), False), - TestScenario(('early_with_info', False, False, None), True), + TestScenario(('early_with_info', True, True, test_datetime, False), True), + TestScenario(('early_no_info', False, False, test_datetime, False), True), + TestScenario(('end', True, False, test_datetime, False), True), + TestScenario(('end', False, True, test_datetime, False), True), + TestScenario(('end', False, False, _NEXT_WEEK, False), False), + TestScenario(('end', False, False, _LAST_WEEK, False), True), + TestScenario(('end', False, False, None, False), False), + 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), ]), ] diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 545c325caa..94611ab323 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -930,12 +930,8 @@ def _get_cert_data(student, course, course_key, is_active, enrollment_mode): ) 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: - course = get_course_by_id(course_key) - may_view_certificate = course.self_paced or course.may_certify() + may_view_certificate = get_course_by_id(course_key).may_certify() show_message = all([ is_active, diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index e1283863a4..0284dea763 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -479,7 +479,8 @@ class CourseOverview(TimeStampedModel): self.certificates_display_behavior, self.certificates_show_before_end, self.has_ended(), - self.certificate_available_date + self.certificate_available_date, + self.self_paced ) @property diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index b49e9a8834..7c9411893b 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -732,6 +732,20 @@ class TestProgramDataExtender(ModuleStoreTestCase): 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 @mock.patch(UTILS_MODULE + '.get_credentials')