Disable posting to LinkedIn feature for microsites until we can support multiple LinkedIn accounts

This commit is contained in:
Chris Dodge
2015-11-06 10:49:37 -05:00
parent 7b801c66ca
commit eeb8c48922
5 changed files with 98 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
import unittest
import ddt
import mock
from django.conf import settings
from django.core.urlresolvers import reverse
@@ -15,9 +16,18 @@ from certificates.tests.factories import GeneratedCertificateFactory # pylint:
from certificates.api import get_certificate_url # pylint: disable=import-error
from course_modes.models import CourseMode
from student.models import LinkedInAddToProfileConfiguration
# pylint: disable=no-member
def _fake_is_request_in_microsite():
"""
Mocked version of microsite helper method to always return true
"""
return True
@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CertificateDisplayTest(ModuleStoreTestCase):
@@ -98,6 +108,60 @@ class CertificateDisplayTest(ModuleStoreTestCase):
self.assertContains(response, u'View Test_Certificate')
self.assertContains(response, test_url)
def test_post_to_linkedin_invisibility(self):
"""
Verifies that the post certificate to linked button
does not appear by default (when config is not set)
"""
self._create_certificate('honor')
# until we set up the configuration, the LinkedIn action
# button should not be visible
self._check_linkedin_visibility(False)
def test_post_to_linkedin_visibility(self):
"""
Verifies that the post certificate to linked button appears
as expected
"""
self._create_certificate('honor')
config = LinkedInAddToProfileConfiguration(
company_identifier='0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9',
enabled=True
)
config.save()
# now we should see it
self._check_linkedin_visibility(True)
@mock.patch("microsite_configuration.microsite.is_request_in_microsite", _fake_is_request_in_microsite)
def test_post_to_linkedin_microsite(self):
"""
Verifies behavior for microsites which disables the post to LinkedIn
feature (for now)
"""
self._create_certificate('honor')
config = LinkedInAddToProfileConfiguration(
company_identifier='0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9',
enabled=True
)
config.save()
# now we should not see it because we are in a microsite
self._check_linkedin_visibility(False)
def _check_linkedin_visibility(self, is_visible):
"""
Performs assertions on the Dashboard
"""
response = self.client.get(reverse('dashboard'))
if is_visible:
self.assertContains(response, u'Add Certificate to LinkedIn Profile')
else:
self.assertNotContains(response, u'Add Certificate to LinkedIn Profile')
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)

View File

@@ -362,7 +362,10 @@ def _cert_info(user, course_overview, cert_status, course_mode): # pylint: disa
# 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:
# posting certificates to LinkedIn is not currently
# supported in microsites/White Labels
if linkedin_config.enabled and not microsite.is_request_in_microsite():
status_dict['linked_in_url'] = linkedin_config.add_to_profile_url(
course_overview.id,
course_overview.display_name,