-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support video tag and video thumbnail generation
- Loading branch information
Showing
4 changed files
with
251 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import cloudinary | ||
from cloudinary import CloudinaryVideo | ||
import unittest | ||
|
||
VIDEO_UPLOAD_PATH = 'http://res.cloudinary.com/test123/video/upload/' | ||
DEFAULT_UPLOAD_PATH = 'http://res.cloudinary.com/test123/image/upload/' | ||
|
||
class VideoTest(unittest.TestCase): | ||
def setUp(self): | ||
cloudinary.config(cloud_name="test123", api_secret="1234") | ||
self.video = CloudinaryVideo("movie") | ||
def test_video_thumbail(self): | ||
self.assertEqual(self.video.video_thumbnail(), VIDEO_UPLOAD_PATH + "movie.jpg") | ||
self.assertEqual(self.video.video_thumbnail(width = 100), VIDEO_UPLOAD_PATH + "w_100/movie.jpg") | ||
|
||
def test_video_image_tag(self): | ||
expected_url = VIDEO_UPLOAD_PATH + "movie.jpg" | ||
self.assertEqual(self.video.image(), "<img src=\"" + expected_url + "\"/>") | ||
|
||
expected_url = VIDEO_UPLOAD_PATH + "w_100/movie.jpg" | ||
self.assertEqual(self.video.image(width= 100), | ||
"<img src=\"" + expected_url + "\" width=\"100\"/>") | ||
|
||
def test_video_tag(self): | ||
""" default """ | ||
expected_url = VIDEO_UPLOAD_PATH + "movie" | ||
self.assertEqual(self.video.video(), "<video poster=\"" + expected_url + ".jpg\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
def test_video_tag_with_attributes(self): | ||
""" test video attributes """ | ||
expected_url = VIDEO_UPLOAD_PATH + "movie" | ||
self.assertEqual(self.video.video(autoplay = 1, controls = True, loop = True, muted = "true", preload = True), | ||
"<video autoplay=\"1\" controls loop muted=\"true\" poster=\"" + expected_url + ".jpg\" preload>" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
def test_video_tag_with_transformation(self): | ||
""" test video attributes """ | ||
options = { | ||
'source_types': "mp4", | ||
'html_height' : "100", | ||
'html_width' : "200", | ||
'video_codec' : {'codec': 'h264'}, | ||
'audio_codec' : 'acc', | ||
'start_offset': 3 | ||
} | ||
expected_url = VIDEO_UPLOAD_PATH + "ac_acc,so_3,vc_h264/movie" | ||
self.assertEqual(self.video.video(**options), | ||
"<video height=\"100\" poster=\"" + expected_url + ".jpg\" src=\"" + expected_url + ".mp4\" width=\"200\"></video>") | ||
|
||
del options['source_types'] | ||
self.assertEqual(self.video.video(**options), | ||
"<video height=\"100\" poster=\"" + expected_url + ".jpg\" width=\"200\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
del options['html_height'] | ||
del options['html_width'] | ||
options['width'] = 250 | ||
expected_url = VIDEO_UPLOAD_PATH + "ac_acc,so_3,vc_h264,w_250/movie" | ||
self.assertEqual(self.video.video(**options), | ||
"<video poster=\"" + expected_url + ".jpg\" width=\"250\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
expected_url = VIDEO_UPLOAD_PATH + "ac_acc,c_fit,so_3,vc_h264,w_250/movie" | ||
options['crop'] = 'fit' | ||
self.assertEqual(self.video.video(**options), | ||
"<video poster=\"" + expected_url + ".jpg\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
def test_video_tag_with_fallback(self): | ||
expected_url = VIDEO_UPLOAD_PATH + "movie" | ||
fallback = "<span id=\"spanid\">Cannot display video</span>" | ||
self.assertEqual(self.video.video(fallback_content = fallback), | ||
"<video poster=\"" + expected_url + ".jpg\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
fallback + | ||
"</video>") | ||
self.assertEqual(self.video.video(fallback_content = fallback, source_types = "mp4"), | ||
"<video poster=\"" + expected_url + ".jpg\" src=\"" + expected_url + ".mp4\">" + | ||
fallback + | ||
"</video>") | ||
|
||
|
||
def test_video_tag_with_source_types(self): | ||
expected_url = VIDEO_UPLOAD_PATH + "movie" | ||
self.assertEqual(self.video.video(source_types = ['ogv', 'mp4']), | ||
"<video poster=\"" + expected_url + ".jpg\">" + | ||
"<source src=\"" + expected_url + ".ogv\" type=\"video/ogg\">" + | ||
"<source src=\"" + expected_url + ".mp4\" type=\"video/mp4\">" + | ||
"</video>") | ||
|
||
def test_video_tag_with_source_transformation(self): | ||
expected_url = VIDEO_UPLOAD_PATH + "q_50/w_100/movie" | ||
expected_ogv_url = VIDEO_UPLOAD_PATH + "q_50/q_70,w_100/movie" | ||
expected_mp4_url = VIDEO_UPLOAD_PATH + "q_50/q_30,w_100/movie" | ||
self.assertEqual(self.video.video(width = 100, transformation = {'quality': 50}, | ||
source_transformation = {'ogv': {'quality': 70}, 'mp4': {'quality': 30}}), | ||
"<video poster=\"" + expected_url + ".jpg\" width=\"100\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_mp4_url + ".mp4\" type=\"video/mp4\">" + | ||
"<source src=\"" + expected_ogv_url + ".ogv\" type=\"video/ogg\">" + | ||
"</video>") | ||
|
||
self.assertEqual(self.video.video(width = 100, transformation = {'quality': 50}, | ||
source_transformation = {'ogv': {'quality': 70}, 'mp4': {'quality': 30}}, | ||
source_types = ['webm', 'mp4']), | ||
"<video poster=\"" + expected_url + ".jpg\" width=\"100\">" + | ||
"<source src=\"" + expected_url + ".webm\" type=\"video/webm\">" + | ||
"<source src=\"" + expected_mp4_url + ".mp4\" type=\"video/mp4\">" + | ||
"</video>") | ||
|
||
def test_video_tag_with_poster(self): | ||
expected_url = VIDEO_UPLOAD_PATH + "movie" | ||
|
||
expected_poster_url = 'http://image/somewhere.jpg' | ||
self.assertEqual(self.video.video(poster = expected_poster_url, source_types = "mp4"), | ||
"<video poster=\"" + expected_poster_url + "\" src=\"" + expected_url + ".mp4\"></video>") | ||
|
||
expected_poster_url = VIDEO_UPLOAD_PATH + "g_north/movie.jpg" | ||
self.assertEqual(self.video.video(poster = {'gravity': 'north'}, source_types = "mp4"), | ||
"<video poster=\"" + expected_poster_url + "\" src=\"" + expected_url + ".mp4\"></video>") | ||
|
||
expected_poster_url = DEFAULT_UPLOAD_PATH + "g_north/my_poster.jpg" | ||
self.assertEqual(self.video.video(poster = {'gravity': 'north', 'public_id': 'my_poster', 'format': 'jpg'}, source_types = "mp4"), | ||
"<video poster=\"" + expected_poster_url + "\" src=\"" + expected_url + ".mp4\"></video>") | ||
|
||
self.assertEqual(self.video.video(poster = None, source_types = "mp4"), | ||
"<video src=\"" + expected_url + ".mp4\"></video>") | ||
|
||
self.assertEqual(self.video.video(poster = False, source_types = "mp4"), | ||
"<video src=\"" + expected_url + ".mp4\"></video>") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |