def test_can_generate_auto_disabled(self):
     """
     Test handling when automatic generation is disabled
     """
     with override_waffle_switch(AUTO_GENERATION_SWITCH, active=False):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
    def test_can_generate_invalidated(self):
        """
        Test handling when user is on the invalidate list
        """
        u = UserFactory()
        cr = CourseFactory()
        key = cr.id  # pylint: disable=no-member
        CourseEnrollmentFactory(
            user=u,
            course_id=key,
            is_active=True,
            mode="verified",
        )
        cert = GeneratedCertificateFactory(
            user=u,
            course_id=key,
            mode=GeneratedCertificate.MODES.verified,
            status=CertificateStatuses.downloadable
        )
        CertificateInvalidationFactory.create(
            generated_certificate=cert,
            invalidated_by=self.user,
            active=True
        )

        assert not _can_generate_v2_certificate(u, key)
        assert _set_v2_cert_status(u, key) == CertificateStatuses.unavailable
 def test_can_generate_not_verified(self):
     """
     Test handling when the user's id is not verified
     """
     with mock.patch(ID_VERIFIED_METHOD, return_value=False):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
 def test_can_generate_ccx(self):
     """
     Test handling when the course is a CCX (custom edX) course
     """
     with mock.patch(CCX_COURSE_METHOD, return_value=True):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
 def test_can_generate_beta_tester(self):
     """
     Test handling when the user is a beta tester
     """
     with mock.patch(BETA_TESTER_METHOD, return_value=True):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
    def test_handle_not_passing_id_verified_cert(self):
        """
        Test handling of a user who is not passing and is id verified and has a cert
        """
        different_user = UserFactory()
        CourseEnrollmentFactory(
            user=different_user,
            course_id=self.course_run_key,
            is_active=True,
            mode=GeneratedCertificate.MODES.verified,
        )
        GeneratedCertificateFactory(
            user=different_user,
            course_id=self.course_run_key,
            mode=GeneratedCertificate.MODES.verified,
            status=CertificateStatuses.generating,
        )

        with mock.patch(PASSING_GRADE_METHOD, return_value=False):
            assert _set_v2_cert_status(
                different_user,
                self.course_run_key) == CertificateStatuses.notpassing
            assert generate_regular_certificate_task(
                different_user, self.course_run_key) is True
            assert not _can_generate_v2_certificate(different_user,
                                                    self.course_run_key)
 def test_can_generate_failing_grade(self):
     """
     Test handling when the user does not have a passing grade
     """
     with mock.patch(PASSING_GRADE_METHOD, return_value=False):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
 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)
 def test_can_generate_web_cert_disabled(self):
     """
     Test handling when web certs are not enabled
     """
     with mock.patch(WEB_CERTS_METHOD, return_value=False):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
 def test_can_generate_no_overview(self):
     """
     Test handling when the course overview is missing
     """
     with mock.patch(COURSE_OVERVIEW_METHOD, return_value=None):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
         assert _set_v2_cert_status(self.user, self.course_run_key) is None
 def test_can_generate_not_passing_no_cert(self):
     """
     Test handling when the user does not have a passing grade and no cert exists
     """
     with mock.patch(PASSING_GRADE_METHOD, return_value=False):
         assert not _can_generate_v2_certificate(self.user,
                                                 self.course_run_key)
         assert _set_v2_cert_status(self.user, self.course_run_key) is None
 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)
 def test_can_generate_not_enrolled(self):
     """
     Test handling when user is not enrolled
     """
     u = UserFactory()
     cr = CourseFactory()
     key = cr.id  # pylint: disable=no-member
     assert not _can_generate_v2_certificate(u, key)
Example #14
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)
 def test_handle_invalid(self):
     """
     Test handling of an invalid user/course run combo
     """
     other_user = UserFactory()
     assert not _can_generate_v2_certificate(other_user,
                                             self.course_run_key)
     assert not generate_certificate_task(other_user, self.course_run_key)
     assert not generate_regular_certificate_task(other_user,
                                                  self.course_run_key)
    def test_can_generate_audit(self):
        """
        Test handling when user is enrolled in audit mode
        """
        u = UserFactory()
        cr = CourseFactory()
        key = cr.id  # pylint: disable=no-member
        CourseEnrollmentFactory(
            user=u,
            course_id=key,
            is_active=True,
            mode="audit",
        )

        assert not _can_generate_v2_certificate(u, key)
    def test_can_generate_not_verified_no_cert(self):
        """
        Test handling when the user's id is not verified and they don't have a cert
        """
        u = UserFactory()
        CourseEnrollmentFactory(
            user=u,
            course_id=self.course_run_key,
            is_active=True,
            mode=GeneratedCertificate.MODES.verified,
        )

        with mock.patch(ID_VERIFIED_METHOD, return_value=False):
            assert not _can_generate_v2_certificate(u, self.course_run_key)
            assert _set_v2_cert_status(
                u, self.course_run_key) == CertificateStatuses.unverified
    def test_can_generate_not_verified_not_passing(self):
        """
        Test handling when the user's id is not verified and the user is not passing
        """
        u = UserFactory()
        CourseEnrollmentFactory(
            user=u,
            course_id=self.course_run_key,
            is_active=True,
            mode=GeneratedCertificate.MODES.verified,
        )
        GeneratedCertificateFactory(user=u,
                                    course_id=self.course_run_key,
                                    mode=GeneratedCertificate.MODES.verified,
                                    status=CertificateStatuses.generating)

        with mock.patch(ID_VERIFIED_METHOD, return_value=False):
            with mock.patch(PASSING_GRADE_METHOD, return_value=False):
                assert not _can_generate_v2_certificate(u, self.course_run_key)
                assert _set_v2_cert_status(u, self.course_run_key) is None
    def test_can_generate_not_passing_cert(self):
        """
        Test handling when the user does not have a passing grade and a cert exists
        """
        u = UserFactory()
        CourseEnrollmentFactory(
            user=u,
            course_id=self.course_run_key,
            is_active=True,
            mode=GeneratedCertificate.MODES.verified,
        )
        GeneratedCertificateFactory(user=u,
                                    course_id=self.course_run_key,
                                    mode=GeneratedCertificate.MODES.verified,
                                    status=CertificateStatuses.generating)

        with mock.patch(PASSING_GRADE_METHOD, return_value=False):
            assert not _can_generate_v2_certificate(u, self.course_run_key)
            assert _set_v2_cert_status(
                u, self.course_run_key) == CertificateStatuses.notpassing