Verified Commit 5a2cf911 authored by Eliot Berriot's avatar Eliot Berriot 💬

Fixed #621: None extension when downloading an in-place imported file

parent baf92ec2
......@@ -121,7 +121,7 @@ class UploadFactory(factory.django.DjangoModelFactory):
model = "music.Upload"
class Params:
in_place = factory.Trait(audio_file=None)
in_place = factory.Trait(audio_file=None, mimetype=None)
playable = factory.Trait(
import_status="finished", library__privacy_level="everyone"
)
......
......@@ -738,9 +738,10 @@ class Upload(models.Model):
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)
if self.audio_file:
return os.path.splitext(self.audio_file.name)[-1].replace(".", "", 1)
if self.in_place_path:
return os.path.splitext(self.in_place_path)[-1].replace(".", "", 1)
def get_file_size(self):
if self.audio_file:
......@@ -823,6 +824,12 @@ class Upload(models.Model):
return version
@property
def in_place_path(self):
if not self.source or not self.source.startswith("file://"):
return
return self.source.lstrip("file://")
MIMETYPE_CHOICES = [(mt, ext) for ext, mt in utils.AUDIO_EXTENSIONS_AND_MIMETYPE]
......
......@@ -490,6 +490,7 @@ def test_fid_is_populated(factories, model, factory_args, namespace):
[
({"audio_file__filename": "test.mp3", "mimetype": None}, "mp3"),
({"mimetype": "audio/mpeg"}, "mp3"),
({"in_place": True, "source": "file:///test.mp3"}, "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"),
......@@ -497,6 +498,7 @@ def test_fid_is_populated(factories, model, factory_args, namespace):
)
def test_upload_extension(factory_args, factories, expected):
upload = factories["music.Upload"].build(**factory_args)
assert upload.extension == expected
......
Fixed None extension when downloading an in-place imported file (#621)
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