def test_multiple_links_with_one_not_supported(self):
     html = (
         '<img src="http://some.url/img.png">'
         '<img src="http://other.url/img.png">'
     )
     url_mappings = [('http://some.url/', 'https://some.url/')]
     with self.assertRaises(ValueError):
         convert_http_image_links(html, url_mappings)
Ejemplo n.º 2
0
 def test_multiple_links_with_one_not_supported(self):
     html = (
         '<img src="http://some.url/img.png">'
         '<img src="http://other.url/img.png">'
     )
     url_mappings = [('http://some.url/', 'https://some.url/')]
     with self.assertRaises(ValueError):
         convert_http_image_links(html, url_mappings)
 def test_link_supported(self):
     html = '<img src="http://some.url/img.png">'
     url_mappings = [('http://some.url/', 'https://other.url/')]
     self.assertEqual(
         convert_http_image_links(html, url_mappings),
         '<img src="https://other.url/img.png">'
     )
Ejemplo n.º 4
0
 def test_link_supported(self):
     html = '<img src="http://some.url/img.png">'
     url_mappings = [('http://some.url/', 'https://other.url/')]
     self.assertEqual(
         convert_http_image_links(html, url_mappings),
         '<img src="https://other.url/img.png">'
     )
Ejemplo n.º 5
0
def process_external_link_field(field):
    # Convert any HTTP image links to S3 to HTTPS.
    # noop if AWS_STORAGE_BUCKET_NAME is not set
    if getattr(settings, 'AWS_STORAGE_BUCKET_NAME', None):
        field = convert_http_image_links(field, [
            (http_s3_url_prefix(), https_s3_url_prefix()),
        ])

        # Add appropriate markup to all links in HTML.
        field = parse_links(field).encode(formatter=None)

    return field
 def test_multiple_links(self):
     html = ('<img src="http://bucket.name/img.png">'
             '<div>Other text</div>'
             '<img src="http://www.com/wp-content/uploads/img2.png">'
             '<img src="/relative/img3.png">')
     url_mappings = [
         ('http://bucket.name/', 'https://bucket.name/'),
         ('http://www.com/wp-content/uploads/', 'https://other.site/'),
     ]
     self.assertEqual(convert_http_image_links(html, url_mappings),
                      ('<img src="https://bucket.name/img.png">'
                       '<div>Other text</div>'
                       '<img src="https://other.site/img2.png">'
                       '<img src="/relative/img3.png">'))
 def test_multiple_links(self):
     html = (
         '<img src="http://bucket.name/img.png">'
         '<div>Other text</div>'
         '<img src="http://www.com/wp-content/uploads/img2.png">'
         '<img src="/relative/img3.png">'
     )
     url_mappings = [
         ('http://bucket.name/', 'https://bucket.name/'),
         ('http://www.com/wp-content/uploads/', 'https://other.site/'),
     ]
     self.assertEqual(
         convert_http_image_links(html, url_mappings),
         (
             '<img src="https://bucket.name/img.png">'
             '<div>Other text</div>'
             '<img src="https://other.site/img2.png">'
             '<img src="/relative/img3.png">'
         )
     )
 def test_no_links(self):
     html = '<html><body><div>Hello</div></body></html>'
     self.assertEqual(
         convert_http_image_links(html, []),
         html
     )
 def test_url_not_in_image_tag(self):
     html = '<a href="http://bucket.name/img.png">'
     self.assertEqual(convert_http_image_links(html, []), html)
 def test_link_not_supported(self):
     html = '<img src="http://some.url/img.png">'
     url_mappings = [('http://other.url', 'https://other.url')]
     with self.assertRaises(ValueError):
         convert_http_image_links(html, url_mappings)
 def test_no_mappings(self):
     html = '<img src="http://some.url/img.png">'
     with self.assertRaises(ValueError):
         convert_http_image_links(html, [])
Ejemplo n.º 12
0
 def test_no_links(self):
     html = '<html><body><div>Hello</div></body></html>'
     self.assertEqual(convert_http_image_links(html, []), html)
Ejemplo n.º 13
0
 def test_url_not_in_image_tag(self):
     html = '<a href="http://bucket.name/img.png">'
     self.assertEqual(convert_http_image_links(html, []), html)
Ejemplo n.º 14
0
 def test_link_not_supported(self):
     html = '<img src="http://some.url/img.png">'
     url_mappings = [('http://other.url', 'https://other.url')]
     with self.assertRaises(ValueError):
         convert_http_image_links(html, url_mappings)
Ejemplo n.º 15
0
 def test_no_mappings(self):
     html = '<img src="http://some.url/img.png">'
     with self.assertRaises(ValueError):
         convert_http_image_links(html, [])