OLD | NEW |
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # Copyright 2016 Google Inc. All Rights Reserved. | 4 # Copyright 2016 Google Inc. All Rights Reserved. |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 440 |
441 def test_meta_name(self): | 441 def test_meta_name(self): |
442 """Tests that the meta name tag is added and correct.""" | 442 """Tests that the meta name tag is added and correct.""" |
443 chrome_app_manifest = {'name': 'a náme'} | 443 chrome_app_manifest = {'name': 'a náme'} |
444 root_path = 'path' | 444 root_path = 'path' |
445 caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path, '') | 445 caterpillar.inject_misc_tags(self.soup, chrome_app_manifest, root_path, '') |
446 meta = self.soup.find('meta', {'name': 'name'}) | 446 meta = self.soup.find('meta', {'name': 'name'}) |
447 self.assertIsNotNone(meta) | 447 self.assertIsNotNone(meta) |
448 self.assertEqual(meta['content'], chrome_app_manifest['name']) | 448 self.assertEqual(meta['content'], chrome_app_manifest['name']) |
449 | 449 |
| 450 def test_no_head(self): |
| 451 """Tests that the manifest link tag is added even with no head.""" |
| 452 chrome_app_manifest = {} |
| 453 root_path = 'path' |
| 454 html = """\ |
| 455 <!DOCTYPE html> |
| 456 <html> |
| 457 <body> |
| 458 <h1> |
| 459 Héllo, World! ÚÑÍ¢ÓÐÉ |
| 460 </h1> |
| 461 </body> |
| 462 </html>""" |
| 463 soup = bs4.BeautifulSoup(html, 'html.parser') |
| 464 caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '') |
| 465 self.assertEqual(unicode(soup), """\ |
| 466 <!DOCTYPE html> |
| 467 |
| 468 <html><head><meta charset="utf-8"/><link href="path/manifest.webmanifest"\ |
| 469 rel="manifest"/></head> |
| 470 <body> |
| 471 <h1> |
| 472 Héllo, World! ÚÑÍ¢ÓÐÉ |
| 473 </h1> |
| 474 </body> |
| 475 </html>""") |
| 476 |
| 477 |
| 478 def test_no_head_or_html(self): |
| 479 """Tests that the manifest link tag is added with no head or html tags.""" |
| 480 chrome_app_manifest = {} |
| 481 root_path = 'path' |
| 482 html = """ |
| 483 <!DOCTYPE html> |
| 484 <body> |
| 485 <h1> |
| 486 Héllo, World! ÚÑÍ¢ÓÐÉ |
| 487 </h1> |
| 488 </body>""" |
| 489 soup = bs4.BeautifulSoup(html, 'html.parser') |
| 490 caterpillar.inject_misc_tags(soup, chrome_app_manifest, root_path, '') |
| 491 self.assertEqual(unicode(soup), """\ |
| 492 <head><meta charset="utf-8"/><link href="path/manifest.webmanifest"\ |
| 493 rel="manifest"/></head> |
| 494 <!DOCTYPE html> |
| 495 |
| 496 <body> |
| 497 <h1> |
| 498 Héllo, World! ÚÑÍ¢ÓÐÉ |
| 499 </h1> |
| 500 </body>""") |
| 501 |
450 | 502 |
451 class TestInsertTodosIntoFile(TestCaseWithTempDir): | 503 class TestInsertTodosIntoFile(TestCaseWithTempDir): |
452 """Tests insert_todos_into_file.""" | 504 """Tests insert_todos_into_file.""" |
453 | 505 |
454 def test_no_todos(self): | 506 def test_no_todos(self): |
455 """Tests that if there are no TODOs to add, nothing is changed.""" | 507 """Tests that if there are no TODOs to add, nothing is changed.""" |
456 js = """// héllo world | 508 js = """// héllo world |
457 unrelated.app.call();""" | 509 unrelated.app.call();""" |
458 filename = 'test.js' | 510 filename = 'test.js' |
459 filepath = os.path.join(self.temp_path, filename) | 511 filepath = os.path.join(self.temp_path, filename) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 } | 664 } |
613 caterpillar.edit_code(self.output_path, [], chrome_app_manifest, | 665 caterpillar.edit_code(self.output_path, [], chrome_app_manifest, |
614 {'boilerplate_dir': BOILERPLATE_DIR}) | 666 {'boilerplate_dir': BOILERPLATE_DIR}) |
615 with codecs.open(os.path.join(self.output_path, 'my índex.html'), | 667 with codecs.open(os.path.join(self.output_path, 'my índex.html'), |
616 encoding='utf-8') as js_file: | 668 encoding='utf-8') as js_file: |
617 self.assertIn('<meta content="test233" name="name"', js_file.read()) | 669 self.assertIn('<meta content="test233" name="name"', js_file.read()) |
618 | 670 |
619 | 671 |
620 if __name__ == '__main__': | 672 if __name__ == '__main__': |
621 unittest.main() | 673 unittest.main() |
OLD | NEW |