fix: Stop showing course certificate buttons to beta testers (#28416)

Beta testers can’t earn course certificates, so they should not see a “Request Certificate” button or other info describing how they can earn a cert.

MICROBA-992
This commit is contained in:
Christie Rice
2021-08-10 09:06:14 -04:00
committed by GitHub
parent f2bb92bc64
commit cf3a6c16d6
9 changed files with 127 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ from django.conf import settings
from lms.djangoapps.certificates import api as certs_api
from lms.djangoapps.certificates.data import CertificateStatuses
from lms.djangoapps.instructor import access
from openedx.core.djangoapps.certificates.config import waffle
from common.djangoapps.student.models import CourseEnrollment
from xmodule.data import CertificatesDisplayBehaviors
@@ -34,16 +35,18 @@ def can_show_certificate_message(course, student, course_grade, certificates_ena
"""
Returns True if a course certificate message can be shown
"""
is_allowlisted = certs_api.is_on_allowlist(student, course.id)
auto_cert_gen_enabled = auto_certificate_generation_enabled()
has_active_enrollment = CourseEnrollment.is_enrolled(student, course.id)
certificates_are_viewable = certs_api.certificates_viewable_for_course(course)
is_beta_tester = access.is_beta_tester(student, course.id)
has_passed_or_is_allowlisted = _has_passed_or_is_allowlisted(course, student, course_grade)
return (
(auto_cert_gen_enabled or certificates_enabled_for_course) and
has_active_enrollment and
certificates_are_viewable and
(course_grade.passed or is_allowlisted)
has_passed_or_is_allowlisted and
(not is_beta_tester)
)
@@ -95,3 +98,13 @@ def display_date_for_certificate(course, certificate):
def is_valid_pdf_certificate(cert_data):
return cert_data.cert_status == CertificateStatuses.downloadable and cert_data.download_url
def _has_passed_or_is_allowlisted(course, student, course_grade):
"""
Returns True if the student has passed this course run, or is on the allowlist for this course run
"""
is_allowlisted = certs_api.is_on_allowlist(student, course.id)
has_passed = course_grade and course_grade.passed
return has_passed or is_allowlisted

View File

@@ -7,14 +7,22 @@ from datetime import datetime
import ddt
import pytz
from django.test import TestCase
from unittest.mock import patch
from edx_toggles.toggles import LegacyWaffleSwitch
from edx_toggles.toggles.testutils import override_waffle_switch
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from openedx.core.djangoapps.certificates import api
from openedx.core.djangoapps.certificates.config import waffle as certs_waffle
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from xmodule.data import CertificatesDisplayBehaviors
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
BETA_TESTER_METHOD = 'openedx.core.djangoapps.certificates.api.access.is_beta_tester'
CERTS_VIEWABLE_METHOD = 'openedx.core.djangoapps.certificates.api.certs_api.certificates_viewable_for_course'
PASSED_OR_ALLOWLISTED_METHOD = 'openedx.core.djangoapps.certificates.api._has_passed_or_is_allowlisted'
# TODO: Copied from lms.djangoapps.certificates.models,
@@ -147,3 +155,33 @@ class CertificatesApiTestCase(TestCase):
maybe_avail = self.course.certificate_available_date if uses_avail_date else self.certificate.modified_date
assert maybe_avail == api.available_date_for_certificate(self.course, self.certificate)
assert self.certificate.modified_date == api.display_date_for_certificate(self.course, self.certificate)
@ddt.ddt
class CertificatesMessagingTestCase(ModuleStoreTestCase):
"""
API tests for certificate messaging
"""
def setUp(self):
super().setUp()
self.course = CourseOverviewFactory.create()
self.course_run_key = self.course.id
self.user = UserFactory.create()
self.enrollment = CourseEnrollmentFactory(
user=self.user,
course_id=self.course_run_key,
is_active=True,
mode=CourseMode.VERIFIED,
)
def test_beta_tester(self):
grade = None
certs_enabled = True
with patch(PASSED_OR_ALLOWLISTED_METHOD, return_value=True):
with patch(CERTS_VIEWABLE_METHOD, return_value=True):
with patch(BETA_TESTER_METHOD, return_value=False):
assert api.can_show_certificate_message(self.course, self.user, grade, certs_enabled)
with patch(BETA_TESTER_METHOD, return_value=True):
assert not api.can_show_certificate_message(self.course, self.user, grade, certs_enabled)