@@ -233,12 +233,77 @@ def test_add_html_enhancements_to_file_with_open_graph(
233233 <link href="https://www.fakesite.com/fake-title.html" rel="canonical"/>
234234<script type="application/ld+json">{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "Fake Site Name", "item": "https://www.fakesite.com"}, {"@type": "ListItem", "position": 2, "name": "Fake_file", "item": "https://www.fakesite.com/fake_file.html"}]}</script>
235235<script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article", "author": {"@type": "Person", "name": "Fake author"}, "publisher": {"@type": "Organization", "name": "Fake Site Name", "logo": {"@type": "ImageObject", "url": "https://www.fakesite.com/fake-logo.jpg"}}, "headline": "Fake Title", "about": "Fake category", "datePublished": "2019-04-03 23:49"}</script>
236+ <meta content="Fake Site Name" property="og:site_name"/>
236237<meta content="https://www.fakesite.com/fake-title.html" property="og:url"/>
237238<meta content="website" property="og:type"/>
238239<meta content="OG Title" property="og:title"/>
239240<meta content="OG Description" property="og:description"/>
240241<meta content="https://www.fakesite.com/og-image.jpg" property="og:image"/>
241242<meta content="fr_FR" property="og:locale"/>
243+ </head>
244+ <body>
245+ <h1>Fake content title</h1>
246+ <p>Fake content 🙃</p>
247+ <a href="https://www.fakesite.com">Fake internal link</a>
248+ <p>Fake content with <code>inline code</code></p>
249+ <p>Fake content with "<a href="https://www.fakesite.com">Fake inline internal link</a>"</p>
250+ </body>
251+ </html>"""
252+ )
253+
254+ def test_add_html_enhancements_to_file_with_open_graph_using_summary_for_description (
255+ self , fake_article , fake_seo_enhancer
256+ ):
257+ """
258+ Test if add_html_to_file with open_graph setting
259+ adds Open Graph tags to HTML files.
260+ """
261+
262+ # Remove higher priority values for the og:description tag to force the use of
263+ # the summary from article description.
264+ del fake_article .metadata ["og_description" ]
265+ del fake_article .description
266+
267+ path = "fake_output/fake_file.html"
268+ fake_html_enhancements = fake_seo_enhancer .launch_html_enhancer (
269+ file = fake_article ,
270+ output_path = "fake_output" ,
271+ path = path ,
272+ open_graph = True ,
273+ )
274+
275+ with patch (
276+ "seo.seo_enhancer.open" , mock_open (read_data = fake_article .content )
277+ ) as mocked_open :
278+ mocked_file_handle = mocked_open .return_value
279+
280+ fake_seo_enhancer .add_html_to_file (
281+ enhancements = fake_html_enhancements , path = path
282+ )
283+ assert len (mocked_open .call_args_list ) == 2
284+ mocked_file_handle .read .assert_called_once ()
285+ mocked_file_handle .write .assert_called_once ()
286+
287+ write_args , _ = mocked_file_handle .write .call_args_list [0 ]
288+ fake_html_content = write_args [0 ]
289+
290+ # The og:description tag should now contain "Fake summary".
291+ assert (
292+ fake_html_content
293+ == """<html>
294+ <head>
295+ <title>Fake Title</title>
296+ <meta content="Fake description" name="description"/>
297+ <link href="https://www.fakesite.com/fake-title.html" rel="canonical"/>
298+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "Fake Site Name", "item": "https://www.fakesite.com"}, {"@type": "ListItem", "position": 2, "name": "Fake_file", "item": "https://www.fakesite.com/fake_file.html"}]}</script>
299+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article", "author": {"@type": "Person", "name": "Fake author"}, "publisher": {"@type": "Organization", "name": "Fake Site Name", "logo": {"@type": "ImageObject", "url": "https://www.fakesite.com/fake-logo.jpg"}}, "headline": "Fake Title", "about": "Fake category", "datePublished": "2019-04-03 23:49"}</script>
300+ <meta content="Fake Site Name" property="og:site_name"/>
301+ <meta content="https://www.fakesite.com/fake-title.html" property="og:url"/>
302+ <meta content="website" property="og:type"/>
303+ <meta content="OG Title" property="og:title"/>
304+ <meta content="Fake summary" property="og:description"/>
305+ <meta content="https://www.fakesite.com/og-image.jpg" property="og:image"/>
306+ <meta content="fr_FR" property="og:locale"/>
242307</head>
243308 <body>
244309 <h1>Fake content title</h1>
@@ -295,6 +360,7 @@ def test_add_html_enhancements_to_file_with_twitter_cards(
295360<script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article", "author": {"@type": "Person", "name": "Fake author"}, "publisher": {"@type": "Organization", "name": "Fake Site Name", "logo": {"@type": "ImageObject", "url": "https://www.fakesite.com/fake-logo.jpg"}}, "headline": "Fake Title", "about": "Fake category", "datePublished": "2019-04-03 23:49"}</script>
296361<meta content="summary" name="twitter:card"/>
297362<meta content="@TestTWCards" name="twitter:site"/>
363+ <meta content="Fake Site Name" property="og:site_name"/>
298364<meta content="https://www.fakesite.com/fake-title.html" property="og:url"/>
299365<meta content="website" property="og:type"/>
300366<meta content="OG Title" property="og:title"/>
0 commit comments