]> littlesong.place Git - littlesongplace.git/commitdiff
Remove ffmpeg from tests to speed up execution
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 5 Apr 2025 16:31:20 +0000 (12:31 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 5 Apr 2025 16:31:20 +0000 (12:31 -0400)
.github/workflows/test-and-deploy.yml
src/littlesongplace/__init__.py
test/conftest.py
test/test_songs.py

index a1894a3b79b1e7c18fddd602c266a841f8808af8..70a2dd78fdb05cce11c68f3083f6555febc9856d 100644 (file)
@@ -96,11 +96,6 @@ jobs:
       with:
         python-version: "3.11"
 
-    - name: Install ffmpeg
-      run: |
-        sudo apt update
-        sudo apt install ffmpeg
-
     - name: Install mpck
       run: |
         wget https://github.com/Sjord/checkmate/releases/download/v0.21/mpck_0.21-1_amd64.deb
index 5c3ff73924a4e5300083ef22692fadc811caac73..c8b7d0825aeb2462a9cbc03715f7b14b997d9425 100644 (file)
@@ -396,7 +396,9 @@ def convert_song(tmp_file, request_file, yt_url):
         out_file.close()
         os.remove(out_file.name)
         result = subprocess.run(["ffmpeg", "-i", tmp_file.name, out_file.name], stdout=subprocess.PIPE)
+        print(result)
         if result.returncode == 0:
+            print('okie')
             # Successfully converted file, overwrite original file
             os.replace(out_file.name, tmp_file.name)
             return True
index 224a295304ba3a7a45b27bf07fd784e94f3b3a2b..182550b9d645aee08e1f363ed9ee8f7aca33f81a 100644 (file)
@@ -8,6 +8,8 @@ import bcrypt
 import requests
 import pytest
 
+pytest.register_assert_rewrite("test.utils")
+
 from .utils import login
 
 fresh_db = None
index 559fa99fd92af2ae8c5a00b84e3bd19156e221ab..9cd5f6641eb8e17b10f61ee118f0bda6348509a5 100644 (file)
@@ -1,4 +1,6 @@
+import subprocess
 from pathlib import Path
+from unittest import mock
 
 import pytest
 
@@ -45,7 +47,20 @@ def test_upload_song_invalid_audio(client):
     # Use this script file as the "audio" file
     upload_song(client, b"Invalid audio file", error=True, filename=__file__)
 
-def test_upload_song_from_mp4(client):
+def _create_fake_mp3(*args, **kwargs):
+    subprocess_args = args[0]
+    if subprocess_args[0] == "ffmpeg":
+        # Create "fake" mp3 file by just copying input file
+        output_filename = subprocess_args[-1]
+        input_filename = subprocess_args[-2]
+        with open(input_filename, "rb") as infile, open(output_filename, "wb") as outfile:
+            outfile.write(infile.read())
+
+    return subprocess.CompletedProcess([], returncode=0, stdout=b"")
+
+@mock.patch("subprocess.run")
+def test_upload_song_from_mp4(fake_run, client):
+    fake_run.side_effect = _create_fake_mp3
     create_user(client, "user", "password", login=True)
     upload_song(client, b"Successfully uploaded &#39;song title&#39;", filename=TEST_DATA/"sample-4s.mp4")