def test_html_to_atom_fetch_author(self): """Based on http://tantek.com/ . https://github.com/snarfed/granary/issues/98 https://github.com/kylewm/mf2util/issues/14 """ with self.assertRaises(AssertionError): # fetch_author requires url atom.html_to_atom("", fetch_author=True) html = u"""\ <body class="h-card vcard"> <img class="photo u-photo" src="photo.jpg" alt=""/> <a class="u-url u-uid" rel="author" href="/author"></a> <h1 class="p-name fn">Tantek Çelik</h1> <div class="h-feed section stream" id="updates"> <span class="p-name"></span><ol> <li class="h-entry hentry as-note"> <p class="p-name entry-title e-content entry-content article"> going to Homebrew Website Club </p></li> </ol></div></body> """ self.expect_requests_get( "https://my.site/author", html, headers=mox.IgnoreArg(), timeout=None, response_headers={"content-type": "text/html; charset=utf-8"}, ) self.mox.ReplayAll() got = atom.html_to_atom(html, "https://my.site/", fetch_author=True) self.assert_multiline_in( u"""\ <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>https://my.site/author</uri> <name>Tantek Çelik</name> </author> <link rel="alternate" href="https://my.site/author" type="text/html" /> <link rel="avatar" href="https://my.site/photo.jpg" /> <link rel="self" href="https://my.site/" type="application/atom+xml" /> <entry> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>https://my.site/author</uri> <name>Tantek Çelik</name> </author> """.encode( "utf-8" ), got.encode("utf-8"), )
def test_html_to_atom_fetch_author(self): """Based on http://tantek.com/ . https://github.com/snarfed/granary/issues/98 https://github.com/kylewm/mf2util/issues/14 """ with self.assertRaises(AssertionError): # fetch_author requires url atom.html_to_atom('', fetch_author=True) html = u"""\ <body class="h-card vcard"> <img class="photo u-photo" src="photo.jpg" alt=""/> <a class="u-url u-uid" rel="author" href="/author"></a> <h1 class="p-name fn">Tantek Çelik</h1> <div class="h-feed section stream" id="updates"> <span class="p-name"></span><ol> <li class="h-entry hentry as-note"> <p class="p-name entry-title e-content entry-content article"> going to Homebrew Website Club </p></li> </ol></div></body> """ self.expect_requests_get( 'https://my.site/author', html, headers=mox.IgnoreArg(), timeout=None, response_headers={'content-type': 'text/html; charset=utf-8'}) self.mox.ReplayAll() got = atom.html_to_atom(html, 'https://my.site/', fetch_author=True) self.assert_multiline_in(u"""\ <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>https://my.site/author</uri> <name>Tantek Çelik</name> </author> <link rel="alternate" href="https://my.site/" type="text/html" /> <link rel="alternate" href="https://my.site/author" type="text/html" /> <link rel="avatar" href="https://my.site/photo.jpg" /> <link rel="self" href="https://my.site/" type="application/atom+xml" /> <entry> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>https://my.site/author</uri> <name>Tantek Çelik</name> </author> """, got, ignore_blanks=True)
def test_html_to_atom_title_without_hfeed_name(self): self.assert_multiline_in("""\ <generator uri="https://granary.io/">granary</generator> <id>https://my.site/feed</id> <title>User feed for Unknown</title> """, atom.html_to_atom("""\ <div class="h-feed"> <span>unmarked feed title</span> <article class="h-entry"> <p class="e-content">entry content</p> </article> </div> """, 'https://my.site/feed'), ignore_blanks=True)
def test_html_to_atom_title_without_hfeed_name(self): self.assert_multiline_in("""\ <generator uri="https://granary.io/">granary</generator> <id>https://my.site/feed</id> <title>User feed for Unknown</title> """, atom.html_to_atom( """\ <div class="h-feed"> <span>unmarked feed title</span> <article class="h-entry"> <p class="e-content">entry content</p> </article> </div> """, 'https://my.site/feed'), ignore_blanks=True)
def test_html_to_atom(self): self.assert_multiline_equals( """\ <?xml version="1.0" encoding="UTF-8"?> <feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:base="https://my.site/"> <generator uri="https://github.com/snarfed/granary">granary</generator> <id>https://my.site/feed</id> <title>my title</title> <logo>http://my/picture</logo> <updated></updated> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>http://my/site</uri> <name>My Name</name> </author> <link rel="alternate" href="http://my/site" type="text/html" /> <link rel="avatar" href="http://my/picture" /> <link rel="self" href="https://my.site/feed" type="application/atom+xml" /> <entry> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>http://my/site</uri> <name>My Name</name> </author> <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> <id>http://my/post</id> <title>my content</title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> my content </div> </content> <link rel="alternate" type="text/html" href="http://my/post" /> <link rel="ostatus:conversation" href="http://my/post" /> <published></published> <updated></updated> <link rel="self" type="application/atom+xml" href="http://my/post" /> </entry> </feed> """, atom.html_to_atom( """\ <div class="h-feed"> <div class="p-author h-card"> <a href="http://my/site">My Name</a> <img src="http://my/picture" /> </div> <span class="p-name">my title</span> <article class="h-entry"> <a class="u-url" href="http://my/post" /> <div class="e-content">my content</div> </article> </div> """, 'https://my.site/feed'))
def test_html_to_atom(self): self.assert_multiline_equals("""\ <?xml version="1.0" encoding="UTF-8"?> <feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:base="https://my.site/"> <generator uri="https://granary.io/">granary</generator> <id>https://my.site/feed</id> <title>my title</title> <logo>http://my/picture</logo> <updated></updated> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>http://my/site</uri> <name>My Name</name> </author> <link rel="alternate" href="https://my.site/feed" type="text/html" /> <link rel="alternate" href="http://my/site" type="text/html" /> <link rel="avatar" href="http://my/picture" /> <link rel="self" href="https://my.site/feed" type="application/atom+xml" /> <entry> <author> <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type> <uri>http://my/site</uri> <name>My Name</name> </author> <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type> <id>http://my/post</id> <title>my content x y z </title> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> my content <pre> x y z </pre> </div> </content> <link rel="alternate" type="text/html" href="http://my/post" /> <link rel="ostatus:conversation" href="http://my/post" /> <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb> <published></published> <updated></updated> <link rel="self" type="application/atom+xml" href="http://my/post" /> </entry> </feed> """, atom.html_to_atom("""\ <div class="h-feed"> <div class="p-author h-card"> <a class="p-name" href="http://my/site">My Name</a> <img src="http://my/picture" /> </div> <span class="p-name">my title</span> <article class="h-entry"> <a class="u-url" href="http://my/post" /> <div class="e-content"> my content <pre> x y z </pre> </div> </article> </div> """, 'https://my.site/feed'), ignore_blanks=True)