Commit a0bb036c authored by Eliot Berriot's avatar Eliot Berriot 💬

Merge branch '473-none-flac-file' into 'develop'

Fix #473: ".None" extension when downloading Flac file

Closes #473

See merge request funkwhale/funkwhale!470
parents c0904ca8 837d6ad0
......@@ -688,6 +688,10 @@ class Upload(models.Model):
@property
def extension(self):
try:
return utils.MIMETYPE_TO_EXTENSION[self.mimetype]
except KeyError:
pass
if not self.audio_file:
return
return os.path.splitext(self.audio_file.name)[-1].replace(".", "", 1)
......
......@@ -33,6 +33,7 @@ AUDIO_EXTENSIONS_AND_MIMETYPE = [
("ogg", "audio/ogg"),
("mp3", "audio/mpeg"),
("flac", "audio/x-flac"),
("flac", "audio/flac"),
]
EXTENSION_TO_MIMETYPE = {ext: mt for ext, mt in AUDIO_EXTENSIONS_AND_MIMETYPE}
......
......@@ -167,8 +167,7 @@ def test_audio_track_mime_type(extention, mimetype, factories):
def test_upload_file_name(factories):
name = "test.mp3"
path = os.path.join(DATA_DIR, name)
upload = factories["music.Upload"](audio_file__from_path=path)
upload = factories["music.Upload"](audio_file__from_path=path, mimetype=None)
assert upload.filename == upload.track.full_name + ".mp3"
......@@ -484,3 +483,18 @@ def test_fid_is_populated(factories, model, factory_args, namespace):
assert instance.fid == federation_utils.full_url(
reverse(namespace, kwargs={"uuid": instance.uuid})
)
@pytest.mark.parametrize(
"factory_args,expected",
[
({"audio_file__filename": "test.mp3", "mimetype": None}, "mp3"),
({"mimetype": "audio/mpeg"}, "mp3"),
({"audio_file__filename": "test.None", "mimetype": "audio/mpeg"}, "mp3"),
({"audio_file__filename": "test.None", "mimetype": "audio/flac"}, "flac"),
({"audio_file__filename": "test.None", "mimetype": "audio/x-flac"}, "flac"),
],
)
def test_upload_extension(factory_args, factories, expected):
upload = factories["music.Upload"].build(**factory_args)
assert upload.extension == expected
Fix ".None" extension when downloading Flac file (#473)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment