Commit a9643c67 by Brian Beggs

Merge pull request #9896 from edx/mattdrayer/release/SOL-1230

mattdrayer/release/SOL-1230
parents 969cf766 2bd26fc0
......@@ -12,6 +12,7 @@ from django.test.utils import override_settings
from openedx.core.lib.tests.assertions.events import assert_event_matches
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from student.roles import CourseStaffRole
from track.tests import EventTrackingTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
......@@ -347,6 +348,13 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
course_id=unicode(self.course.id)
)
response = self.client.get(test_url + '?preview=honor')
#accessing certificate web view in preview mode without
# staff or instructor access should show invalid certificate
self.assertIn('This is an invalid certificate number', response.content)
CourseStaffRole(self.course.id).add_users(self.user)
response = self.client.get(test_url + '?preview=honor')
self.assertNotIn(self.course.display_name, response.content)
self.assertIn('course_title_0', response.content)
self.assertIn('Signatory_Title 0', response.content)
......@@ -359,6 +367,27 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
self.assertIn('Signatory_Title 0', response.content)
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
def test_render_html_view_with_preview_mode_when_user_already_has_cert(self):
"""
test certificate web view should render properly in
preview mode even if user who is previewing already has a certificate
generated with different mode.
"""
self._add_course_certificates(count=1, signatory_count=2)
CourseStaffRole(self.course.id).add_users(self.user)
test_url = get_certificate_url(
user_id=self.user.id,
course_id=unicode(self.course.id)
)
# user has already has certificate generated for 'honor' mode
# so let's try to preview in 'verified' mode.
response = self.client.get(test_url + '?preview=verified')
self.assertNotIn(self.course.display_name, response.content)
self.assertIn('course_title_0', response.content)
self.assertIn('Signatory_Title 0', response.content)
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
def test_render_html_view_invalid_certificate_configuration(self):
test_url = get_certificate_url(
user_id=self.user.id,
......
......@@ -14,6 +14,7 @@ from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from courseware.courses import course_image_url
from courseware.access import has_access
from edxmako.shortcuts import render_to_response
from edxmako.template import Template
from eventtracking import tracker
......@@ -287,6 +288,7 @@ def render_html_view(request, user_id, course_id):
context = {}
context['platform_name'] = microsite.get_value("platform_name", settings.PLATFORM_NAME)
context['course_id'] = course_id
preview_mode = request.GET.get('preview', None)
# Update the view context with the default ConfigurationModel settings
configuration = CertificateHtmlViewConfiguration.get_config()
......@@ -334,17 +336,27 @@ def render_html_view(request, user_id, course_id):
raise CourseDoesNotExist
# Attempt to load the user's generated certificate data
user_certificate = GeneratedCertificate.objects.get(
user=user,
course_id=course_key
)
if preview_mode:
user_certificate = GeneratedCertificate.objects.get(
user=user,
course_id=course_key,
mode=preview_mode
)
else:
user_certificate = GeneratedCertificate.objects.get(
user=user,
course_id=course_key
)
# If there's no generated certificate data for this user, we need to see if we're in 'preview' mode...
# If we are, we'll need to create a mock version of the user_certificate container for previewing
except GeneratedCertificate.DoesNotExist:
if request.GET.get('preview', None):
if preview_mode and (
has_access(request.user, 'instructor', course)
or has_access(request.user, 'staff', course)
):
user_certificate = GeneratedCertificate(
mode=request.GET.get('preview'),
mode=preview_mode,
verify_uuid=unicode(uuid4().hex),
modified_date=datetime.now().date()
)
......@@ -383,7 +395,7 @@ def render_html_view(request, user_id, course_id):
# Get the active certificate configuration for this course
# If we do not have an active certificate, we'll need to send the user to the "Invalid" screen
# Passing in the 'preview' parameter, if specified, will return a configuration, if defined
active_configuration = get_active_web_certificate(course, request.GET.get('preview'))
active_configuration = get_active_web_certificate(course, preview_mode)
if active_configuration is None:
return render_to_response(invalid_template_path, context)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment