|
49 | 49 | ) |
50 | 50 | from openedx.core.djangolib.js_utils import js_escaped_string |
51 | 51 | from openedx.core.djangolib.testing.utils import CacheIsolationTestCase |
| 52 | +from openedx.core.lib.courses import course_image_url |
52 | 53 | from openedx.core.lib.tests.assertions.events import assert_event_matches |
53 | 54 | from openedx.features.name_affirmation_api.utils import get_name_affirmation_service |
54 | 55 | from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order |
@@ -352,6 +353,68 @@ def test_linkedin_share_url_site(self): |
352 | 353 | js_escaped_string(self.linkedin_url.format(params=urlencode(params))), |
353 | 354 | ) |
354 | 355 |
|
| 356 | + @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { |
| 357 | + "CERTIFICATE_FACEBOOK": True, |
| 358 | + "CERTIFICATE_FACEBOOK_TEXT": "test FB text" |
| 359 | + }) |
| 360 | + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) |
| 361 | + def test_render_certificate_html_view_with_facebook_meta_tags(self): |
| 362 | + """ |
| 363 | + Test view html certificate if share to FB is enabled. |
| 364 | + If 'facebook_share_enabled=True', <meta> tags with property="og:..." |
| 365 | + must be enabled to pass parameters to FB. |
| 366 | + """ |
| 367 | + self._add_course_certificates(count=1, signatory_count=1, is_active=True) |
| 368 | + self.course.cert_html_view_enabled = True |
| 369 | + self.course.save() |
| 370 | + self.update_course(self.course, self.user.id) |
| 371 | + test_url = get_certificate_url( |
| 372 | + user_id=self.user.id, |
| 373 | + course_id=str(self.course.id), |
| 374 | + uuid=self.cert.verify_uuid |
| 375 | + ) |
| 376 | + platform_name = settings.PLATFORM_NAME |
| 377 | + share_url = f'http://testserver{test_url}' |
| 378 | + full_course_image_url = f'http://testserver{course_image_url(self.course)}' |
| 379 | + document_title = f'{self.course.org} {self.course.number} Certificate | {platform_name}' |
| 380 | + response = self.client.get(test_url) |
| 381 | + |
| 382 | + assert response.status_code == 200 |
| 383 | + self.assertContains(response, f'<meta property="og:url" content="{share_url}" />') |
| 384 | + self.assertContains(response, f'<meta property="og:title" content="{document_title}" />') |
| 385 | + self.assertContains(response, '<meta property="og:type" content="image/png" />') |
| 386 | + self.assertContains(response, f'<meta property="og:image" content="{full_course_image_url}" />') |
| 387 | + self.assertContains(response, '<meta property="og:description" content="test FB text" />') |
| 388 | + |
| 389 | + @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { |
| 390 | + "CERTIFICATE_FACEBOOK": False, |
| 391 | + }) |
| 392 | + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) |
| 393 | + def test_render_certificate_html_view_without_facebook_meta_tags(self): |
| 394 | + """ |
| 395 | + Test view html certificate if share to FB is disabled. |
| 396 | + If 'facebook_share_enabled=False', html certificate view |
| 397 | + should not contain <meta> tags with parameters property="og:..." |
| 398 | + """ |
| 399 | + self._add_course_certificates(count=1, signatory_count=1, is_active=True) |
| 400 | + self.course.cert_html_view_enabled = True |
| 401 | + self.course.save() |
| 402 | + self.update_course(self.course, self.user.id) |
| 403 | + |
| 404 | + test_url = get_certificate_url( |
| 405 | + user_id=self.user.id, |
| 406 | + course_id=str(self.course.id), |
| 407 | + uuid=self.cert.verify_uuid |
| 408 | + ) |
| 409 | + response = self.client.get(test_url) |
| 410 | + |
| 411 | + assert response.status_code == 200 |
| 412 | + self.assertNotContains(response, '<meta property="og:url" ') |
| 413 | + self.assertNotContains(response, '<meta property="og:title" ') |
| 414 | + self.assertNotContains(response, '<meta property="og:type" content="image/png" />') |
| 415 | + self.assertNotContains(response, '<meta property="og:image" ') |
| 416 | + self.assertNotContains(response, '<meta property="og:description" ') |
| 417 | + |
355 | 418 | @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) |
356 | 419 | @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", {"CERTIFICATE_FACEBOOK": True}) |
357 | 420 | @with_site_configuration( |
|
0 commit comments