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
+import subprocess
from pathlib import Path
+from unittest import mock
import pytest
# 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 'song title'", filename=TEST_DATA/"sample-4s.mp4")