def test_add_image(self): image_src = wikidata.add_image(fromstring("<div></div>")) self.assertEqual(image_src, None) html = u""" <div> <div id="P18"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P18"> image </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <a href="https://commons.wikimedia.org/wiki/File:image.png"> image.png </a> </div> </div> </div> </div> </div> </div> </div> """ html_etree = fromstring(html) image_src = wikidata.add_image(html_etree) self.assertEqual( image_src, "https://commons.wikimedia.org/wiki/Special:FilePath/image.png?width=500&height=400" ) html = u""" <div> <div id="P2910"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P2910"> icon </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <a href="https://commons.wikimedia.org/wiki/File:icon.png"> icon.png </a> </div> </div> </div> </div> </div> </div> <div id="P154"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P154"> logo </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <a href="https://commons.wikimedia.org/wiki/File:logo.png"> logo.png </a> </div> </div> </div> </div> </div> </div> </div> """ html_etree = fromstring(html) image_src = wikidata.add_image(html_etree) self.assertEqual( image_src, "https://commons.wikimedia.org/wiki/Special:FilePath/logo.png?width=500&height=400" )
def test_add_image(self): image_src = wikidata.add_image(fromstring("<div></div>")) self.assertEqual(image_src, None) html = u""" <div> <div id="P18"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P18"> image </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <div class="commons-media-caption"> <a href="https://commons.wikimedia.org/wiki/File:image.png">image.png</a> <br/>2,687 × 3,356; 1.22 MB </div> </div> </div> </div> </div> </div> </div> </div> """ html_etree = fromstring(html) image_src = wikidata.add_image(html_etree) self.assertEqual(image_src, "https://commons.wikimedia.org/wiki/Special:FilePath/image.png?width=500&height=400") html = u""" <div> <div id="P2910"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P2910"> icon </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <div class="commons-media-caption"> <a href="https://commons.wikimedia.org/wiki/File:icon.png">icon.png</a> <br/>671 × 671; 18 KB</div> </div> </div> </div> </div> </div> </div> </div> <div id="P154"> <div class="wikibase-statementgroupview-property-label"> <a href="/wiki/Property:P154"> logo </a> </div> <div class="wikibase-statementlistview"> <div class="wikibase-statementview listview-item"> <div class="wikibase-statementview-rankselector"> <span class="wikibase-rankselector-normal"></span> </div> <div class="wikibase-statementview-mainsnak"> <div> <div class="wikibase-snakview-value"> <div class="commons-media-caption"> <a href="https://commons.wikimedia.org/wiki/File:logo.png">logo.png</a> <br/>170 × 170; 1 KB </div> </div> </div> </div> </div> </div> </div> </div> """ html_etree = fromstring(html) image_src = wikidata.add_image(html_etree) self.assertEqual(image_src, "https://commons.wikimedia.org/wiki/Special:FilePath/logo.png?width=500&height=400")