Skip to content

Commit 90f99b8

Browse files
authored
feat: add Open Graph sharing metadata to program certs (openedx#2858)
* feat: add Open Graph sharing metadata to program certs Adding Open Graph sharing metadata deprogram certificates so they look good on social media. FIXES: APER-3403
1 parent cb9127e commit 90f99b8

File tree

12 files changed

+1040
-2
lines changed

12 files changed

+1040
-2
lines changed

credentials/apps/credentials/tests/test_views.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ def test_sharing_bar_with_staff_user(self):
150150

151151
self.assertContains(response, "Print or share your certificate")
152152

153+
@responses.activate
154+
def test_open_graph_metadata(self):
155+
"""Verify that the anonymous view contains OpenGraph metadata."""
156+
self.client.logout()
157+
response = self._render_user_credential()
158+
159+
self.assertContains(response, "og:url")
160+
self.assertContains(response, "og:title")
161+
self.assertContains(response, "og:description")
162+
self.assertContains(response, '"og:type" content="image/png"')
163+
self.assertContains(response, self.user_credential.get_absolute_url())
164+
self.assertContains(response, "I completed a course at ")
165+
153166
@responses.activate
154167
def test_awarded_with_logged_in_user(self):
155168
"""Verify that the view renders awarded certificates with sharing bar."""
@@ -160,7 +173,7 @@ def test_awarded_with_logged_in_user(self):
160173
self.assertContains(response, "Print or share your certificate")
161174
self.assertContains(response, "Print this certificate")
162175

163-
self.assertContains(response=response, text=self.PROGRAM_NAME, count=2)
176+
self.assertContains(response=response, text=self.PROGRAM_NAME, count=3)
164177
self.assertNotContains(response=response, text=self.CREDENTIAL_TITLE)
165178

166179
self.assertEqual(response_context_data["user_credential"], self.user_credential)
@@ -226,7 +239,7 @@ def test_awarded_with_custom_title(self):
226239

227240
self.assertContains(response, "Print or share your certificate")
228241
self.assertNotContains(response=response, text=self.PROGRAM_NAME)
229-
self.assertContains(response=response, text=self.CREDENTIAL_TITLE, count=2)
242+
self.assertContains(response=response, text=self.CREDENTIAL_TITLE, count=3)
230243

231244
def test_revoked(self):
232245
"""Verify that the view returns 404 when the uuid is valid but certificate status

credentials/apps/credentials/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def get_context_data(self, **kwargs):
188188
"program_name": program_details.title,
189189
"credential_title": program_details.credential_title,
190190
"org_name_string": org_name_string,
191+
"share_url": self.request.build_absolute_uri(),
192+
"share_image_url": program_details.organizations[0].certificate_logo_image_url,
193+
"share_text": _("I completed a course at {platform_name}.").format(
194+
platform_name=self.site_configuration.platform_name
195+
),
191196
}
192197
)
193198
if program_details.hours_of_effort:
420 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)