Files
discord-embed/tests/test_video.py

34 lines
876 B
Python

import imghdr
import os
import settings
from video import make_thumbnail, video_resolution
TEST_FILE = "tests/test.mp4"
def test_video_resolution():
"""Test video_resolution() works."""
assert video_resolution(TEST_FILE) == (422, 422)
def test_make_thumbnail():
"""Test make_thumbnail() works."""
domain = os.environ["SERVE_DOMAIN"]
# Remove trailing slash from domain
if domain.endswith("/"):
domain = domain[:-1]
# Remove thumbnail if it exists
if os.path.exists(f"{settings.upload_folder}/test.mp4.jpg"):
os.remove(f"{settings.upload_folder}/test.mp4.jpg")
thumbnail = make_thumbnail(TEST_FILE, "test.mp4")
# Check if thumbnail is a jpeg.
assert imghdr.what(f"{settings.upload_folder}/test.mp4.jpg") == "jpeg"
# Check if it returns the correct URL.
assert thumbnail == f"{domain}/test.mp4.jpg"