Exemplo n.º 1
0
def listen_for_passing_grade(sender, user, course_id, **kwargs):  # pylint: disable=unused-argument
    """
    Listen for a signal indicating that the user has passed a course run.

    If needed, generate a certificate task.
    """
    if not auto_certificate_generation_enabled():
        return

    if can_generate_certificate_task(user, course_id):
        cert = GeneratedCertificate.certificate_for_student(user, course_id)
        if cert is not None and CertificateStatuses.is_passing_status(
                cert.status):
            log.info(
                f'{course_id} is using V2 certificates, and the cert status is already passing for user '
                f'{user.id}. Passing grade signal will be ignored.')
            return
        log.info(
            f'{course_id} is using V2 certificates. Attempt will be made to generate a V2 certificate for '
            f'{user.id} as a passing grade was received.')
        return generate_certificate_task(user, course_id)

    if _fire_ungenerated_certificate_task(user, course_id):
        log.info(
            'Certificate generation task initiated for {user} : {course} via passing grade'
            .format(user=user.id, course=course_id))
 def test_handle_valid(self):
     """
     Test handling of a valid user/course run combo.
     """
     assert _can_generate_v2_certificate(self.user, self.course_run_key)
     assert can_generate_certificate_task(self.user, self.course_run_key)
     assert generate_certificate_task(self.user, self.course_run_key)
Exemplo n.º 3
0
def _listen_for_id_verification_status_changed(sender, user, **kwargs):  # pylint: disable=unused-argument
    """
    Listen for a signal indicating that the user's id verification status has changed.

    If needed, generate a certificate task.
    """
    if not auto_certificate_generation_enabled():
        return

    user_enrollments = CourseEnrollment.enrollments_for_user(user=user)

    grade_factory = CourseGradeFactory()
    expected_verification_status = IDVerificationService.user_status(user)
    expected_verification_status = expected_verification_status['status']
    for enrollment in user_enrollments:
        if can_generate_certificate_task(user, enrollment.course_id):
            log.info(
                f'{enrollment.course_id} is using V2 certificates. Attempt will be made to generate a V2 '
                f'certificate for {user.id}. Id verification status is {expected_verification_status}'
            )
            generate_certificate_task(user, enrollment.course_id)
        elif grade_factory.read(user=user,
                                course=enrollment.course_overview).passed:
            if _fire_ungenerated_certificate_task(
                    user, enrollment.course_id, expected_verification_status):
                message = (
                    'Certificate generation task initiated for {user} : {course} via track change '
                    + 'with verification status of {status}')
                log.info(
                    message.format(user=user.id,
                                   course=enrollment.course_id,
                                   status=expected_verification_status))
Exemplo n.º 4
0
 def test_handle_invalid(self):
     """
     Test handling of an invalid user/course run combo
     """
     assert not _can_generate_v2_certificate(self.user, self.course_run_key)
     assert not can_generate_certificate_task(self.user, self.course_run_key)
     assert not generate_certificate_task(self.user, self.course_run_key)
     assert not generate_regular_certificate_task(self.user, self.course_run_key)
Exemplo n.º 5
0
    def test_handle_valid(self):
        """
        Test handling of a valid user/course run combo.

        Note: these assertions are placeholders for now. They will be updated as the implementation is added.
        """
        assert not _can_generate_v2_certificate(self.user, self.course_run_key)
        assert can_generate_certificate_task(self.user, self.course_run_key)
        assert not generate_certificate_task(self.user, self.course_run_key)
        assert not generate_regular_certificate_task(self.user, self.course_run_key)
Exemplo n.º 6
0
    def test_handle_invalid(self):
        """
        Test handling of an invalid user/course run combo
        """
        u = UserFactory()

        assert not _can_generate_allowlist_certificate(u, self.course_run_key)
        assert not generate_allowlist_certificate_task(u, self.course_run_key)
        assert not can_generate_certificate_task(u, self.course_run_key)
        assert not generate_certificate_task(u, self.course_run_key)
        assert _set_allowlist_cert_status(u, self.course_run_key) is None
Exemplo n.º 7
0
def _listen_for_enrollment_mode_change(sender, user, course_key, mode, **kwargs):  # pylint: disable=unused-argument
    """
    Listen for the signal indicating that a user's enrollment mode has changed.

    If possible, grant the user a course certificate. Note that we intentionally do not revoke certificates here, even
    if the user has moved to the audit track.
    """
    if modes_api.is_eligible_for_certificate(mode):
        if can_generate_certificate_task(user, course_key):
            log.info(f'{course_key} is using V2 certificates. Attempt will be made to generate a V2 certificate for '
                     f'{user.id} since the enrollment mode is now {mode}.')
            generate_certificate_task(user, course_key)
Exemplo n.º 8
0
def listen_for_passing_grade(sender, user, course_id, **kwargs):  # pylint: disable=unused-argument
    """
    Listen for a learner passing a course, send cert generation task,
    downstream signal from COURSE_GRADE_CHANGED
    """
    if not auto_certificate_generation_enabled():
        return

    if can_generate_certificate_task(user, course_id):
        log.info(f'{course_id} is using V2 certificates. Attempt will be made to generate a V2 certificate for '
                 f'{user.id} as a passing grade was received.')
        return generate_certificate_task(user, course_id)

    if _fire_ungenerated_certificate_task(user, course_id):
        log.info('Certificate generation task initiated for {user} : {course} via passing grade'.format(
            user=user.id,
            course=course_id
        ))
Exemplo n.º 9
0
 def test_handle_valid_general_methods(self):
     """
     Test handling of a valid user/course run combo for the general (non-allowlist) generation methods
     """
     assert can_generate_certificate_task(self.user, self.course_run_key)
     assert generate_certificate_task(self.user, self.course_run_key)