Merge pull request #8385 from edx/asadiqbal08/SOL-961
(WIP) SOL-961 Student Generated Certificate Flow shows "download" certificate
This commit is contained in:
@@ -816,6 +816,85 @@ class ProgressPageTests(ModuleStoreTestCase):
|
||||
resp = views.progress(self.request, course_id=unicode(self.course.id))
|
||||
self.assertNotContains(resp, 'Request Certificate')
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True})
|
||||
@patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [],
|
||||
'grade_breakdown': []}))
|
||||
def test_view_certificate_link(self):
|
||||
"""
|
||||
If certificate web view is enabled then certificate web view button should appear for user who certificate is
|
||||
available/generated
|
||||
"""
|
||||
GeneratedCertificateFactory.create(
|
||||
user=self.user,
|
||||
course_id=self.course.id,
|
||||
status=CertificateStatuses.downloadable,
|
||||
download_url="http://www.example.com/certificate.pdf",
|
||||
mode='honor'
|
||||
)
|
||||
|
||||
# Enable the feature, but do not enable it for this course
|
||||
CertificateGenerationConfiguration(enabled=True).save()
|
||||
|
||||
# Enable certificate generation for this course
|
||||
certs_api.set_cert_generation_enabled(self.course.id, True)
|
||||
|
||||
#course certificate configurations
|
||||
certificates = [
|
||||
{
|
||||
'id': 1,
|
||||
'name': 'Name 1',
|
||||
'description': 'Description 1',
|
||||
'course_title': 'course_title_1',
|
||||
'org_logo_path': '/t4x/orgX/testX/asset/org-logo-1.png',
|
||||
'signatories': [],
|
||||
'version': 1,
|
||||
'is_active': True
|
||||
}
|
||||
]
|
||||
|
||||
self.course.certificates = {'certificates': certificates}
|
||||
self.course.save()
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
resp = views.progress(self.request, course_id=unicode(self.course.id))
|
||||
self.assertContains(resp, u"View Certificate")
|
||||
self.assertContains(resp, u"You can now view your certificate")
|
||||
self.assertContains(resp, certs_api.get_certificate_url(user_id=self.user.id, course_id=self.course.id))
|
||||
|
||||
# when course certificate is not active
|
||||
certificates[0]['is_active'] = False
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
resp = views.progress(self.request, course_id=unicode(self.course.id))
|
||||
self.assertNotContains(resp, u"View Your Certificate")
|
||||
self.assertNotContains(resp, u"You can now view your certificate")
|
||||
self.assertContains(resp, u"We're creating your certificate.")
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False})
|
||||
@patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [],
|
||||
'grade_breakdown': []}))
|
||||
def test_view_certificate_link_hidden(self):
|
||||
"""
|
||||
If certificate web view is disabled then certificate web view button should not appear for user who certificate
|
||||
is available/generated
|
||||
"""
|
||||
GeneratedCertificateFactory.create(
|
||||
user=self.user,
|
||||
course_id=self.course.id,
|
||||
status=CertificateStatuses.downloadable,
|
||||
download_url="http://www.example.com/certificate.pdf",
|
||||
mode='honor'
|
||||
)
|
||||
|
||||
# Enable the feature, but do not enable it for this course
|
||||
CertificateGenerationConfiguration(enabled=True).save()
|
||||
|
||||
# Enable certificate generation for this course
|
||||
certs_api.set_cert_generation_enabled(self.course.id, True)
|
||||
|
||||
resp = views.progress(self.request, course_id=unicode(self.course.id))
|
||||
self.assertContains(resp, u"Download Your Certificate")
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class VerifyCourseKeyDecoratorTests(TestCase):
|
||||
|
||||
@@ -1063,6 +1063,21 @@ def _progress(request, course_key, student_id):
|
||||
|
||||
if show_generate_cert_btn:
|
||||
context.update(certs_api.certificate_downloadable_status(student, course_key))
|
||||
# showing the certificate web view button if feature flags are enabled.
|
||||
if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False):
|
||||
if certs_api.get_active_web_certificate(course) is not None:
|
||||
context.update({
|
||||
'show_cert_web_view': True,
|
||||
'cert_web_view_url': u'{url}'.format(
|
||||
url=certs_api.get_certificate_url(user_id=student.id, course_id=unicode(course.id))
|
||||
)
|
||||
})
|
||||
else:
|
||||
context.update({
|
||||
'is_downloadable': False,
|
||||
'is_generating': True,
|
||||
'download_url': None
|
||||
})
|
||||
|
||||
with grades.manual_transaction():
|
||||
response = render_to_response('courseware/progress.html', context)
|
||||
|
||||
@@ -59,15 +59,25 @@ from django.utils.http import urlquote_plus
|
||||
<% post_url = reverse('generate_user_cert', args=[unicode(course.id)]) %>
|
||||
<div class="msg-content">
|
||||
<h2 class="title">${_("Your certificate is available")}</h2>
|
||||
%if show_cert_web_view:
|
||||
<p class="copy">${_("You can now view your certificate.")}</p>
|
||||
%else:
|
||||
<p class="copy">${_(
|
||||
"You can now download your certificate as a PDF. If you keep working and receive a higher grade,you can request an {link_start} updated certificate {link_end}.").format(
|
||||
link_start=u"<a class='generate_certs' href='#' data-endpoint={}>".format(post_url) ,link_end=u"</a>")}
|
||||
</p>
|
||||
%endif
|
||||
</div>
|
||||
<div class="msg-actions">
|
||||
%if show_cert_web_view:
|
||||
<a class="btn" href="${cert_web_view_url}" target="_blank" title="${_('View certificate in a new browser window or tab.')}">
|
||||
${_("View Certificate")}
|
||||
</a>
|
||||
%else:
|
||||
<a class="btn" href="${download_url}" target="_blank" title="${_('PDF will open in a new browser window or tab.')}">
|
||||
${_("Download Your Certificate")}
|
||||
</a>
|
||||
%endif
|
||||
</div>
|
||||
%elif is_generating:
|
||||
<div class="msg-content">
|
||||
|
||||
Reference in New Issue
Block a user