def test_no_size_querystring_when_size_undefined(): soup = bs4.BeautifulSoup(features="html.parser") url = ("//upload.wikimedia.org/wikipedia/commons/" "thumb/4/40/P_ps.png/35px-P_ps.png") tag = soup.new_tag("img", src=url) ImageParser.replace(tag) assert tag.attrs['src'].endswith(".png")
def test_append_size_querystring(): soup = bs4.BeautifulSoup(features="html.parser") url = ("//upload.wikimedia.org/wikipedia/commons/" "thumb/4/40/P_ps.png/35px-P_ps.png") tag = soup.new_tag("img", src=url, width='100px', height='50px') ImageParser.replace(tag) assert tag.attrs.get("width") is None assert tag.attrs.get("height") is None assert tag.attrs['src'].endswith("?s=100px-50px")
def _check(self, url, should_web, should_dsk): """Do proper checking.""" tag = self.soup.new_tag("img", src=url) dsk, web = ImageParser.replace(tag) self.assertEqual(web, should_web) self.assertEqual(dsk, should_dsk) self.assertEqual(tag.attrs["src"], '/images/' + should_dsk)