def test_01_get_available_plugin_uids(self): """ Test ``autodiscover`` and ``get_available_plugin_uids``. """ res = get_registered_plugin_uids() res.sort() c = ['vimeo', 'youtube'] c.sort() self.assertEqual(res, c) return res
def test_07_register_unregister(self): """ Testing register/unregister. """ from vishap.contrib.plugins.vimeo.vishap_plugin import VimeoPlugin class Example2Plugin(BaseVideoPlugin): """ Example plugin. """ uid = "youtube" name = "Example with youtube ``uid``" url_pattern = "^(?P<prefix>(http\:\/\/www\.youtube\.com\/watch\?v=)|(http\:\/\/www\.youtube\.com\/v\/)|(http\:\/\/youtu\.be\/))(?P<value>[A-Za-z0-9\-=_]{11})" id_pattern = "^(?P<value>[A-Za-z0-9\-=_]{11})" thumbnail_pattern = "//img.youtube.com/vi/{0}/{1}.jpg" embed_code = """ <iframe src="//www.youtube.com/embed/{video_id}" {options} frameborder="0" allowfullscreen></iframe> """ plugin_registry.register(Example2Plugin) # Since key `ru` already exists in the registry it can't be replaced (without force-register). res = plugin_registry.register(Example2Plugin) self.assertTrue(not res) # Now with force-register it can. res = plugin_registry.register(Example2Plugin, force=True) self.assertTrue(res) # Once we have it there and it's forced, we can't register another. res = plugin_registry.register(Example2Plugin, force=True) self.assertTrue(not res) # Unregister non-forced language pack. res = plugin_registry.unregister(VimeoPlugin) self.assertTrue( res and not VimeoPlugin.uid in get_registered_plugin_uids()) res = plugin_registry.unregister(Example2Plugin) self.assertTrue(not res and Example2Plugin.uid in get_registered_plugin_uids())
def test_07_register_unregister(self): """ Testing register/unregister. """ from vishap.contrib.plugins.vimeo.vishap_plugin import VimeoPlugin class Example2Plugin(BaseVideoPlugin): """ Example plugin. """ uid = "youtube" name = "Example with youtube ``uid``" url_pattern = "^(?P<prefix>(http\:\/\/www\.youtube\.com\/watch\?v=)|(http\:\/\/www\.youtube\.com\/v\/)|(http\:\/\/youtu\.be\/))(?P<value>[A-Za-z0-9\-=_]{11})" id_pattern = "^(?P<value>[A-Za-z0-9\-=_]{11})" thumbnail_pattern = "//img.youtube.com/vi/{0}/{1}.jpg" embed_code = """ <iframe src="//www.youtube.com/embed/{video_id}" {options} frameborder="0" allowfullscreen></iframe> """ plugin_registry.register(Example2Plugin) # Since key `ru` already exists in the registry it can't be replaced (without force-register). res = plugin_registry.register(Example2Plugin) self.assertTrue(not res) # Now with force-register it can. res = plugin_registry.register(Example2Plugin, force=True) self.assertTrue(res) # Once we have it there and it's forced, we can't register another. res = plugin_registry.register(Example2Plugin, force=True) self.assertTrue(not res) # Unregister non-forced language pack. res = plugin_registry.unregister(VimeoPlugin) self.assertTrue(res and not VimeoPlugin.uid in get_registered_plugin_uids()) res = plugin_registry.unregister(Example2Plugin) self.assertTrue(not res and Example2Plugin.uid in get_registered_plugin_uids())
def test_06_register_custom_plugin(self): """ Test registering of a custom plugin. """ class ExamplePlugin(BaseVideoPlugin): """ Example plugin. """ uid = "example" name = "Example" url_pattern = "^(?P<prefix>(http\:\/\/www\.youtube\.com\/watch\?v=)|(http\:\/\/www\.youtube\.com\/v\/)|(http\:\/\/youtu\.be\/))(?P<value>[A-Za-z0-9\-=_]{11})" id_pattern = "^(?P<value>[A-Za-z0-9\-=_]{11})" thumbnail_pattern = "//img.youtube.com/vi/{0}/{1}.jpg" embed_code = """ <iframe src="//www.youtube.com/embed/{video_id}" {options} frameborder="0" allowfullscreen></iframe> """ plugin_registry.register(ExamplePlugin) assert 'example' in get_registered_plugin_uids() res = render_video(self.youtube_urls[0], plugin_uid='example').strip() self.assertEqual(res, self.rendered_youtube_responsive_embed_codes[0]) return res