def test_external_link(self): soup = BeautifulSoup( '<a href="https://wwww.google.com">external link/a>', 'html.parser') output = str(parse_links(soup)) self.assertIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_cfpb_link(self): soup = BeautifulSoup( '<a href="http://www.consumerfinance.gov/foo">cfpb link</a>', 'html.parser') output = str(parse_links(soup)) self.assertNotIn('external-site', output) self.assertNotIn('class="icon-link_text"', output)
def _process_data(field): if isinstance(field, basestring): field = parse_links(field).encode(formatter=None) elif isinstance(field, list): for i, value in enumerate(field): field[i] = _process_data(value) elif isinstance(field, dict): for key, value in field.iteritems(): field[key] = _process_data(value) return field
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_gov_link(self): soup = BeautifulSoup('<a href="http://www.fdic.gov/bar">gov link</a>', 'html.parser') output = str(parse_links(soup)) self.assertNotIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_cfpb_link(self): soup = BeautifulSoup('<a href="http://www.consumerfinance.gov/foo">cfpb link</a>', 'html.parser') output = str(parse_links(soup)) self.assertNotIn('external-site', output) self.assertNotIn('class="icon-link_text"', output)
def test_gov_link(self): link = '<a href="http://www.fdic.gov/bar">gov link</a>' output = str(parse_links(link)) self.assertNotIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_cfpb_link(self): link = '<a href="http://www.consumerfinance.gov/foo">cfpb link</a>' output = str(parse_links(link)) self.assertNotIn('external-site', output) self.assertNotIn('class="icon-link_text"', output)
def test_external_link(self): link = '<a href="https://wwww.google.com">external link/a>' output = str(parse_links(link)) self.assertIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_gov_link(self): link = '<a href="http://www.fdic.gov/bar">gov link</a>' output = str(parse_links(link)) self.assertNotIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_external_link(self): link = '<a href="https://wwww.google.com">external link/a>' output = str(parse_links(link)) self.assertIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_different_case_pdf_link_gets_download_icon(self): link = '<a href="/something.PDF">link</a>' parsed = str(parse_links(link)) self.assertIn('cf-icon-download', parsed)
def test_parse_links_returns_beautiful_soup(self): self.assertIsInstance( parse_links('<a href="/something">text</a>'), BeautifulSoup )
def test_gov_link(self): soup = BeautifulSoup('<a href="http://www.fdic.gov/bar">gov link</a>', 'html.parser') output = str(parse_links(soup)) self.assertNotIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_external_link(self): soup = BeautifulSoup('<a href="https://wwww.google.com">external link/a>', 'html.parser') output = str(parse_links(soup)) self.assertIn('external-site', output) self.assertIn('class="icon-link_text"', output)
def test_cfpb_link(self): link = '<a href="http://www.consumerfinance.gov/foo">cfpb link</a>' output = str(parse_links(link)) self.assertNotIn('external-site', output) self.assertNotIn('class="icon-link_text"', output)
def test_pdf_link_gets_download_icon(self): link = '<a href="/something.pdf">link</a>' parsed = str(parse_links(link)) self.assertIn('cf-icon-svg', parsed)