Beispiel #1
0
    def test_with_downloadable_web_cert(self):
        CourseEnrollment.enroll(self.student, self.course.id, mode='honor')
        self._setup_course_certificate()
        with self._mock_passing_grade():
            certs_api.generate_user_certificates(self.student, self.course.id)

        cert_status = certificate_status_for_student(self.student,
                                                     self.course.id)
        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student,
                                                      self.course.id),
            {
                'is_downloadable':
                True,
                'is_generating':
                False,
                'is_unverified':
                False,
                'download_url':
                '/certificates/user/{user_id}/course/{course_id}'.format(
                    user_id=self.student.id,  # pylint: disable=no-member
                    course_id=self.course.id,
                ),
                'uuid':
                cert_status['uuid']
            })
Beispiel #2
0
 def get_certificate(self, model):
     """Returns the information about the user's certificate in the course."""
     certificate_info = certificate_downloadable_status(model.user, model.course_id)
     if certificate_info["is_downloadable"]:
         return {"url": self.context["request"].build_absolute_uri(certificate_info["download_url"])}
     else:
         return {}
Beispiel #3
0
 def test_cert_status_with_generating(self):
     GeneratedCertificateFactory.create(
         user=self.student, course_id=self.course.id, status=CertificateStatuses.generating, mode="verified"
     )
     self.assertEqual(
         certs_api.certificate_downloadable_status(self.student, self.course.id),
         {"is_downloadable": False, "is_generating": True, "download_url": None, "uuid": None},
     )
Beispiel #4
0
 def test_user_with_out_cert(self):
     self.assertEqual(
         certs_api.certificate_downloadable_status(self.student_no_cert,
                                                   self.course.id),
         {
             'is_downloadable': False,
             'is_generating': False,
             'download_url': None
         })
Beispiel #5
0
 def test_user_with_out_cert(self):
     self.assertEqual(
         certs_api.certificate_downloadable_status(self.student_no_cert, self.course.id),
         {
             'is_downloadable': False,
             'is_generating': False,
             'download_url': None
         }
     )
Beispiel #6
0
 def get_certificate(self, model):
     """Returns the information about the user's certificate in the course."""
     certificate_info = certificate_downloadable_status(model.user, model.course_id)
     if certificate_info['is_downloadable']:
         return {
             'url': self.context['request'].build_absolute_uri(
                 certificate_info['download_url']
             ),
         }
     else:
         return {}
Beispiel #7
0
 def test_user_with_out_cert(self):
     """
     in case of no certificate means is_generating is False and is_downloadable is False
     """
     self.assertEqual(
         certificate_downloadable_status(self.student_no_cert, self.course.id),
         {
             'is_downloadable': False,
             'is_generating': False,
             'download_url': None
         }
     )
    def get_cert_status(self):
        student_id = self.scope_ids.user_id
        course_id = str(self.xmodule_runtime.course_id)
        course_key = CourseKey.from_string(course_id)
        student = User.objects.prefetch_related("groups").get(id=student_id)
	course = get_course_with_access(student, 'load', course_key, depth=None, check_if_enrolled=True)

        show_generate_cert_btn = certs_api.cert_generation_enabled(course_key)	
        grade_summary = get_grades(course,student)		
	

	print "grade_summary====================",grade_summary
	
	failed = None
	if grade_summary["totaled_scores"]:
		if grade_summary["percent"]   < course.grading_policy["GRADE_CUTOFFS"]["Pass"]:
			failed = True
	
	
	context = {
                        'passed': grade_summary,
                        'course':course,
			'student':student,
			'failed':failed
                }
       	if grade_summary["percent"]  and grade_summary["percent"]   >= course.grading_policy["GRADE_CUTOFFS"]["Pass"]:
		

		print "in totaled score"
		context.update({
                        'show_generate_cert_btn':True
                })

            	cert_status = certs_api.certificate_downloadable_status(student, course_key)
	    	context.update(cert_status)
        	# showing the certificate web view button if feature flags are enabled.
        	if certs_api.has_html_certificates_enabled(course_key, course):
            		if certs_api.get_active_web_certificate(course) is not None:
              			context.update({
                    			'show_cert_web_view': True,
                    			'cert_web_view_url': certs_api.get_certificate_url(course_id=course_key, uuid=cert_status['uuid']),
					'show_generate_cert_btn':True
                		})
            		else:
                		context.update({
                    			'is_downloadable': False,
                    			'is_generating': True,
                    			'download_url': None
                		})

        print "outside totaled score"
	return context
Beispiel #9
0
    def test_with_downloadable_pdf_cert(self):
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode="verified",
            download_url="www.google.com",
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {"is_downloadable": True, "is_generating": False, "download_url": "www.google.com"},
        )
Beispiel #10
0
    def test_user_cert_status_with_error(self):
        GeneratedCertificateFactory.create(user=self.student,
                                           course_id=self.course.id,
                                           status=CertificateStatuses.error,
                                           mode='verified')

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student,
                                                      self.course.id),
            {
                'is_downloadable': False,
                'is_generating': True,
                'download_url': None
            })
Beispiel #11
0
    def test_user_with_downloadable_cert(self):
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified',
            download_url='www.google.com')

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student,
                                                      self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': 'www.google.com'
            })
Beispiel #12
0
    def test_with_downloadable_web_cert(self):
        CourseEnrollment.enroll(self.student, self.course.id, mode="honor")
        self._setup_course_certificate()
        with self._mock_passing_grade():
            certs_api.generate_user_certificates(self.student, self.course.id)

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                "is_downloadable": True,
                "is_generating": False,
                "download_url": "/certificates/user/{user_id}/course/{course_id}".format(
                    user_id=self.student.id, course_id=self.course.id  # pylint: disable=no-member
                ),
            },
        )
Beispiel #13
0
    def test_user_cert_status_with_error(self):
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.error,
            mode='verified'
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': False,
                'is_generating': True,
                'download_url': None
            }
        )
Beispiel #14
0
    def test_cert_api_return(self, self_paced, cert_avail_date, cert_downloadable_status):
        """
        Test 'downloadable status'
        """
        self.course.self_paced = self_paced
        self.course.certificate_available_date = cert_avail_date
        self.course.save()

        CourseEnrollment.enroll(self.student, self.course.id, mode='honor')
        self._setup_course_certificate()
        with mock_passing_grade():
            certs_api.generate_user_certificates(self.student, self.course.id)

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id)['is_downloadable'],
            cert_downloadable_status
        )
Beispiel #15
0
    def test_with_downloadable_web_cert(self):
        CourseEnrollment.enroll(self.student, self.course.id, mode='honor')
        self._setup_course_certificate()
        with self._mock_passing_grade():
            certs_api.generate_user_certificates(self.student, self.course.id)

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': '/certificates/user/{user_id}/course/{course_id}'.format(
                    user_id=self.student.id,  # pylint: disable=no-member
                    course_id=self.course.id,
                ),
            }
        )
Beispiel #16
0
    def test_user_with_downloadable_cert(self):
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified',
            download_url='www.google.com'
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': 'www.google.com'
            }
        )
Beispiel #17
0
    def test_cert_api_return(self, self_paced, cert_avail_delta, cert_downloadable_status):
        """
        Test 'downloadable status'
        """
        cert_avail_date = datetime.now(pytz.UTC) + cert_avail_delta
        self.course.self_paced = self_paced
        self.course.certificate_available_date = cert_avail_date
        self.course.save()

        CourseEnrollment.enroll(self.student, self.course.id, mode='honor')
        self._setup_course_certificate()
        with mock_passing_grade():
            certs_api.generate_user_certificates(self.student, self.course.id)

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id)['is_downloadable'],
            cert_downloadable_status
        )
Beispiel #18
0
    def test_user_cert_status_with_generating(self):
        """
        in case of certificate with error means means is_generating is True and is_downloadable is False
        """
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.generating,
            mode='verified'
        )

        self.assertEqual(
            certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': False,
                'is_generating': True,
                'download_url': None
            }
        )
Beispiel #19
0
    def verify_downloadable_pdf_cert(self):
        """
        Verifies certificate_downloadable_status returns the
        correct response for PDF certificates.
        """
        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified',
            download_url='www.google.com'
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': 'www.google.com'
            }
        )
Beispiel #20
0
    def verify_downloadable_pdf_cert(self):
        """
        Verifies certificate_downloadable_status returns the
        correct response for PDF certificates.
        """
        cert = GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified',
            download_url='www.google.com',
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student,
                                                      self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': 'www.google.com',
                'uuid': cert.verify_uuid
            })
Beispiel #21
0
    def test_user_with_downloadable_cert(self):
        """
        in case of downloadable certificate means is_generating is False and is_downloadable is True
        download_url has cert link
        """

        GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode='verified',
            download_url='www.google.com'
        )

        self.assertEqual(
            certificate_downloadable_status(self.student, self.course.id),
            {
                'is_downloadable': True,
                'is_generating': False,
                'download_url': 'www.google.com'
            }
        )
Beispiel #22
0
    def verify_downloadable_pdf_cert(self):
        """
        Verifies certificate_downloadable_status returns the
        correct response for PDF certificates.
        """
        cert = GeneratedCertificateFactory.create(
            user=self.student,
            course_id=self.course.id,
            status=CertificateStatuses.downloadable,
            mode="verified",
            download_url="www.google.com",
        )

        self.assertEqual(
            certs_api.certificate_downloadable_status(self.student, self.course.id),
            {
                "is_downloadable": True,
                "is_generating": False,
                "download_url": "www.google.com",
                "uuid": cert.verify_uuid,
            },
        )
Beispiel #23
0
 def test_without_cert(self):
     self.assertEqual(
         certs_api.certificate_downloadable_status(self.student_no_cert, self.course.id),
         {"is_downloadable": False, "is_generating": False, "download_url": None, "uuid": None},
     )
Beispiel #24
0
def generate_user_cert(request, course_id):
    """Start generating a new certificate for the user.

    Certificate generation is allowed if:
    * The user has passed the course, and
    * The user does not already have a pending/completed certificate.

    Note that if an error occurs during certificate generation
    (for example, if the queue is down), then we simply mark the
    certificate generation task status as "error" and re-run
    the task with a management command.  To students, the certificate
    will appear to be "generating" until it is re-run.

    Args:
        request (HttpRequest): The POST request to this view.
        course_id (unicode): The identifier for the course.

    Returns:
        HttpResponse: 200 on success, 400 if a new certificate cannot be generated.

    """

    if not request.user.is_authenticated():
        log.info(u"Anon user trying to generate certificate for %s", course_id)
        return HttpResponseBadRequest(
            _('You must be signed in to {platform_name} to create a certificate.'
              ).format(platform_name=configuration_helpers.get_value(
                  'PLATFORM_NAME', settings.PLATFORM_NAME)))

    student = request.user
    course_key = CourseKey.from_string(course_id)

    course = modulestore().get_course(course_key, depth=2)
    if not course:
        return HttpResponseBadRequest(_("Course is not valid"))

    if not is_course_passed(course, None, student, request):
        return HttpResponseBadRequest(
            _("Your certificate will be available when you pass the course."))

    certificate_status = certs_api.certificate_downloadable_status(
        student, course.id)

    if certificate_status["is_downloadable"]:
        return HttpResponseBadRequest(
            _("Certificate has already been created."))
    elif certificate_status["is_generating"]:
        return HttpResponseBadRequest(_("Certificate is being created."))
    else:
        # If the certificate is not already in-process or completed,
        # then create a new certificate generation task.
        # If the certificate cannot be added to the queue, this will
        # mark the certificate with "error" status, so it can be re-run
        # with a management command.  From the user's perspective,
        # it will appear that the certificate task was submitted successfully.
        base_url = settings.LMS_ROOT_URL
        MandrillClient().send_mail(
            MandrillClient.COURSE_COMPLETION_TEMPLATE, student.email, {
                'course_name':
                course.display_name,
                'course_url':
                get_course_link(course_id=course.id),
                'full_name':
                student.first_name + " " + student.last_name,
                'certificate_url':
                base_url +
                get_certificate_url(user_id=student.id, course_id=course.id),
                'course_library_url':
                base_url + '/courses',
            })
        certs_api.generate_user_certificates(student,
                                             course.id,
                                             course=course,
                                             generation_mode='self')
        _track_successful_certificate_generation(student.id, course.id)
        return HttpResponse()
Beispiel #25
0
def check_status(request, course_id):
    course_key = locator.CourseLocator.from_string(course_id)
    status = certificate_downloadable_status(request.user, course_key)
    return Response(status)