5151from xmodule .modulestore .tests .django_utils import ModuleStoreTestCase , SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
5252from xmodule .modulestore .tests .factories import CourseFactory , check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order
5353from xmodule .data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order
54+ from openedx .core .djangoapps .site_configuration .tests .test_util import with_site_configuration_context
55+
5456log = logging .getLogger (__name__ )
5557
5658BETA_TESTER_METHOD = 'common.djangoapps.student.helpers.access.is_beta_tester'
@@ -90,85 +92,132 @@ def test_cert_info(self):
9092 download_url = 'http://s3.edx/cert'
9193 )
9294 enrollment = CourseEnrollmentFactory (user = user , course_id = course .id , mode = CourseMode .VERIFIED )
95+ # LinkedIn sharing disabled as we are expecting 'linked_in_url': None in our test case
96+ SITE_CONFIGURATION = {
97+ 'SOCIAL_SHARING_SETTINGS' : {
98+ 'CERTIFICATE_LINKEDIN' : False
99+ }
100+ }
101+ with with_site_configuration_context (configuration = SITE_CONFIGURATION ):
102+ assert _cert_info (user , enrollment , None ) == {
103+ 'status' : 'processing' ,
104+ 'show_survey_button' : False ,
105+ 'can_unenroll' : True ,
106+ }
93107
94- assert _cert_info (user , enrollment , None ) == \
95- {'status' : 'processing' , 'show_survey_button' : False , 'can_unenroll' : True }
96-
97- cert_status = {'status' : 'unavailable' , 'mode' : 'honor' , 'uuid' : None }
98- assert _cert_info (user , enrollment , cert_status ) == {'status' : 'processing' , 'show_survey_button' : False ,
99- 'mode' : 'honor' , 'linked_in_url' : None ,
100- 'can_unenroll' : True }
108+ cert_status = {'status' : 'unavailable' , 'mode' : 'honor' , 'uuid' : None }
109+ assert _cert_info (user , enrollment , cert_status ) == {
110+ 'status' : 'processing' ,
111+ 'show_survey_button' : False ,
112+ 'mode' : 'honor' ,
113+ 'linked_in_url' : None ,
114+ 'can_unenroll' : True ,
115+ }
101116
102- cert_status = {'status' : 'generating' , 'grade' : '0.67' , 'mode' : 'honor' , 'uuid' : None }
103- with patch ('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read' ) as patch_persisted_grade :
104- patch_persisted_grade .return_value = Mock (percent = 1.0 )
105- assert _cert_info (user , enrollment , cert_status ) == {'status' : 'generating' , 'show_survey_button' : True ,
106- 'survey_url' : survey_url , 'grade' : '1.0' ,
107- 'mode' : 'honor' , 'linked_in_url' : None ,
108- 'can_unenroll' : False }
117+ cert_status = {'status' : 'generating' , 'grade' : '0.67' , 'mode' : 'honor' , 'uuid' : None }
118+ with patch ('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read' ) as patch_persisted_grade :
119+ patch_persisted_grade .return_value = Mock (percent = 1.0 )
120+ assert _cert_info (user , enrollment , cert_status ) == {
121+ 'status' : 'generating' ,
122+ 'show_survey_button' : True ,
123+ 'survey_url' : survey_url ,
124+ 'grade' : '1.0' ,
125+ 'mode' : 'honor' ,
126+ 'linked_in_url' : None ,
127+ 'can_unenroll' : False ,
128+ }
129+
130+ cert_status = {'status' : 'generating' , 'grade' : '0.67' , 'mode' : 'honor' , 'uuid' : None }
131+ assert _cert_info (user , enrollment , cert_status ) == {
132+ 'status' : 'generating' ,
133+ 'show_survey_button' : True ,
134+ 'survey_url' : survey_url ,
135+ 'grade' : '0.67' ,
136+ 'mode' : 'honor' ,
137+ 'linked_in_url' : None ,
138+ 'can_unenroll' : False ,
139+ }
109140
110- cert_status = {'status' : 'generating' , 'grade' : '0.67' , 'mode' : 'honor' , 'uuid' : None }
111- assert _cert_info (user , enrollment , cert_status ) == {'status' : 'generating' , 'show_survey_button' : True ,
112- 'survey_url' : survey_url , 'grade' : '0.67' , 'mode' : 'honor' ,
113- 'linked_in_url' : None , 'can_unenroll' : False }
141+ cert_status = {
142+ 'status' : 'downloadable' ,
143+ 'grade' : '0.67' ,
144+ 'download_url' : cert .download_url ,
145+ 'mode' : 'honor' ,
146+ 'uuid' : 'fakeuuidbutitsfine' ,
147+ }
148+ assert _cert_info (user , enrollment , cert_status ) == {
149+ 'status' : 'downloadable' ,
150+ 'download_url' : cert .download_url ,
151+ 'show_survey_button' : True ,
152+ 'survey_url' : survey_url ,
153+ 'grade' : '0.67' ,
154+ 'mode' : 'honor' ,
155+ 'linked_in_url' : None ,
156+ 'can_unenroll' : False ,
157+ }
114158
115- cert_status = {
116- 'status' : 'downloadable' ,
117- 'grade' : '0.67' ,
118- 'download_url' : cert .download_url ,
119- 'mode' : 'honor' ,
120- 'uuid' : 'fakeuuidbutitsfine' ,
121- }
122- assert _cert_info (user , enrollment , cert_status ) == {'status' : 'downloadable' ,
123- 'download_url' : cert .download_url ,
124- 'show_survey_button' : True , 'survey_url' : survey_url ,
125- 'grade' : '0.67' , 'mode' : 'honor' , 'linked_in_url' : None ,
126- 'can_unenroll' : False }
159+ cert_status = {
160+ 'status' : 'notpassing' ,
161+ 'grade' : '0.67' ,
162+ 'download_url' : cert .download_url ,
163+ 'mode' : 'honor' ,
164+ 'uuid' : 'fakeuuidbutitsfine' ,
165+ }
166+ assert _cert_info (user , enrollment , cert_status ) == {
167+ 'status' : 'notpassing' ,
168+ 'show_survey_button' : True ,
169+ 'survey_url' : survey_url ,
170+ 'grade' : '0.67' ,
171+ 'mode' : 'honor' ,
172+ 'linked_in_url' : None ,
173+ 'can_unenroll' : True ,
174+ }
127175
128- cert_status = {
129- 'status' : 'notpassing' , 'grade' : '0.67' ,
130- 'download_url' : cert .download_url ,
131- 'mode' : 'honor' ,
132- 'uuid' : 'fakeuuidbutitsfine' ,
133- }
134- assert _cert_info (user , enrollment , cert_status ) == {'status' : 'notpassing' , 'show_survey_button' : True ,
135- 'survey_url' : survey_url , 'grade' : '0.67' , 'mode' : 'honor' ,
136- 'linked_in_url' : None , 'can_unenroll' : True }
137-
138- # Test a course that doesn't have a survey specified
139- course2 = CourseOverviewFactory .create (
140- end_of_course_survey_url = None ,
141- certificates_display_behavior = 'end' ,
142- )
143- enrollment2 = CourseEnrollmentFactory (user = user , course_id = course2 .id , mode = CourseMode .VERIFIED )
176+ # Test a course that doesn't have a survey specified
177+ course2 = CourseOverviewFactory .create (
178+ end_of_course_survey_url = None ,
179+ certificates_display_behavior = 'end' ,
180+ )
181+ enrollment2 = CourseEnrollmentFactory (user = user , course_id = course2 .id , mode = CourseMode .VERIFIED )
144182
145- cert_status = {
146- 'status' : 'notpassing' , 'grade' : '0.67' ,
147- 'download_url' : cert .download_url , 'mode' : 'honor' , 'uuid' : 'fakeuuidbutitsfine'
148- }
149- assert _cert_info (user , enrollment2 , cert_status ) == {'status' : 'notpassing' , 'show_survey_button' : False ,
150- 'grade' : '0.67' , 'mode' : 'honor' , 'linked_in_url' : None ,
151- 'can_unenroll' : True }
183+ cert_status = {
184+ 'status' : 'notpassing' , 'grade' : '0.67' ,
185+ 'download_url' : cert .download_url , 'mode' : 'honor' , 'uuid' : 'fakeuuidbutitsfine'
186+ }
187+ assert _cert_info (user , enrollment2 , cert_status ) == {
188+ 'status' : 'notpassing' ,
189+ 'show_survey_button' : False ,
190+ 'grade' : '0.67' ,
191+ 'mode' : 'honor' ,
192+ 'linked_in_url' : None ,
193+ 'can_unenroll' : True
194+ }
152195
153- course3 = CourseOverviewFactory .create (
154- end_of_course_survey_url = None ,
155- certificates_display_behavior = 'early_no_info' ,
156- )
157- enrollment3 = CourseEnrollmentFactory (user = user , course_id = course3 .id , mode = CourseMode .VERIFIED )
158- # test when the display is unavailable or notpassing, we get the correct results out
159- course2 .certificates_display_behavior = CertificatesDisplayBehaviors .EARLY_NO_INFO
160- cert_status = {'status' : 'unavailable' , 'mode' : 'honor' , 'uuid' : None }
161- assert _cert_info (user , enrollment3 , cert_status ) == {'status' : 'processing' , 'show_survey_button' : False ,
162- 'can_unenroll' : True }
196+ course3 = CourseOverviewFactory .create (
197+ end_of_course_survey_url = None ,
198+ certificates_display_behavior = 'early_no_info' ,
199+ )
200+ enrollment3 = CourseEnrollmentFactory (user = user , course_id = course3 .id , mode = CourseMode .VERIFIED )
201+ # test when the display is unavailable or notpassing, we get the correct results out
202+ course2 .certificates_display_behavior = CertificatesDisplayBehaviors .EARLY_NO_INFO
203+ cert_status = {'status' : 'unavailable' , 'mode' : 'honor' , 'uuid' : None }
204+ assert _cert_info (user , enrollment3 , cert_status ) == {
205+ 'status' : 'processing' ,
206+ 'show_survey_button' : False ,
207+ 'can_unenroll' : True
208+ }
163209
164- cert_status = {
165- 'status' : 'notpassing' , 'grade' : '0.67' ,
166- 'download_url' : cert .download_url ,
167- 'mode' : 'honor' ,
168- 'uuid' : 'fakeuuidbutitsfine'
169- }
170- assert _cert_info (user , enrollment3 , cert_status ) == {'status' : 'processing' , 'show_survey_button' : False ,
171- 'can_unenroll' : True }
210+ cert_status = {
211+ 'status' : 'notpassing' , 'grade' : '0.67' ,
212+ 'download_url' : cert .download_url ,
213+ 'mode' : 'honor' ,
214+ 'uuid' : 'fakeuuidbutitsfine'
215+ }
216+ assert _cert_info (user , enrollment3 , cert_status ) == {
217+ 'status' : 'processing' ,
218+ 'show_survey_button' : False ,
219+ 'can_unenroll' : True
220+ }
172221
173222 def test_cert_info_beta_tester (self ):
174223 user = UserFactory .create ()
@@ -192,15 +241,22 @@ def test_cert_info_beta_tester(self):
192241 'uuid' : 'blah' ,
193242 }
194243 with patch (BETA_TESTER_METHOD , return_value = False ):
195- assert _cert_info (user , enrollment , cert_status ) == {
196- 'status' : status ,
197- 'download_url' : cert .download_url ,
198- 'show_survey_button' : False ,
199- 'grade' : grade ,
200- 'mode' : mode ,
201- 'linked_in_url' : None ,
202- 'can_unenroll' : False
244+ # LinkedIn sharing disabled as we are expecting 'linked_in_url': None in our test case
245+ SITE_CONFIGURATION = {
246+ 'SOCIAL_SHARING_SETTINGS' : {
247+ 'CERTIFICATE_LINKEDIN' : False
248+ }
203249 }
250+ with with_site_configuration_context (configuration = SITE_CONFIGURATION ):
251+ assert _cert_info (user , enrollment , cert_status ) == {
252+ 'status' : status ,
253+ 'download_url' : cert .download_url ,
254+ 'show_survey_button' : False ,
255+ 'grade' : grade ,
256+ 'mode' : mode ,
257+ 'linked_in_url' : None ,
258+ 'can_unenroll' : False
259+ }
204260
205261 with patch (BETA_TESTER_METHOD , return_value = True ):
206262 assert _cert_info (user , enrollment , cert_status ) == {
@@ -397,7 +453,16 @@ def test_linked_in_add_to_profile_btn_not_appearing_without_config(self):
397453 grade = '67' ,
398454 download_url = download_url
399455 )
400- response = self .client .get (reverse ('dashboard' ))
456+ # LinkedIn sharing disabled
457+ # When CERTIFICATE_LINKEDIN is set to False in site configuration,
458+ # the LinkedIn "Add to Profile" button should not be visible to users
459+ SITE_CONFIGURATION = {
460+ 'SOCIAL_SHARING_SETTINGS' : {
461+ 'CERTIFICATE_LINKEDIN' : False
462+ }
463+ }
464+ with with_site_configuration_context (configuration = SITE_CONFIGURATION ):
465+ response = self .client .get (reverse ('dashboard' ))
401466
402467 assert response .status_code == 200
403468 self .assertNotContains (response , 'Add Certificate to LinkedIn' )
@@ -435,7 +500,16 @@ def test_linked_in_add_to_profile_btn_with_certificate(self):
435500 grade = '67' ,
436501 download_url = 'https://www.edx.org'
437502 )
438- response = self .client .get (reverse ('dashboard' ))
503+ # LinkedIn sharing disabled
504+ # When CERTIFICATE_LINKEDIN is set to False in site configuration,
505+ # the LinkedIn "Add to Profile" button should not be visible to users
506+ SITE_CONFIGURATION = {
507+ 'SOCIAL_SHARING_SETTINGS' : {
508+ 'CERTIFICATE_LINKEDIN' : True
509+ }
510+ }
511+ with with_site_configuration_context (configuration = SITE_CONFIGURATION ):
512+ response = self .client .get (reverse ('dashboard' ))
439513
440514 assert response .status_code == 200
441515 self .assertContains (response , 'Add Certificate to LinkedIn' )
0 commit comments