Tests for CustomBackend

This commit is contained in:
Juda Kaleta 2013-08-22 16:55:49 +02:00
parent acd0dbf9c8
commit 2a4fe971b5
4 changed files with 48 additions and 6 deletions

View file

@ -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<code>[0-9]+)')
pattern_url = 'http://play.myvideo.com/c/%s/'
pattern_thumbnail_url = 'http://thumb.myvideo.com/c/%s/'

View file

@ -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': {

View file

@ -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

View file

@ -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/')