Fixed #621: None extension when downloading an in-place imported file
This commit is contained in:
parent
baf92ec22c
commit
5a2cf9112b
|
@ -121,7 +121,7 @@ class UploadFactory(factory.django.DjangoModelFactory):
|
||||||
model = "music.Upload"
|
model = "music.Upload"
|
||||||
|
|
||||||
class Params:
|
class Params:
|
||||||
in_place = factory.Trait(audio_file=None)
|
in_place = factory.Trait(audio_file=None, mimetype=None)
|
||||||
playable = factory.Trait(
|
playable = factory.Trait(
|
||||||
import_status="finished", library__privacy_level="everyone"
|
import_status="finished", library__privacy_level="everyone"
|
||||||
)
|
)
|
||||||
|
|
|
@ -738,9 +738,10 @@ class Upload(models.Model):
|
||||||
return utils.MIMETYPE_TO_EXTENSION[self.mimetype]
|
return utils.MIMETYPE_TO_EXTENSION[self.mimetype]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if not self.audio_file:
|
if self.audio_file:
|
||||||
return
|
return os.path.splitext(self.audio_file.name)[-1].replace(".", "", 1)
|
||||||
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):
|
def get_file_size(self):
|
||||||
if self.audio_file:
|
if self.audio_file:
|
||||||
|
@ -823,6 +824,12 @@ class Upload(models.Model):
|
||||||
|
|
||||||
return version
|
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]
|
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"),
|
({"audio_file__filename": "test.mp3", "mimetype": None}, "mp3"),
|
||||||
({"mimetype": "audio/mpeg"}, "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/mpeg"}, "mp3"),
|
||||||
({"audio_file__filename": "test.None", "mimetype": "audio/flac"}, "flac"),
|
({"audio_file__filename": "test.None", "mimetype": "audio/flac"}, "flac"),
|
||||||
({"audio_file__filename": "test.None", "mimetype": "audio/x-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):
|
def test_upload_extension(factory_args, factories, expected):
|
||||||
upload = factories["music.Upload"].build(**factory_args)
|
upload = factories["music.Upload"].build(**factory_args)
|
||||||
|
|
||||||
assert upload.extension == expected
|
assert upload.extension == expected
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed None extension when downloading an in-place imported file (#621)
|
Loading…
Reference in New Issue