diff --git a/tests/test_discord_embed.py b/tests/test_discord_embed.py index 24993bc..f358590 100644 --- a/tests/test_discord_embed.py +++ b/tests/test_discord_embed.py @@ -1,4 +1,3 @@ -import imghdr import os from fastapi.testclient import TestClient @@ -6,7 +5,6 @@ from fastapi.testclient import TestClient from discord_embed import __version__, settings from discord_embed.generate_html import generate_html_for_videos from discord_embed.main import app -from discord_embed.video import make_thumbnail, video_resolution from discord_embed.webhook import send_webhook client = TestClient(app) @@ -41,27 +39,6 @@ def test_generate_html_for_videos(): assert generated_html == f"{domain}/test_video.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] - - 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" - - def test_save_to_disk(): """Test save_to_disk() works.""" # TODO: Implement this test. I need to mock the UploadFile object. diff --git a/tests/test_video.py b/tests/test_video.py new file mode 100644 index 0000000..5f24f09 --- /dev/null +++ b/tests/test_video.py @@ -0,0 +1,33 @@ +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" diff --git a/uploads/test.mp4 b/uploads/test.mp4 new file mode 100644 index 0000000..995e692 Binary files /dev/null and b/uploads/test.mp4 differ