Example #1
0
 def test_external_link_with_background_img(self):
     s = ('<a href="https://somewhere/foo"><span>'
          '<div style="background-image: url(\'some.png\')"></div>'
          '</span></a>')
     output = parse_links(s)
     self.assertIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #2
0
 def test_rich_text_links_get_expanded(self):
     page = CFGOVPage(title='foo bar', slug='foo-bar')
     publish_page(page)
     link = f'<body><a id="{page.id}" linktype="page">foo bar</a></body>'
     output = parse_links(link)
     self.assertEqual('<body><a href="/foo-bar/">foo bar</a></body>',
                      output)
Example #3
0
    def test_with_svg_not_at_the_end_still_gets_svg(self):
        s = ('<a href="https://external.gov">'
             '<span><svg>something</svg> Text after icon</span>'
             '</a>')

        output = parse_links(s)
        soup = BeautifulSoup(output, 'html.parser')
        self.assertEqual(len(soup.find_all('svg')), 2)
Example #4
0
 def test_files_get_download_icon(self):
     file_types = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'csv', 'zip']
     for file_type in file_types:
         link = '<a href="/something.{}">link</a>'.format(
             file_type
         ).encode('utf-8')
         output = parse_links(link)
         self.assertIn(b'cf-icon-svg', output)
Example #5
0
 def test_external_link_outside_body_with_attributes(self):
     s = '''
     <a href="https://somewhere/foo">Link</a>
     <body class="test">
     </body>
     '''
     output = parse_links(s)
     self.assertNotIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #6
0
 def test_external_link_with_attribute(self):
     s = '''
     <body>
         <a href="https://somewhere" data-thing="something">Link</a>
     </body>
     '''
     output = parse_links(s)
     self.assertIn('external-site', output)
     self.assertIn('cf-icon-svg', output)
Example #7
0
 def test_multiline_external_gov_link(self):
     s = '''<a class="m-list_link a-link"
     href="https://usa.gov/">
     <span>
     USA
     .gov</span>
     </a>
     '''
     output = parse_links(s)
     self.assertIn('cf-icon-svg', output)
Example #8
0
 def test_internal_link(self):
     """Internal links get neither icon nor redirect."""
     link = '''
     <body>
         <a href="https://www.consumerfinance.gov/foo">cfpb link</a>
     </body>
     '''
     output = parse_links(link)
     self.assertNotIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #9
0
 def test_multiple_links(self):
     s = '''
     <body>
         <a href="https://first.com">one</a>
         <a href="https://second.com">two</a>
     </body>
     '''
     output = parse_links(s)
     soup = BeautifulSoup(output, 'html.parser')
     self.assertEqual(len(soup.find_all('a')), 2)
Example #10
0
 def test_external_link_with_img(self):
     s = '<body><a href="https://somewhere"><img src="some.png"></a></body>'
     output = parse_links(s)
     self.assertIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #11
0
 def test_external_link_with_header(self):
     s = '<body><a href="https://somewhere"><h3>Header</h3></a></body>'
     output = parse_links(s)
     self.assertIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #12
0
 def test_different_case_pdf_link_gets_download_icon(self):
     link = '<a href="/something.PDF">link</a>'
     output = parse_links(link)
     self.assertIn('cf-icon-svg', output)
Example #13
0
 def check_after_parse_links_has_a_single_svg(self, s):
     output = parse_links(s)
     soup = BeautifulSoup(output, 'html.parser')
     self.assertEqual(len(soup.find_all('svg')), 1)
Example #14
0
 def test_relative_link_remains_unmodified(self):
     self.assertEqual(
         parse_links('<body><a href="/something">text</a></body>'),
         '<body><a href="/something">text</a></body>')
Example #15
0
 def test_relative_link_remains_unmodified(self):
     self.assertEqual(
         parse_links('<a href="/something">text</a>'),
         '<a href="/something">text</a>'
     )
Example #16
0
 def test_rich_text_links_get_expanded(self):
     page = CFGOVPage(title='foo bar', slug='foo-bar')
     publish_page(page)
     link = b'<a id="{}" linktype="page">foo bar</a>'.format(page.id)
     output = parse_links(link)
     self.assertEqual(b'<a href="/foo-bar/">foo bar</a>', output)
Example #17
0
 def test_different_case_pdf_link_gets_download_icon(self):
     link = '<body><a href="/something.PDF">link</a></body>'
     output = parse_links(link)
     self.assertIn('cf-icon-svg', output)
Example #18
0
 def test_internal_link(self):
     """Internal links get neither icon nor redirect."""
     link = '<a href="https://www.consumerfinance.gov/foo">cfpb link</a>'
     output = parse_links(link)
     self.assertNotIn('external-site', output)
     self.assertNotIn('cf-icon-svg', output)
Example #19
0
 def test_non_gov_link(self):
     """Non gov links get external link icon and redirect."""
     link = '<body><a href="https://google.com">external link</a></body>'
     output = parse_links(link)
     self.assertIn('external-site', output)
     self.assertIn('cf-icon-svg', output)
Example #20
0
 def test_gov_link(self):
     """Gov links get external link icon but not redirect."""
     link = '<a href="https://www.fdic.gov/bar">gov link</a>'
     output = parse_links(link)
     self.assertIn('cf-icon-svg', output)
Example #21
0
 def test_non_gov_link(self):
     """Non gov links get external link icon and redirect."""
     link = '<a href="https://wwww.google.com">external link</a>'
     output = parse_links(link)
     self.assertIn('external-site', output)
     self.assertIn('cf-icon-svg', output)
Example #22
0
 def test_works_properly_on_bytestrings(self):
     self.assertEqual(
         parse_links(b'<a href="/something">text</a>'),
         '<a href="/something">text</a>'
     )
Example #23
0
 def check_after_parse_links_has_this_many_svgs(self, count, s):
     output = parse_links(s)
     soup = BeautifulSoup(output, 'html.parser')
     self.assertEqual(len(soup.find_all('svg')), count)
Example #24
0
 def test_rich_text_links_get_expanded(self):
     page = CFGOVPage(title='foo bar', slug='foo-bar')
     publish_page(page)
     link = '<a id="{}" linktype="page">foo bar</a>'.format(page.id)
     output = parse_links(link)
     self.assertEqual('<a href="/foo-bar/">foo bar</a>', output)
Example #25
0
 def test_in_page_anchor_links_have_current_path_stripped(self):
     s = '<body><a href="/foo/bar/#anchor">Anchor</a></body>'
     output = parse_links(s, request_path='/foo/bar/')
     self.assertNotIn('/foo/bar/', output)
     self.assertIn('href="#anchor"', output)
Example #26
0
 def test_non_default_encoding(self):
     s = '<body><a href="/something">哈哈</a></body>'
     encoding = 'gb2312'
     parsed = parse_links(s.encode(encoding), encoding=encoding)
     self.assertEqual(parsed, s)
Example #27
0
 def test_works_properly_on_bytestrings(self):
     self.assertEqual(
         parse_links(b'<body><a href="/something">text</a></body>'),
         '<body><a href="/something">text</a></body>')
Example #28
0
 def test_non_default_encoding(self):
     s = '<a href="/something">哈哈</a>'
     encoding = 'gb2312'
     parsed = parse_links(s.encode(encoding), encoding=encoding)
     self.assertEqual(parsed, s)
Example #29
0
 def test_gov_link(self):
     """Gov links get external link icon but not redirect."""
     link = '<body><a href="https://www.fdic.gov/bar">gov link</a></body>'
     output = parse_links(link)
     self.assertIn('cf-icon-svg', output)
Example #30
0
 def test_files_get_download_icon(self):
     file_types = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'csv', 'zip']
     for file_type in file_types:
         link = f'<body><a href="/something.{file_type}">link</a></body>'
         output = parse_links(link)
         self.assertIn('cf-icon-svg', output)