示例#1
0
    def test_generation(self):
        """
        Test that a cert is successfully generated
        """
        cert = get_certificate_for_user_id(self.user.id, self.course_run_key)
        assert not cert

        with mock.patch(PASSING_GRADE_METHOD, return_value=True):
            with mock.patch(ID_VERIFIED_METHOD, return_value=True):
                generate_certificate_task(self.user, self.course_run_key)

                cert = get_certificate_for_user_id(self.user.id, self.course_run_key)
                assert cert.status == CertificateStatuses.downloadable
                assert cert.mode == CourseMode.VERIFIED
示例#2
0
    def test_generation_unverified(self, enable_idv_requirement):
        """
        Test that a cert is successfully generated with a status of unverified
        """
        cert = get_certificate_for_user_id(self.user.id, self.course_run_key)
        assert not cert

        with mock.patch(PASSING_GRADE_METHOD, return_value=True):
            with mock.patch(ID_VERIFIED_METHOD, return_value=False):
                with mock.patch.dict(settings.FEATURES, ENABLE_CERTIFICATES_IDV_REQUIREMENT=enable_idv_requirement):
                    generate_certificate_task(self.user, self.course_run_key)

                    cert = get_certificate_for_user_id(self.user.id, self.course_run_key)
                    assert cert.mode == CourseMode.VERIFIED
                    if enable_idv_requirement:
                        assert cert.status == CertificateStatuses.unverified
                    else:
                        assert cert.status == CertificateStatuses.downloadable
示例#3
0
    def test_get_certificate_for_user_id(self):
        """
        Test to get a certificate for a user id for a specific course.
        """
        cert = get_certificate_for_user_id(self.student, self.web_cert_course.id)

        assert cert is not None
        assert cert.course_id == self.web_cert_course.id
        assert cert.mode == CourseMode.VERIFIED
        assert cert.status == CertificateStatuses.downloadable
        assert cert.grade == '0.88'
示例#4
0
    def handle_goal(goal, today, sunday_date, monday_date):
        """Sends an email reminder for a single CourseGoal, if it passes all our checks"""
        if not COURSE_GOALS_NUMBER_OF_DAYS_GOALS.is_enabled(goal.course_key):
            return False

        enrollment = CourseEnrollment.get_enrollment(goal.user,
                                                     goal.course_key,
                                                     select_related=['course'])
        # If you're not actively enrolled in the course or your enrollment was this week
        if not enrollment or not enrollment.is_active or enrollment.created.date(
        ) >= monday_date:
            return False

        audit_access_expiration_date = get_user_course_expiration_date(
            goal.user, enrollment.course_overview)
        # If an audit user's access expires this week, exclude them from the email since they may not
        # be able to hit their goal anyway
        if audit_access_expiration_date and audit_access_expiration_date.date(
        ) <= sunday_date:
            return False

        cert = get_certificate_for_user_id(goal.user, goal.course_key)
        # If a user has a downloadable certificate, we will consider them as having completed
        # the course and opt them out of receiving emails
        if cert and cert.status == CertificateStatuses.downloadable:
            return False

        # Check the number of days left to successfully hit their goal
        week_activity_count = UserActivity.objects.filter(
            user=goal.user,
            course_key=goal.course_key,
            date__gte=monday_date,
        ).count()
        required_days_left = goal.days_per_week - week_activity_count
        # The weekdays are 0 indexed, but we want this to be 1 to match required_days_left.
        # Essentially, if today is Sunday, days_left_in_week should be 1 since they have Sunday to hit their goal.
        days_left_in_week = SUNDAY_WEEKDAY - today.weekday() + 1

        # We want to email users in the morning of their timezone
        user_timezone = get_user_timezone_or_last_seen_timezone_or_utc(
            goal.user)
        now_in_users_timezone = datetime.now(user_timezone)
        if not 9 <= now_in_users_timezone.hour < 12:
            return False

        if required_days_left == days_left_in_week:
            send_ace_message(goal)
            CourseGoalReminderStatus.objects.update_or_create(
                goal=goal, defaults={'email_reminder_sent': True})
            return True

        return False
示例#5
0
    def test_generation_notpassing(self):
        """
        Test that a cert is successfully generated with a status of notpassing
        """
        GeneratedCertificateFactory(user=self.user,
                                    course_id=self.course_run_key,
                                    status=CertificateStatuses.unavailable,
                                    mode=CourseMode.AUDIT)

        with mock.patch(PASSING_GRADE_METHOD, return_value=False):
            with mock.patch(ID_VERIFIED_METHOD, return_value=True):
                generate_certificate_task(self.user, self.course_run_key)

                cert = get_certificate_for_user_id(self.user.id,
                                                   self.course_run_key)
                assert cert.status == CertificateStatuses.notpassing
                assert cert.mode == CourseMode.VERIFIED
示例#6
0
    def is_entitlement_regainable(self, entitlement):
        """
        Determines from the policy if an entitlement can still be regained by the user, if they choose
        to by leaving and regaining their entitlement within policy.regain_period days from start date of
        the course or their redemption, whichever comes later, and the expiration period hasn't passed yet
        """
        if entitlement.expired_at:
            return False

        if entitlement.enrollment_course_run:
            certificate = certificates_api.get_certificate_for_user_id(
                entitlement.user, entitlement.enrollment_course_run.course_id)
            if certificate and not CertificateStatuses.is_refundable_status(
                    certificate.status):
                return False

            # This is >= because a days_until_expiration 0 means that the expiration day has not fully passed yet
            # and that the entitlement should not be expired as there is still time
            return self.get_days_until_expiration(entitlement) >= 0
        return False