11"""Tests for LinkedIn Add to Profile configuration. """
22
3-
3+ from types import SimpleNamespace
44from urllib .parse import quote
55import ddt
6-
76from django .conf import settings
87from django .test import TestCase
98
109from lms .djangoapps .certificates .tests .factories import LinkedInAddToProfileConfigurationFactory
1110from openedx .core .djangoapps .site_configuration .tests .test_util import with_site_configuration_context
1211
13-
1412@ddt .ddt
1513class LinkedInAddToProfileUrlTests (TestCase ):
1614 """Tests for URL generation of LinkedInAddToProfileConfig. """
1715
1816 COURSE_NAME = 'Test Course ☃'
1917 CERT_URL = 'http://s3.edx/cert'
18+ COURSE_ORGANIZATION = 'TEST+ORGANIZATION'
2019 SITE_CONFIGURATION = {
2120 'SOCIAL_SHARING_SETTINGS' : {
2221 'CERTIFICATE_LINKEDIN_MODE_TO_CERT_NAME' : {
@@ -27,6 +26,17 @@ class LinkedInAddToProfileUrlTests(TestCase):
2726 }
2827 }
2928 }
29+ SITE_CONFIGURATION_COURSE_LEVEL_ORG = {
30+ 'SOCIAL_SHARING_SETTINGS' : {
31+ 'CERTIFICATE_LINKEDIN_DEFAULTS_TO_COURSE_ORGANIZATION_NAME' : True ,
32+ 'CERTIFICATE_LINKEDIN_MODE_TO_CERT_NAME' : {
33+ 'honor' : '{platform_name} Honor Code Credential for {course_name}' ,
34+ 'verified' : '{platform_name} Verified Credential for {course_name}' ,
35+ 'professional' : '{platform_name} Professional Credential for {course_name}' ,
36+ 'no-id-professional' : '{platform_name} Professional Credential for {course_name}' ,
37+ }
38+ }
39+ }
3040
3141 @ddt .data (
3242 ('honor' , 'Honor+Code+Certificate+for+Test+Course+%E2%98%83' ),
@@ -49,7 +59,13 @@ def test_linked_in_url(self, cert_mode, expected_cert_name):
4959 company_identifier = config .company_identifier ,
5060 )
5161
52- actual_url = config .add_to_profile_url (self .COURSE_NAME , cert_mode , self .CERT_URL )
62+ course_mock_object = SimpleNamespace (
63+ display_name = self .COURSE_NAME , display_organization = self .COURSE_ORGANIZATION
64+ )
65+
66+ actual_url = config .add_to_profile_url (
67+ course_mock_object , cert_mode , self .CERT_URL
68+ )
5369
5470 self .assertEqual (actual_url , expected_url )
5571
@@ -74,8 +90,49 @@ def test_linked_in_url_with_cert_name_override(self, cert_mode, expected_cert_na
7490 cert_url = quote (self .CERT_URL , safe = '' ),
7591 company_identifier = config .company_identifier ,
7692 )
77-
7893 with with_site_configuration_context (configuration = self .SITE_CONFIGURATION ):
79- actual_url = config .add_to_profile_url (self .COURSE_NAME , cert_mode , self .CERT_URL )
94+ course_mock_object = SimpleNamespace (
95+ display_name = self .COURSE_NAME ,
96+ display_organization = self .COURSE_ORGANIZATION ,
97+ )
98+ actual_url = config .add_to_profile_url (
99+ course_mock_object , cert_mode , self .CERT_URL
100+ )
101+ self .assertEqual (actual_url , expected_url )
102+
103+ @ddt .data (
104+ ('honor' , 'Honor+Code+Credential+for+Test+Course+%E2%98%83' ),
105+ ('verified' , 'Verified+Credential+for+Test+Course+%E2%98%83' ),
106+ ('professional' , 'Professional+Credential+for+Test+Course+%E2%98%83' ),
107+ ('no-id-professional' , 'Professional+Credential+for+Test+Course+%E2%98%83' ),
108+ ('default_mode' , 'Certificate+for+Test+Course+%E2%98%83' )
109+ )
110+ @ddt .unpack
111+ def test_linked_in_url_with_course_org_name_override (
112+ self , cert_mode , expected_cert_name
113+ ):
114+ config = LinkedInAddToProfileConfigurationFactory ()
115+
116+ expected_url = (
117+ 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
118+ 'name={platform}+{cert_name}&certUrl={cert_url}&'
119+ 'organizationName={course_organization_name}'
120+ ).format (
121+ platform = quote (settings .PLATFORM_NAME .encode ('utf-8' )),
122+ cert_name = expected_cert_name ,
123+ cert_url = quote (self .CERT_URL , safe = '' ),
124+ course_organization_name = quote (self .COURSE_ORGANIZATION .encode ('utf-8' )),
125+ )
126+
127+ with with_site_configuration_context (
128+ configuration = self .SITE_CONFIGURATION_COURSE_LEVEL_ORG
129+ ):
130+ course_mock_object = SimpleNamespace (
131+ display_name = self .COURSE_NAME ,
132+ display_organization = self .COURSE_ORGANIZATION ,
133+ )
134+ actual_url = config .add_to_profile_url (
135+ course_mock_object , cert_mode , self .CERT_URL
136+ )
80137
81138 self .assertEqual (actual_url , expected_url )
0 commit comments