From 464bcf336e6b73d1b30d2924334fa3be916d3cc7 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Tue, 31 Mar 2015 13:24:28 -0400 Subject: [PATCH] Show certificates for all verified modes --- .../student/tests/test_certificates.py | 54 +++++++++++++++++++ .../_dashboard_certificate_information.html | 7 ++- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 common/djangoapps/student/tests/test_certificates.py diff --git a/common/djangoapps/student/tests/test_certificates.py b/common/djangoapps/student/tests/test_certificates.py new file mode 100644 index 0000000000..4a440f7ed9 --- /dev/null +++ b/common/djangoapps/student/tests/test_certificates.py @@ -0,0 +1,54 @@ +"""Tests for display of certificates on the student dashboard. """ + +import unittest +import ddt + +from django.conf import settings +from django.core.urlresolvers import reverse + +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory +from student.tests.factories import UserFactory, CourseEnrollmentFactory +from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error + + +@ddt.ddt +@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') +class CertificateDisplayTest(ModuleStoreTestCase): + """Tests display of certificates on the student dashboard. """ + + USERNAME = "test_user" + PASSWORD = "password" + DOWNLOAD_URL = "http://www.example.com/certificate.pdf" + + def setUp(self): + super(CertificateDisplayTest, self).setUp() + self.user = UserFactory.create(username=self.USERNAME, password=self.PASSWORD) + result = self.client.login(username=self.USERNAME, password=self.PASSWORD) + self.assertTrue(result, msg="Could not log in") + + self.course = CourseFactory() + self.course.certificates_display_behavior = "early_with_info" + self.update_course(self.course, self.user.username) + + @ddt.data('verified', 'professional') + def test_display_verified_certificate(self, enrollment_mode): + self._create_certificate(enrollment_mode) + self._check_can_download_certificate() + + def _create_certificate(self, enrollment_mode): + """Simulate that the user has a generated certificate. """ + CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, mode=enrollment_mode) + GeneratedCertificateFactory( + user=self.user, + course_id=self.course.id, + mode=enrollment_mode, + download_url=self.DOWNLOAD_URL, + status="downloadable", + grade=0.98, + ) + + def _check_can_download_certificate(self): + response = self.client.get(reverse('dashboard')) + self.assertContains(response, u'Download Your ID Verified') + self.assertContains(response, self.DOWNLOAD_URL) diff --git a/lms/templates/dashboard/_dashboard_certificate_information.html b/lms/templates/dashboard/_dashboard_certificate_information.html index 676e4b91fd..798c12b5db 100644 --- a/lms/templates/dashboard/_dashboard_certificate_information.html +++ b/lms/templates/dashboard/_dashboard_certificate_information.html @@ -1,6 +1,9 @@ <%page args="cert_status, course, enrollment" /> -<%! from django.utils.translation import ugettext as _ %> +<%! +from django.utils.translation import ugettext as _ +from course_modes.models import CourseMode +%> <%namespace name='static' file='../static_content.html'/> <% @@ -61,7 +64,7 @@ else: ${_("Download Your {cert_name_short} (PDF)").format(cert_name_short=cert_name_short)} - % elif cert_status['show_download_url'] and enrollment.mode == 'verified': + % elif cert_status['show_download_url'] and enrollment.mode in CourseMode.VERIFIED_MODES: