diff --git a/openedx/features/learner_profile/tests/views/test_learner_profile.py b/openedx/features/learner_profile/tests/views/test_learner_profile.py index 185004beff..1583d9f833 100644 --- a/openedx/features/learner_profile/tests/views/test_learner_profile.py +++ b/openedx/features/learner_profile/tests/views/test_learner_profile.py @@ -201,3 +201,19 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase): self.assertContains(response, 'Explore New Courses') else: self.assertNotContains(response, 'Explore New Courses') + + def test_certificate_for_visibility_for_not_viewable_course(self): + """ + Verify that a certificate is not shown if certificate are not viewable to users. + """ + # add new course with certificate_available_date is future date. + course = CourseFactory.create( + certificate_available_date=datetime.datetime.now() + datetime.timedelta(days=5) + ) + + cert = self._create_certificate(course_key=course.id) + cert.save() + + response = self.client.get('/u/{username}'.format(username=self.user.username)) + + self.assertNotContains(response, 'card certificate-card mode-{cert_mode}'.format(cert_mode=cert.mode)) diff --git a/openedx/features/learner_profile/views/learner_achievements.py b/openedx/features/learner_profile/views/learner_achievements.py index 19c944ffc2..059d6a1fc6 100644 --- a/openedx/features/learner_profile/views/learner_achievements.py +++ b/openedx/features/learner_profile/views/learner_achievements.py @@ -4,6 +4,7 @@ Views to render a learner's achievements. from django.template.loader import render_to_string from lms.djangoapps.certificates import api as certificate_api +from openedx.core.djangoapps.certificates.api import certificates_viewable_for_course from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from web_fragments.fragment import Fragment @@ -41,7 +42,8 @@ class LearnerAchievementsFragmentView(EdxFragmentView): try: course_overview = CourseOverview.get_from_id(course_key) course_certificate['course'] = course_overview - passing_certificates.append(course_certificate) + if certificates_viewable_for_course(course_overview): + passing_certificates.append(course_certificate) except CourseOverview.DoesNotExist: # This is unlikely to fail as the course should exist. # Ideally the cert should have all the information that