From c230f22b5237df9123a4f87fee0fa5f9089c8477 Mon Sep 17 00:00:00 2001 From: asadiqbal Date: Mon, 24 Aug 2015 18:03:57 +0500 Subject: [PATCH] SOL-1097 --- .../certificates/tests/test_views.py | 16 ++++++++++ lms/djangoapps/certificates/views/webview.py | 30 +++++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lms/djangoapps/certificates/tests/test_views.py b/lms/djangoapps/certificates/tests/test_views.py index d4b56143c5..21c8930d43 100644 --- a/lms/djangoapps/certificates/tests/test_views.py +++ b/lms/djangoapps/certificates/tests/test_views.py @@ -39,6 +39,8 @@ from certificates.tests.factories import ( BadgeAssertionFactory, ) from util import organizations_helpers as organizations_api +from django.test.client import RequestFactory +import urllib FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True @@ -379,6 +381,7 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase): self.user.profile.name = "Joe User" self.user.profile.save() self.client.login(username=self.user.username, password='foo') + self.request = RequestFactory().request() self.cert = GeneratedCertificate.objects.create( user=self.user, @@ -457,6 +460,19 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase): ) template.save() + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + def test_linkedin_share_url(self): + """ + Test: LinkedIn share URL. + """ + self._add_course_certificates(count=1, signatory_count=1, is_active=True) + test_url = get_certificate_url( + user_id=self.user.id, + course_id=unicode(self.course.id) + ) + response = self.client.get(test_url) + self.assertTrue(urllib.quote_plus(self.request.build_absolute_uri(test_url)) in response.content) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) def test_rendering_course_organization_data(self): """ diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index 5650c686db..2396fe4ee6 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -228,21 +228,6 @@ def _update_certificate_context(context, course, user, user_certificate): if certificate_type_description: context['certificate_type_description'] = certificate_type_description - # If enabled, show the LinkedIn "add to profile" button - # Clicking this button sends the user to LinkedIn where they - # can add the certificate information to their profile. - linkedin_config = LinkedInAddToProfileConfiguration.current() - if linkedin_config.enabled: - context['linked_in_url'] = linkedin_config.add_to_profile_url( - course.id, - course.display_name, - user_certificate.mode, - get_certificate_url( - user_id=user.id, - course_id=unicode(course.id) - ) - ) - # Translators: This line is displayed to a user who has completed a course and achieved a certification context['accomplishment_banner_opening'] = _("{fullname}, you've earned a certificate!").format( fullname=user_fullname @@ -377,6 +362,21 @@ def render_html_view(request, user_id, course_id): # Append/Override the existing view context values with request-time values _update_certificate_context(context, course, user, user_certificate) + # If enabled, show the LinkedIn "add to profile" button + # Clicking this button sends the user to LinkedIn where they + # can add the certificate information to their profile. + linkedin_config = LinkedInAddToProfileConfiguration.current() + if linkedin_config.enabled: + context['linked_in_url'] = linkedin_config.add_to_profile_url( + course.id, + course.display_name, + user_certificate.mode, + request.build_absolute_uri(get_certificate_url( + user_id=user.id, + course_id=unicode(course.id) + )) + ) + # Microsites will need to be able to override any hard coded # content that was put into the context in the # _update_certificate_context() call above. For example the