mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-04-28 16:34:42 +00:00
tests
This commit is contained in:
parent
7616ae15dc
commit
20733d8997
3 changed files with 135 additions and 0 deletions
0
embed_video/tests/__init__.py
Normal file
0
embed_video/tests/__init__.py
Normal file
29
embed_video/tests/django_settings.py
Normal file
29
embed_video/tests/django_settings.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
|
||||
from django.conf.global_settings import *
|
||||
|
||||
DEBUG = True
|
||||
|
||||
STATIC_ROOT = MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static')
|
||||
STATIC_URL = MEDIA_URL = '/static/'
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'embed_video',
|
||||
)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console':{
|
||||
'level':'DEBUG',
|
||||
'class':'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'less': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
}
|
||||
}
|
||||
106
embed_video/tests/tests.py
Normal file
106
embed_video/tests/tests.py
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import os
|
||||
|
||||
from unittest import main, TestCase
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.template.base import Template
|
||||
from django.template.context import RequestContext
|
||||
|
||||
from ..base import detect_backend, YoutubeBackend, VimeoBackend
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'embed_video.tests.django_settings'
|
||||
|
||||
|
||||
class EmbedVideoTestCase(TestCase):
|
||||
youtube_urls = (
|
||||
('http://www.youtube.com/watch?v=jsrRJyHBvzw', 'jsrRJyHBvzw'),
|
||||
('http://youtube.com/watch?v=jsrRJyHBvzw', 'jsrRJyHBvzw'),
|
||||
('http://youtu.be/jsrRJyHBvzw', 'jsrRJyHBvzw'),
|
||||
('http://www.youtube.com/watch?v=iwGFalTRHDA&feature=related', 'iwGFalTRHDA'),
|
||||
('http://youtu.be/n17B_uFF4cA', 'n17B_uFF4cA'),
|
||||
('http://www.youtube.com/watch?v=t-ZRX8984sc', 't-ZRX8984sc'),
|
||||
('http://youtu.be/t-ZRX8984sc', 't-ZRX8984sc'),
|
||||
)
|
||||
|
||||
vimeo_urls = (
|
||||
('http://vimeo.com/66577491', '66577491'),
|
||||
('http://www.vimeo.com/66577491', '66577491'),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
from django.conf import settings as django_settings
|
||||
self.django_settings = django_settings
|
||||
|
||||
def _grc(self):
|
||||
return RequestContext(HttpRequest())
|
||||
|
||||
def test_embed(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video 'http://www.youtube.com/watch?v=jsrRJyHBvzw' as ytb %}
|
||||
{{ ytb|embed:'large' }}
|
||||
{% endvideo %}
|
||||
""")
|
||||
rendered = '<iframe width="1280" height="720" src="http://www.youtube.com/embed/jsrRJyHBvzw?wmode=opaque" frameborder="0" allowfullscreen></iframe>'
|
||||
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
||||
def test_embed_user_size(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video 'http://www.youtube.com/watch?v=jsrRJyHBvzw' as ytb %}
|
||||
{{ ytb|embed:'800x800' }}
|
||||
{% endvideo %}
|
||||
""")
|
||||
rendered = '<iframe width="800" height="800" src="http://www.youtube.com/embed/jsrRJyHBvzw?wmode=opaque" frameborder="0" allowfullscreen></iframe>'
|
||||
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
||||
|
||||
def test_tag_youtube(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video 'http://www.youtube.com/watch?v=jsrRJyHBvzw' as ytb %}
|
||||
{{ ytb.url }}
|
||||
{% endvideo %}
|
||||
""")
|
||||
rendered = 'http://www.youtube.com/embed/jsrRJyHBvzw?wmode=opaque'
|
||||
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
||||
def test_tag_vimeo(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video 'https://vimeo.com/66577491' as vimeo %}
|
||||
{{ vimeo.url }}
|
||||
{% endvideo %}
|
||||
""")
|
||||
rendered = 'http://player.vimeo.com/video/66577491'
|
||||
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
||||
def test_detect_youtube(self):
|
||||
for url in self.youtube_urls:
|
||||
backend = detect_backend(url[0])
|
||||
self.assertIsInstance(backend, YoutubeBackend)
|
||||
|
||||
def test_detect_vimeo(self):
|
||||
for url in self.vimeo_urls:
|
||||
backend = detect_backend(url[0])
|
||||
self.assertIsInstance(backend, VimeoBackend)
|
||||
|
||||
def test_code_youtube(self):
|
||||
for url in self.youtube_urls:
|
||||
backend = YoutubeBackend(url[0])
|
||||
code = backend.get_code()
|
||||
self.assertEqual(code, url[1])
|
||||
|
||||
def test_code_vimeo(self):
|
||||
for url in self.vimeo_urls:
|
||||
backend = VimeoBackend(url[0])
|
||||
code = backend.get_code()
|
||||
self.assertEqual(code, url[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in a new issue