again
This commit is contained in:
parent
85206166c5
commit
3df80b30f4
|
@ -47,7 +47,7 @@ def create_data(super_user_name=None):
|
|||
|
||||
library = federation_factories.MusicLibraryFactory(
|
||||
actor=(super_user.actor if super_user else federation_factories.ActorFactory()),
|
||||
local=True,
|
||||
local=True if super_user else False,
|
||||
)
|
||||
uploads = music_factories.UploadFactory.create_batch(
|
||||
size=random.randint(3, 18),
|
||||
|
@ -113,7 +113,7 @@ def create_data(super_user_name=None):
|
|||
# my artist channel
|
||||
my_artist_library = federation_factories.MusicLibraryFactory(
|
||||
actor=(super_user.actor if super_user else federation_factories.ActorFactory()),
|
||||
local=True,
|
||||
local=True if super_user else False,
|
||||
)
|
||||
my_artist_channel = audio_factories.ChannelFactory(
|
||||
library=my_artist_library,
|
||||
|
|
|
@ -99,6 +99,7 @@ def migrate_libraries_to_playlist(apps, schema_editor):
|
|||
to_public_libs.append(library)
|
||||
|
||||
library.privacy_level = "me"
|
||||
library.playlist = playlist
|
||||
library.save()
|
||||
except Exception as e:
|
||||
print(f"An error occurred during library.playlist creation : {e}")
|
||||
|
@ -161,8 +162,7 @@ def check_succefull_migration(apps, schema_editor):
|
|||
|
||||
elif actor.playlists.filter(library__isnull=True).count() > 0:
|
||||
raise Exception(
|
||||
f"Incoherent playlist database state : all playlists do not have lib or too many libs\
|
||||
actor.playlists.filter(library__isnull=True).count() = {actor.playlists.filter(library__isnull=True).count()} "
|
||||
f"Incoherent playlist database state : all local playlists do not have lib or too many libs"
|
||||
)
|
||||
elif actor.libraries.count() - 3 != not_build_in_libs or (
|
||||
hasattr(actor, "channel") and actor.libraries.count() > 1
|
||||
|
@ -171,7 +171,7 @@ def check_succefull_migration(apps, schema_editor):
|
|||
f"Incoherent library database state, check for errors in log and share them to the funkwhale team. Migration was abordted to prevent data loss.\
|
||||
actor libs = {actor.libraries.count()} and acto not built-in lib = {not_build_in_libs} \
|
||||
and acto pl ={actor.playlists.count()} and not channel lib = {actor.libraries.filter(channel__isnull=False).count()} \
|
||||
and {actor.name} actor_playlist_lib {actor_playlist_lib}"
|
||||
and actor.nae = {actor.name}"
|
||||
)
|
||||
for playlist in Playlist.objects.all():
|
||||
if not federation_utils.is_local(playlist.fid):
|
||||
|
|
|
@ -104,7 +104,6 @@ def test_migrate_libraries_to_playlist(migrator):
|
|||
Library = music_apps.get_model("music", "Library")
|
||||
Upload = music_apps.get_model("music", "Upload")
|
||||
Playlist = music_apps.get_model("playlists", "Playlist")
|
||||
Plt = music_apps.get_model("playlists", "PlaylistTrack")
|
||||
|
||||
# Create data
|
||||
d = settings.FEDERATION_HOSTNAME
|
||||
|
@ -125,6 +124,15 @@ def test_migrate_libraries_to_playlist(migrator):
|
|||
uuid=uuid4(),
|
||||
description="This is a description",
|
||||
)
|
||||
Library.objects.create(
|
||||
name="me",
|
||||
actor=actor,
|
||||
creation_date=now(),
|
||||
privacy_level="me",
|
||||
uuid=uuid4(),
|
||||
description="This is a description",
|
||||
fid=f"http://{d}/mylocallob",
|
||||
)
|
||||
|
||||
library_not_local = Library.objects.create(
|
||||
name="This should not becane playlist name",
|
||||
|
@ -136,22 +144,6 @@ def test_migrate_libraries_to_playlist(migrator):
|
|||
description="This is a description recalling to eat the rich",
|
||||
)
|
||||
|
||||
playlist = Playlist.objects.create(
|
||||
name="This should becane a library name",
|
||||
fid="https://asupernotlocal.acab/federation/music/playlist/8505207e-45da-449a-9ec8-ed12a848fcea",
|
||||
actor=actor,
|
||||
creation_date=now(),
|
||||
privacy_level="everyone",
|
||||
uuid=uuid4(),
|
||||
)
|
||||
|
||||
playlist_not_local = Playlist.objects.create(
|
||||
name="This should not becane a library name",
|
||||
actor=target_actor,
|
||||
creation_date=now(),
|
||||
privacy_level="everyone",
|
||||
uuid=uuid4(),
|
||||
)
|
||||
Track.objects.create()
|
||||
Track.objects.create()
|
||||
track = Track.objects.create()
|
||||
|
@ -167,13 +159,29 @@ def test_migrate_libraries_to_playlist(migrator):
|
|||
Upload.objects.create(library=library_not_local, track=track),
|
||||
Upload.objects.create(library=library_not_local, track=track2),
|
||||
Upload.objects.create(library=library_not_local, track=track3),
|
||||
# Plt = music_apps.get_model("playlists", "PlaylistTrack")
|
||||
# playlist = Playlist.objects.create(
|
||||
# name="This should becane a library name",
|
||||
# fid="https://asupernotlocal.acab/federation/music/playlist/8505207e-45da-449a-9ec8-ed12a848fcea",
|
||||
# actor=actor,
|
||||
# creation_date=now(),
|
||||
# privacy_level="everyone",
|
||||
# uuid=uuid4(),
|
||||
# )
|
||||
|
||||
Plt.objects.create(playlist=playlist, track=track)
|
||||
Plt.objects.create(
|
||||
playlist=playlist_not_local,
|
||||
track=track,
|
||||
fid="https://asupernotlocal.acab/federation/music/playlistttrack/8505207e-",
|
||||
)
|
||||
# playlist_not_local = Playlist.objects.create(
|
||||
# name="This should not becane a library name",
|
||||
# actor=target_actor,
|
||||
# creation_date=now(),
|
||||
# privacy_level="everyone",
|
||||
# uuid=uuid4(),
|
||||
# )
|
||||
# Plt.objects.create(playlist=playlist, track=track)
|
||||
# Plt.objects.create(
|
||||
# playlist=playlist_not_local,
|
||||
# track=track,
|
||||
# fid="https://asupernotlocal.acab/federation/music/playlistttrack/8505207e-",
|
||||
# )
|
||||
|
||||
library_follow = LibraryFollow.objects.create(
|
||||
uuid=uuid4(),
|
||||
|
@ -204,6 +212,10 @@ def test_migrate_libraries_to_playlist(migrator):
|
|||
assert playlist.privacy_level == library.privacy_level
|
||||
assert playlist.description == library.description
|
||||
|
||||
# Verify Playlist me creation skipped
|
||||
assert not Playlist.objects.filter(name="me")
|
||||
assert playlist.actor.libraries.filter(name="me").count() == 1
|
||||
|
||||
# Verify PlaylistTrack creation
|
||||
playlist_tracks = PlaylistTrack.objects.filter(playlist=playlist).order_by("index")
|
||||
assert playlist_tracks.count() == 3
|
||||
|
|
Loading…
Reference in New Issue