Beispiel #1
0
 def test_parses_html(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = ('<img src="http://example.net/images/hahafunny.jpg" />'
             '<img src="https://otherexample/moreserious.png" />'
             '<img src="//example.net/no_http.jpg" />'
             '<img src=" http://example.net/leading_space.jpg" />'
             '<img src=http://example.net/mising_quotes.jpg />'
             '<img src="ftp://example.net/ftp_image.jpg" />'
             '<img src="/images/hahafunny.jpg">')
     parsed = (
         '<img src="https://fakecdn.org/735030fa488e1866b4302ac611c075d541a'
         '773e3/687474703a2f2f6578616d706c652e6e65742f696d616765732f6861686'
         '166756e6e792e6a7067">'
         '<img src="https://fakecdn.org/c81915f5756fad02cfae7d07e359624dae8'
         '77667/68747470733a2f2f6f746865726578616d706c652f6d6f7265736572696'
         'f75732e706e67">'
         '<img src="https://fakecdn.org/1d5de168888358e62b7c2f850265c5bfb43'
         'e46c3/2f2f6578616d706c652e6e65742f6e6f5f687474702e6a7067">'
         '<img src="https://fakecdn.org/f4837f9cd17f391dd4c78e49f7b57934f69'
         '66f7c/20687474703a2f2f6578616d706c652e6e65742f6c656164696e675f737'
         '06163652e6a7067">'
         '<img src="https://fakecdn.org/d4ef06afe02debfdcbce1b1b078666e9187'
         '32793/687474703a2f2f6578616d706c652e6e65742f6d6973696e675f71756f7'
         '465732e6a7067">'
         '<img src="https://fakecdn.org/46bb6a3963ac29bd9c1587f2f533dad926c'
         '82330/6674703a2f2f6578616d706c652e6e65742f6674705f696d6167652e6a7'
         '067">'
         '<img src="https://fakecdn.org/17c855d7008b1307d277d725cb045b0fc0e'
         '23ea7/2f696d616765732f6861686166756e6e792e6a7067">')
     self.assertEqual(client.parse_html(html), parsed)
Beispiel #2
0
 def test_unmarkedup_text(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     text = """butts"""
     self.assertEqual(client.parse_html(text), text)
Beispiel #3
0
 def test_ignores_relative(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = """<p><img src="/images/hahafunny.jpg"></p>"""
     self.assertEqual(client.parse_html(html), html)
Beispiel #4
0
 def test_parses_html(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = """<img src="http://example.net/images/hahafunny.jpg" /><img src="https://otherexample/moreserious.png" />"""
     parsed = """<img src="https://fakecdn.org/735030fa488e1866b4302ac611c075d541a773e3/687474703a2f2f6578616d706c652e6e65742f696d616765732f6861686166756e6e792e6a7067">"""\
              """<img src="https://fakecdn.org/c81915f5756fad02cfae7d07e359624dae877667/68747470733a2f2f6f746865726578616d706c652f6d6f7265736572696f75732e706e67">"""
     self.assertEqual(client.parse_html(html), parsed)
Beispiel #5
0
 def test_unmarkedup_text(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     text = """butts"""
     self.assertEqual(client.parse_html(text), text)
Beispiel #6
0
 def test_ignores_already_hosted(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = '<p><img src="https://fakecdn.org/images/hahafunny.jpg"></p>'
     self.assertEqual(client.parse_html(html), html)
Beispiel #7
0
 def test_ignores_relative(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = """<p><img src="/images/hahafunny.jpg"></p>"""
     self.assertEqual(client.parse_html(html), html)
Beispiel #8
0
 def test_parses_html(self):
     client = CamoClient("https://fakecdn.org/", key="hello")
     html = """<img src="http://example.net/images/hahafunny.jpg" /><img src="https://otherexample/moreserious.png" />"""
     parsed = """<img src="https://fakecdn.org/735030fa488e1866b4302ac611c075d541a773e3/687474703a2f2f6578616d706c652e6e65742f696d616765732f6861686166756e6e792e6a7067">"""\
              """<img src="https://fakecdn.org/c81915f5756fad02cfae7d07e359624dae877667/68747470733a2f2f6f746865726578616d706c652f6d6f7265736572696f75732e706e67">"""
     self.assertEqual(client.parse_html(html), parsed)
Beispiel #9
0
 def test_parses_html_for_css_links(self):
     client = CamoClient("https://fakecdn.org/", key=b"hello")
     html = """<link rel="stylesheet" href="http://www.csszengarden.com/214/214.css" />"""
     parsed = """<link rel="stylesheet" href="https://fakecdn.org/0d5370557ac9428fdd6964cf0351b68690a88721/687474703a2f2f7777772e6373737a656e67617264656e2e636f6d2f3231342f3231342e637373">"""
     self.assertEqual(client.parse_html(html), parsed)