diff --git a/api/tests/music/test_utils.py b/api/tests/music/test_utils.py index 67a4212d89e1b22391051a88d90d651228e37a40..0f445348cdc759f7db9c357087ca43a73d948a1c 100644 --- a/api/tests/music/test_utils.py +++ b/api/tests/music/test_utils.py @@ -1,6 +1,7 @@ import os import pathlib import pytest +import tempfile from funkwhale_api.music import utils @@ -28,6 +29,7 @@ def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker): ("sample.flac", {"bitrate": 1608000, "length": 0.001}), ("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}), ("test.ogg", {"bitrate": 112000, "length": 1}), + ("test.opus", {"bitrate": 112000, "length": 1}) ], ) def test_get_audio_file_data(name, expected): @@ -109,3 +111,21 @@ def test_get_dirs_and_files(path, expected, tmpdir): (root_path / "System" / "file.ogg").touch() assert utils.browse_dir(root_path, path) == expected + +@pytest.mark.parametrize( + "name, expected", + [ + ("sample.flac", {"bitrate": 1608000, "length": 0.001}), + ("test.mp3", {"bitrate": 8000, "length": 267.70285714285717}), + ("test.ogg", {"bitrate": 112000, "length": 1}), + ("test.opus", {"bitrate": 112000, "length": 1}) + ], +) +def test_transcode_file(name, expected): + path = pathlib.Path(os.path.join(DATA_DIR, name)) + with tempfile.NamedTemporaryFile() as dest: + utils.transcode_file(path, pathlib.Path(dest.name)) + with open(dest.name, "rb") as f: + result = utils.get_audio_file_data(f) + + assert result == expected