def test_no_head(self):
    """Tests that the manifest link tag is added even with no head."""
    chrome_app_manifest = {}
    root_path = 'path'
    html = """\
<!DOCTYPE html>
<html>
 <body>
  <h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
 </body>
</html>"""
    soup = bs4.BeautifulSoup(html, 'html.parser')
    caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '')
    self.assertEqual(unicode(soup), """\
<!DOCTYPE html>

<html><head><meta charset="utf-8"/><link href="path/manifest.webmanifest"\
 rel="manifest"/></head>
<body>
<h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
</body>
</html>""")
  def test_no_duplicate_metas(self):
    """Tests that existing meta tags aren't duplicated."""
    chrome_app_manifest = {'description': 'a déscription'}
    root_path = 'path'
    html = """
<!DOCTYPE html>
<html>
 <head>
  <title>
   Hello Wó®ld
  </title>
  <meta name="description" content="tést description"/>
  <link href="styles/main.css" rel="stylesheet"/>
 </head>
 <body>
  <h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
 </body>
</html>"""
    soup = bs4.BeautifulSoup(html)
    caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '')
    metas = soup.findAll('meta', {'name': 'description'})
    self.assertEqual(len(metas), 1)
    self.assertEqual(metas[0]['content'], 'tést description')
Example #3
0
    def test_no_head(self):
        """Tests that the manifest link tag is added even with no head."""
        chrome_app_manifest = {}
        root_path = 'path'
        html = """\
<!DOCTYPE html>
<html>
 <body>
  <h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
 </body>
</html>"""
        soup = bs4.BeautifulSoup(html, 'html.parser')
        caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '')
        self.assertEqual(
            unicode(soup), """\
<!DOCTYPE html>

<html><head><meta charset="utf-8"/><link href="path/manifest.webmanifest"\
 rel="manifest"/></head>
<body>
<h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
</body>
</html>""")
 def test_meta_charset(self):
   """Tests that the meta charset tag is added and correct."""
   chrome_app_manifest = {}
   root_path = 'path'
   caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path, '')
   meta = self.soup.find('meta', charset='utf-8')
   self.assertIsNotNone(meta)
Example #5
0
    def test_no_duplicate_metas(self):
        """Tests that existing meta tags aren't duplicated."""
        chrome_app_manifest = {'description': 'a déscription'}
        root_path = 'path'
        html = """
<!DOCTYPE html>
<html>
 <head>
  <title>
   Hello Wó®ld
  </title>
  <meta name="description" content="tést description"/>
  <link href="styles/main.css" rel="stylesheet"/>
 </head>
 <body>
  <h1>
   Héllo, World! ÚÑÍ¢ÓÐÉ
  </h1>
 </body>
</html>"""
        soup = bs4.BeautifulSoup(html)
        caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '')
        metas = soup.findAll('meta', {'name': 'description'})
        self.assertEqual(len(metas), 1)
        self.assertEqual(metas[0]['content'], 'tést description')
 def test_meta_name(self):
   """Tests that the meta name tag is added and correct."""
   chrome_app_manifest = {'name': 'a náme'}
   root_path = 'path'
   caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path, '')
   meta = self.soup.find('meta', {'name': 'name'})
   self.assertIsNotNone(meta)
   self.assertEqual(meta['content'], chrome_app_manifest['name'])
Example #7
0
 def test_meta_charset(self):
     """Tests that the meta charset tag is added and correct."""
     chrome_app_manifest = {}
     root_path = 'path'
     caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path,
                                  '')
     meta = self.soup.find('meta', charset='utf-8')
     self.assertIsNotNone(meta)
 def test_manifest_link(self):
   """Tests that the manifest link tag is added and correct."""
   chrome_app_manifest = {}
   root_path = 'path'
   caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path, '')
   link = self.soup.find('link', rel='manifest')
   self.assertIsNotNone(link)
   self.assertEqual(link['href'],
                    os.path.join(root_path, 'manifest.webmanifest'))
Example #9
0
 def test_meta_name(self):
     """Tests that the meta name tag is added and correct."""
     chrome_app_manifest = {'name': 'a náme'}
     root_path = 'path'
     caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path,
                                  '')
     meta = self.soup.find('meta', {'name': 'name'})
     self.assertIsNotNone(meta)
     self.assertEqual(meta['content'], chrome_app_manifest['name'])
Example #10
0
 def test_manifest_link(self):
     """Tests that the manifest link tag is added and correct."""
     chrome_app_manifest = {}
     root_path = 'path'
     caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path,
                                  '')
     link = self.soup.find('link', rel='manifest')
     self.assertIsNotNone(link)
     self.assertEqual(link['href'],
                      os.path.join(root_path, 'manifest.webmanifest'))