test_tools.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import re
  4. from odoo.tests import common, tagged
  5. from odoo.addons.web_editor import tools
  6. @tagged('post_install', '-at_install')
  7. class TestVideoUtils(common.BaseCase):
  8. urls = {
  9. 'youtube': 'https://www.youtube.com/watch?v=xCvFZrrQq7k',
  10. 'vimeo': 'https://vimeo.com/395399735',
  11. 'dailymotion': 'https://www.dailymotion.com/video/x7svr6t',
  12. 'youku': 'https://v.youku.com/v_show/id_XMzY1MjY4.html?spm=a2hzp.8244740.0.0',
  13. 'instagram': 'https://www.instagram.com/p/B6dXGTxggTG/',
  14. 'dailymotion_hub_no_video': 'http://www.dailymotion.com/hub/x9q_Galatasaray',
  15. 'dailymotion_hub_#video': 'http://www.dailymotion.com/hub/x9q_Galatasaray#video=x2jvvep',
  16. 'dai.ly': 'https://dai.ly/x578has',
  17. 'dailymotion_embed': 'https://www.dailymotion.com/embed/video/x578has?autoplay=1',
  18. 'dailymotion_video_extra': 'https://www.dailymotion.com/video/x2jvvep_hakan-yukur-klip_sport',
  19. 'player_youku': 'https://player.youku.com/player.php/sid/XMTI5Mjg5NjE4MA==/v.swf',
  20. 'youku_embed': 'https://player.youku.com/embed/XNTIwMzE1MzUzNg',
  21. }
  22. def test_player_regexes(self):
  23. #youtube
  24. self.assertIsNotNone(re.search(tools.player_regexes['youtube'], TestVideoUtils.urls['youtube']))
  25. #vimeo
  26. self.assertIsNotNone(re.search(tools.player_regexes['vimeo'], TestVideoUtils.urls['vimeo']))
  27. #dailymotion
  28. self.assertIsNotNone(re.search(tools.player_regexes['dailymotion'], TestVideoUtils.urls['dailymotion']))
  29. #youku
  30. self.assertIsNotNone(re.search(tools.player_regexes['youku'], TestVideoUtils.urls['youku']))
  31. #instagram
  32. self.assertIsNotNone(re.search(tools.player_regexes['instagram'], TestVideoUtils.urls['instagram']))
  33. def test_get_video_source_data(self):
  34. self.assertEqual(3, len(tools.get_video_source_data(TestVideoUtils.urls['youtube'])))
  35. #youtube
  36. self.assertEqual('youtube', tools.get_video_source_data(TestVideoUtils.urls['youtube'])[0])
  37. self.assertEqual('xCvFZrrQq7k', tools.get_video_source_data(TestVideoUtils.urls['youtube'])[1])
  38. #vimeo
  39. self.assertEqual('vimeo', tools.get_video_source_data(TestVideoUtils.urls['vimeo'])[0])
  40. self.assertEqual('395399735', tools.get_video_source_data(TestVideoUtils.urls['vimeo'])[1])
  41. #dailymotion
  42. self.assertEqual('dailymotion', tools.get_video_source_data(TestVideoUtils.urls['dailymotion'])[0])
  43. self.assertEqual('x7svr6t', tools.get_video_source_data(TestVideoUtils.urls['dailymotion'])[1])
  44. self.assertEqual(None, tools.get_video_source_data(TestVideoUtils.urls['dailymotion_hub_no_video']))
  45. self.assertEqual('dailymotion', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_hub_#video'])[0])
  46. self.assertEqual('x2jvvep', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_hub_#video'])[1])
  47. self.assertEqual('dailymotion', tools.get_video_source_data(TestVideoUtils.urls['dai.ly'])[0])
  48. self.assertEqual('x578has', tools.get_video_source_data(TestVideoUtils.urls['dai.ly'])[1])
  49. self.assertEqual('dailymotion', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_embed'])[0])
  50. self.assertEqual('x578has', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_embed'])[1])
  51. self.assertEqual('dailymotion', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_video_extra'])[0])
  52. self.assertEqual('x2jvvep', tools.get_video_source_data(TestVideoUtils.urls['dailymotion_video_extra'])[1])
  53. #youku
  54. self.assertEqual('youku', tools.get_video_source_data(TestVideoUtils.urls['youku'])[0])
  55. self.assertEqual('XMzY1MjY4', tools.get_video_source_data(TestVideoUtils.urls['youku'])[1])
  56. self.assertEqual('youku', tools.get_video_source_data(TestVideoUtils.urls['player_youku'])[0])
  57. self.assertEqual('XMTI5Mjg5NjE4MA', tools.get_video_source_data(TestVideoUtils.urls['player_youku'])[1])
  58. self.assertEqual('youku', tools.get_video_source_data(TestVideoUtils.urls['youku_embed'])[0])
  59. self.assertEqual('XNTIwMzE1MzUzNg', tools.get_video_source_data(TestVideoUtils.urls['youku_embed'])[1])
  60. #instagram
  61. self.assertEqual('instagram', tools.get_video_source_data(TestVideoUtils.urls['instagram'])[0])
  62. self.assertEqual('B6dXGTxggTG', tools.get_video_source_data(TestVideoUtils.urls['instagram'])[1])
  63. def test_get_video_url_data(self):
  64. self.assertEqual(2, len(tools.get_video_url_data(TestVideoUtils.urls['youtube'])))
  65. #youtube
  66. self.assertEqual('youtube', tools.get_video_url_data(TestVideoUtils.urls['youtube'])['platform'])
  67. #vimeo
  68. self.assertEqual('vimeo', tools.get_video_url_data(TestVideoUtils.urls['vimeo'])['platform'])
  69. #dailymotion
  70. self.assertEqual('dailymotion', tools.get_video_url_data(TestVideoUtils.urls['dailymotion'])['platform'])
  71. #youku
  72. self.assertEqual('youku', tools.get_video_url_data(TestVideoUtils.urls['youku'])['platform'])
  73. #instagram
  74. self.assertEqual('instagram', tools.get_video_url_data(TestVideoUtils.urls['instagram'])['platform'])
  75. def test_valid_video_url(self):
  76. self.assertIsNotNone(re.search(tools.valid_url_regex, TestVideoUtils.urls['youtube']))
  77. @tagged('-standard', 'external')
  78. class TestVideoUtilsExternal(common.BaseCase):
  79. def test_get_video_thumbnail(self):
  80. #youtube
  81. self.assertIsInstance(tools.get_video_thumbnail(TestVideoUtils.urls['youtube']), bytes)
  82. #vimeo
  83. self.assertIsInstance(tools.get_video_thumbnail(TestVideoUtils.urls['vimeo']), bytes)
  84. #dailymotion
  85. self.assertIsInstance(tools.get_video_thumbnail(TestVideoUtils.urls['dailymotion']), bytes)
  86. #instagram
  87. self.assertIsInstance(tools.get_video_thumbnail(TestVideoUtils.urls['instagram']), bytes)
  88. #default
  89. self.assertIsInstance(tools.get_video_thumbnail(TestVideoUtils.urls['youku']), bytes)