mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 02:59:55 +02:00
Fix #777: Added a prune_library management command to remove obsolete metadata
This commit is contained in:
parent
96010917fb
commit
5916a1ba99
8 changed files with 388 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import pytest
|
||||
|
||||
from funkwhale_api.music.management.commands import fix_uploads
|
||||
from funkwhale_api.music.management.commands import prune_library
|
||||
|
||||
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
@ -73,3 +75,78 @@ def test_fix_uploads_mimetype(factories, mocker):
|
|||
|
||||
assert upload1.mimetype == "audio/mpeg"
|
||||
assert upload2.mimetype == "audio/something"
|
||||
|
||||
|
||||
def test_prune_library_dry_run(factories):
|
||||
prunable = factories["music.Track"]()
|
||||
not_prunable = factories["music.Track"]()
|
||||
c = prune_library.Command()
|
||||
options = {
|
||||
"prune_artists": True,
|
||||
"prune_albums": True,
|
||||
"prune_tracks": True,
|
||||
"exclude_favorites": False,
|
||||
"exclude_listenings": False,
|
||||
"exclude_playlists": False,
|
||||
"dry_run": True,
|
||||
}
|
||||
c.handle(**options)
|
||||
|
||||
for t in [prunable, not_prunable]:
|
||||
# nothing pruned, because dry run
|
||||
t.refresh_from_db()
|
||||
|
||||
|
||||
def test_prune_library(factories, mocker):
|
||||
prunable_track = factories["music.Track"]()
|
||||
not_prunable_track = factories["music.Track"]()
|
||||
prunable_tracks = prunable_track.__class__.objects.filter(pk=prunable_track.pk)
|
||||
get_prunable_tracks = mocker.patch(
|
||||
"funkwhale_api.music.tasks.get_prunable_tracks", return_value=prunable_tracks
|
||||
)
|
||||
|
||||
prunable_album = factories["music.Album"]()
|
||||
not_prunable_album = factories["music.Album"]()
|
||||
prunable_albums = prunable_album.__class__.objects.filter(pk=prunable_album.pk)
|
||||
get_prunable_albums = mocker.patch(
|
||||
"funkwhale_api.music.tasks.get_prunable_albums", return_value=prunable_albums
|
||||
)
|
||||
|
||||
prunable_artist = factories["music.Artist"]()
|
||||
not_prunable_artist = factories["music.Artist"]()
|
||||
prunable_artists = prunable_artist.__class__.objects.filter(pk=prunable_artist.pk)
|
||||
get_prunable_artists = mocker.patch(
|
||||
"funkwhale_api.music.tasks.get_prunable_artists", return_value=prunable_artists
|
||||
)
|
||||
|
||||
c = prune_library.Command()
|
||||
options = {
|
||||
"exclude_favorites": mocker.Mock(),
|
||||
"exclude_listenings": mocker.Mock(),
|
||||
"exclude_playlists": mocker.Mock(),
|
||||
"prune_artists": True,
|
||||
"prune_albums": True,
|
||||
"prune_tracks": True,
|
||||
"dry_run": False,
|
||||
}
|
||||
c.handle(**options)
|
||||
|
||||
get_prunable_tracks.assert_called_once_with(
|
||||
exclude_favorites=options["exclude_favorites"],
|
||||
exclude_listenings=options["exclude_listenings"],
|
||||
exclude_playlists=options["exclude_playlists"],
|
||||
)
|
||||
get_prunable_albums.assert_called_once()
|
||||
get_prunable_artists.assert_called_once()
|
||||
|
||||
with pytest.raises(prunable_track.DoesNotExist):
|
||||
prunable_track.refresh_from_db()
|
||||
|
||||
with pytest.raises(prunable_album.DoesNotExist):
|
||||
prunable_album.refresh_from_db()
|
||||
|
||||
with pytest.raises(prunable_artist.DoesNotExist):
|
||||
prunable_artist.refresh_from_db()
|
||||
|
||||
for o in [not_prunable_track, not_prunable_album, not_prunable_artist]:
|
||||
o.refresh_from_db()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue