diff --git a/embed_video/tests/custom_backend.py b/embed_video/tests/custom_backend.py new file mode 100644 index 0000000..79a54b3 --- /dev/null +++ b/embed_video/tests/custom_backend.py @@ -0,0 +1,11 @@ +import re + +from embed_video.backends import VideoBackend + + +class CustomBackend(VideoBackend): + re_detect = re.compile(r'http://myvideo\.com/[0-9]+') + re_code = re.compile(r'http://myvideo\.com/(?P[0-9]+)') + + pattern_url = 'http://play.myvideo.com/c/%s/' + pattern_thumbnail_url = 'http://thumb.myvideo.com/c/%s/' diff --git a/embed_video/tests/django_settings.py b/embed_video/tests/django_settings.py index fe35230..00c05a8 100644 --- a/embed_video/tests/django_settings.py +++ b/embed_video/tests/django_settings.py @@ -12,13 +12,22 @@ INSTALLED_APPS = ( 'embed_video', ) + +EMBED_VIDEO_BACKENDS = ( + 'embed_video.backends.YoutubeBackend', + 'embed_video.backends.VimeoBackend', + 'embed_video.backends.SoundCloudBackend', + 'embed_video.tests.custom_backend.CustomBackend', +) + + LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { - 'console':{ - 'level':'DEBUG', - 'class':'logging.StreamHandler', + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', }, }, 'loggers': { diff --git a/embed_video/tests/tests.py b/embed_video/tests/tests.py index feea829..d65a126 100644 --- a/embed_video/tests/tests.py +++ b/embed_video/tests/tests.py @@ -2,6 +2,3 @@ import os os.environ['DJANGO_SETTINGS_MODULE'] = 'embed_video.tests.django_settings' -from .tests_fields import EmbedVideoFieldTestCase, EmbedVideoFormFieldTestCase -from .tests_backend import EmbedVideoTestCase -from .tests_tags import EmbedVideoNodeTestCase diff --git a/embed_video/tests/tests_custom_backend.py b/embed_video/tests/tests_custom_backend.py new file mode 100644 index 0000000..a0d9ad7 --- /dev/null +++ b/embed_video/tests/tests_custom_backend.py @@ -0,0 +1,25 @@ +from unittest import TestCase + +from embed_video.backends import detect_backend + +from .custom_backend import CustomBackend + + +class CustomBackendTestCase(TestCase): + def setUp(self): + self.backend = detect_backend('http://myvideo.com/1530') + + def test_detect_backend(self): + self.assertIsInstance(self.backend, CustomBackend) + + def test_code(self): + self.assertEqual(self.backend.code, '1530') + + def test_url(self): + self.assertEqual(self.backend.get_url(), + 'http://play.myvideo.com/c/1530/') + + def test_thumbnail(self): + self.assertEqual(self.backend.get_thumbnail_url(), + 'http://thumb.myvideo.com/c/1530/') +