Merge branch 'faster-ci' into 'develop'
Faster tests See merge request funkwhale/funkwhale!1063
This commit is contained in:
commit
2440550591
|
@ -86,6 +86,17 @@ class DomainFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
||||||
return self.service_actor
|
return self.service_actor
|
||||||
|
|
||||||
|
|
||||||
|
_CACHE = {}
|
||||||
|
|
||||||
|
|
||||||
|
def get_cached_key_pair():
|
||||||
|
try:
|
||||||
|
return _CACHE["keys"]
|
||||||
|
except KeyError:
|
||||||
|
_CACHE["keys"] = keys.get_key_pair()
|
||||||
|
return _CACHE["keys"]
|
||||||
|
|
||||||
|
|
||||||
@registry.register
|
@registry.register
|
||||||
class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
||||||
public_key = None
|
public_key = None
|
||||||
|
@ -111,11 +122,14 @@ class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
||||||
o.domain.name, o.preferred_username
|
o.domain.name, o.preferred_username
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
keys = factory.LazyFunction(keys.get_key_pair)
|
keys = factory.LazyFunction(get_cached_key_pair)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Actor
|
model = models.Actor
|
||||||
|
|
||||||
|
class Params:
|
||||||
|
with_real_keys = factory.Trait(keys=factory.LazyFunction(keys.get_key_pair),)
|
||||||
|
|
||||||
@factory.post_generation
|
@factory.post_generation
|
||||||
def local(self, create, extracted, **kwargs):
|
def local(self, create, extracted, **kwargs):
|
||||||
if not extracted and not kwargs:
|
if not extracted and not kwargs:
|
||||||
|
|
|
@ -64,7 +64,6 @@ class ArtistFactory(
|
||||||
mbid = factory.Faker("uuid4")
|
mbid = factory.Faker("uuid4")
|
||||||
fid = factory.Faker("federation_url")
|
fid = factory.Faker("federation_url")
|
||||||
playable = playable_factory("track__album__artist")
|
playable = playable_factory("track__album__artist")
|
||||||
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = "music.Artist"
|
model = "music.Artist"
|
||||||
|
@ -74,6 +73,9 @@ class ArtistFactory(
|
||||||
attributed_to=factory.SubFactory(federation_factories.ActorFactory)
|
attributed_to=factory.SubFactory(federation_factories.ActorFactory)
|
||||||
)
|
)
|
||||||
local = factory.Trait(fid=factory.Faker("federation_url", local=True))
|
local = factory.Trait(fid=factory.Faker("federation_url", local=True))
|
||||||
|
with_cover = factory.Trait(
|
||||||
|
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@registry.register
|
@registry.register
|
||||||
|
@ -83,7 +85,6 @@ class AlbumFactory(
|
||||||
title = factory.Faker("sentence", nb_words=3)
|
title = factory.Faker("sentence", nb_words=3)
|
||||||
mbid = factory.Faker("uuid4")
|
mbid = factory.Faker("uuid4")
|
||||||
release_date = factory.Faker("date_object")
|
release_date = factory.Faker("date_object")
|
||||||
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
|
|
||||||
artist = factory.SubFactory(ArtistFactory)
|
artist = factory.SubFactory(ArtistFactory)
|
||||||
release_group_id = factory.Faker("uuid4")
|
release_group_id = factory.Faker("uuid4")
|
||||||
fid = factory.Faker("federation_url")
|
fid = factory.Faker("federation_url")
|
||||||
|
@ -100,6 +101,9 @@ class AlbumFactory(
|
||||||
local = factory.Trait(
|
local = factory.Trait(
|
||||||
fid=factory.Faker("federation_url", local=True), artist__local=True
|
fid=factory.Faker("federation_url", local=True), artist__local=True
|
||||||
)
|
)
|
||||||
|
with_cover = factory.Trait(
|
||||||
|
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@registry.register
|
@registry.register
|
||||||
|
@ -112,7 +116,6 @@ class TrackFactory(
|
||||||
album = factory.SubFactory(AlbumFactory)
|
album = factory.SubFactory(AlbumFactory)
|
||||||
position = 1
|
position = 1
|
||||||
playable = playable_factory("track")
|
playable = playable_factory("track")
|
||||||
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = "music.Track"
|
model = "music.Track"
|
||||||
|
@ -125,6 +128,9 @@ class TrackFactory(
|
||||||
local = factory.Trait(
|
local = factory.Trait(
|
||||||
fid=factory.Faker("federation_url", local=True), album__local=True
|
fid=factory.Faker("federation_url", local=True), album__local=True
|
||||||
)
|
)
|
||||||
|
with_cover = factory.Trait(
|
||||||
|
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
|
||||||
|
)
|
||||||
|
|
||||||
@factory.post_generation
|
@factory.post_generation
|
||||||
def artist(self, created, extracted, **kwargs):
|
def artist(self, created, extracted, **kwargs):
|
||||||
|
|
|
@ -290,6 +290,7 @@ def test_rss_item_serializer(factories):
|
||||||
track__description=description,
|
track__description=description,
|
||||||
track__disc_number=4,
|
track__disc_number=4,
|
||||||
track__position=42,
|
track__position=42,
|
||||||
|
track__with_cover=True,
|
||||||
)
|
)
|
||||||
setattr(
|
setattr(
|
||||||
upload.track,
|
upload.track,
|
||||||
|
@ -339,6 +340,7 @@ def test_rss_channel_serializer(factories):
|
||||||
artist__set_tags=["pop", "rock"],
|
artist__set_tags=["pop", "rock"],
|
||||||
artist__description=description,
|
artist__description=description,
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
|
artist__with_cover=True,
|
||||||
)
|
)
|
||||||
setattr(
|
setattr(
|
||||||
channel.artist,
|
channel.artist,
|
||||||
|
|
|
@ -11,7 +11,9 @@ from funkwhale_api.music import serializers
|
||||||
|
|
||||||
@pytest.mark.parametrize("attribute", ["uuid", "actor.full_username"])
|
@pytest.mark.parametrize("attribute", ["uuid", "actor.full_username"])
|
||||||
def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, settings):
|
def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, settings):
|
||||||
channel = factories["audio.Channel"](library__privacy_level="everyone")
|
channel = factories["audio.Channel"](
|
||||||
|
library__privacy_level="everyone", artist__with_cover=True
|
||||||
|
)
|
||||||
factories["music.Upload"](playable=True, library=channel.library)
|
factories["music.Upload"](playable=True, library=channel.library)
|
||||||
url = "/channels/{}".format(utils.recursive_getattr(channel, attribute))
|
url = "/channels/{}".format(utils.recursive_getattr(channel, attribute))
|
||||||
detail_url = "/channels/{}".format(channel.actor.full_username)
|
detail_url = "/channels/{}".format(channel.actor.full_username)
|
||||||
|
@ -77,7 +79,7 @@ def test_channel_detail(attribute, spa_html, no_api_auth, client, factories, set
|
||||||
def test_oembed_channel(factories, no_api_auth, api_client, settings):
|
def test_oembed_channel(factories, no_api_auth, api_client, settings):
|
||||||
settings.FUNKWHALE_URL = "http://test"
|
settings.FUNKWHALE_URL = "http://test"
|
||||||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||||
channel = factories["audio.Channel"]()
|
channel = factories["audio.Channel"](artist__with_cover=True)
|
||||||
artist = channel.artist
|
artist = channel.artist
|
||||||
url = reverse("api:v1:oembed")
|
url = reverse("api:v1:oembed")
|
||||||
obj_url = "https://test.com/channels/{}".format(channel.uuid)
|
obj_url = "https://test.com/channels/{}".format(channel.uuid)
|
||||||
|
|
|
@ -55,7 +55,9 @@ def test_channel_create(logged_in_api_client):
|
||||||
"field", ["uuid", "actor.preferred_username", "actor.full_username"],
|
"field", ["uuid", "actor.preferred_username", "actor.full_username"],
|
||||||
)
|
)
|
||||||
def test_channel_detail(field, factories, logged_in_api_client):
|
def test_channel_detail(field, factories, logged_in_api_client):
|
||||||
channel = factories["audio.Channel"](artist__description=None, local=True)
|
channel = factories["audio.Channel"](
|
||||||
|
artist__description=None, local=True, artist__with_cover=True
|
||||||
|
)
|
||||||
|
|
||||||
url = reverse(
|
url = reverse(
|
||||||
"api:v1:channels-detail",
|
"api:v1:channels-detail",
|
||||||
|
@ -74,7 +76,9 @@ def test_channel_detail(field, factories, logged_in_api_client):
|
||||||
|
|
||||||
|
|
||||||
def test_channel_list(factories, logged_in_api_client):
|
def test_channel_list(factories, logged_in_api_client):
|
||||||
channel = factories["audio.Channel"](artist__description=None)
|
channel = factories["audio.Channel"](
|
||||||
|
artist__description=None, artist__with_cover=True
|
||||||
|
)
|
||||||
setattr(channel.artist, "_tracks_count", 0)
|
setattr(channel.artist, "_tracks_count", 0)
|
||||||
setattr(channel.artist, "_prefetched_tagged_items", [])
|
setattr(channel.artist, "_prefetched_tagged_items", [])
|
||||||
url = reverse("api:v1:channels-list")
|
url = reverse("api:v1:channels-list")
|
||||||
|
@ -216,7 +220,9 @@ def test_channel_unsubscribe(factories, logged_in_api_client):
|
||||||
|
|
||||||
def test_subscriptions_list(factories, logged_in_api_client):
|
def test_subscriptions_list(factories, logged_in_api_client):
|
||||||
actor = logged_in_api_client.user.create_actor()
|
actor = logged_in_api_client.user.create_actor()
|
||||||
channel = factories["audio.Channel"](artist__description=None)
|
channel = factories["audio.Channel"](
|
||||||
|
artist__description=None, artist__with_cover=True
|
||||||
|
)
|
||||||
subscription = factories["audio.Subscription"](target=channel.actor, actor=actor)
|
subscription = factories["audio.Subscription"](target=channel.actor, actor=actor)
|
||||||
setattr(subscription.target.channel.artist, "_tracks_count", 0)
|
setattr(subscription.target.channel.artist, "_tracks_count", 0)
|
||||||
setattr(subscription.target.channel.artist, "_prefetched_tagged_items", [])
|
setattr(subscription.target.channel.artist, "_prefetched_tagged_items", [])
|
||||||
|
|
|
@ -64,7 +64,9 @@ def test_attachment(factories, now):
|
||||||
@pytest.mark.parametrize("args, expected", [([], [0]), ([True], [0]), ([False], [1])])
|
@pytest.mark.parametrize("args, expected", [([], [0]), ([True], [0]), ([False], [1])])
|
||||||
def test_attachment_queryset_attached(args, expected, factories, queryset_equal_list):
|
def test_attachment_queryset_attached(args, expected, factories, queryset_equal_list):
|
||||||
attachments = [
|
attachments = [
|
||||||
factories["music.Album"](artist__attachment_cover=None).attachment_cover,
|
factories["music.Album"](
|
||||||
|
with_cover=True, artist__attachment_cover=None
|
||||||
|
).attachment_cover,
|
||||||
factories["common.Attachment"](),
|
factories["common.Attachment"](),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ def test_prune_unattached_attachments(factories, settings, now):
|
||||||
)
|
)
|
||||||
attachments = [
|
attachments = [
|
||||||
# attached, kept
|
# attached, kept
|
||||||
factories["music.Album"]().attachment_cover,
|
factories["music.Album"](with_cover=True).attachment_cover,
|
||||||
# recent, kept
|
# recent, kept
|
||||||
factories["common.Attachment"](),
|
factories["common.Attachment"](),
|
||||||
# too old, pruned
|
# too old, pruned
|
||||||
|
|
|
@ -141,7 +141,7 @@ def test_render_html(text, content_type, permissive, expected):
|
||||||
|
|
||||||
|
|
||||||
def test_attach_file_url(factories):
|
def test_attach_file_url(factories):
|
||||||
album = factories["music.Album"]()
|
album = factories["music.Album"](with_cover=True)
|
||||||
existing_attachment = album.attachment_cover
|
existing_attachment = album.attachment_cover
|
||||||
assert existing_attachment is not None
|
assert existing_attachment is not None
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ def test_attach_file_url(factories):
|
||||||
|
|
||||||
|
|
||||||
def test_attach_file_url_fetch(factories, r_mock):
|
def test_attach_file_url_fetch(factories, r_mock):
|
||||||
album = factories["music.Album"]()
|
album = factories["music.Album"](with_cover=True)
|
||||||
|
|
||||||
data = {"mimetype": "image/jpeg", "url": "https://example.com/test.jpg"}
|
data = {"mimetype": "image/jpeg", "url": "https://example.com/test.jpg"}
|
||||||
r_mock.get(data["url"], body=io.BytesIO(b"content"))
|
r_mock.get(data["url"], body=io.BytesIO(b"content"))
|
||||||
|
|
|
@ -29,8 +29,6 @@ def test_user_can_get_his_favorites(
|
||||||
favorite, context={"request": request}
|
favorite, context={"request": request}
|
||||||
).data
|
).data
|
||||||
]
|
]
|
||||||
expected[0]["track"]["artist"].pop("cover")
|
|
||||||
expected[0]["track"]["album"]["artist"].pop("cover")
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.data["results"] == expected
|
assert response.data["results"] == expected
|
||||||
|
|
|
@ -321,7 +321,9 @@ def test_outbox_create_audio_channel(factories, mocker):
|
||||||
|
|
||||||
def test_inbox_create_audio(factories, mocker):
|
def test_inbox_create_audio(factories, mocker):
|
||||||
activity = factories["federation.Activity"]()
|
activity = factories["federation.Activity"]()
|
||||||
upload = factories["music.Upload"](bitrate=42, duration=55)
|
upload = factories["music.Upload"](
|
||||||
|
bitrate=42, duration=55, track__album__with_cover=True
|
||||||
|
)
|
||||||
payload = {
|
payload = {
|
||||||
"@context": jsonld.get_default_context(),
|
"@context": jsonld.get_default_context(),
|
||||||
"type": "Create",
|
"type": "Create",
|
||||||
|
|
|
@ -646,7 +646,7 @@ def test_music_library_serializer_from_ap_update(factories, mocker):
|
||||||
def test_activity_pub_artist_serializer_to_ap(factories):
|
def test_activity_pub_artist_serializer_to_ap(factories):
|
||||||
content = factories["common.Content"]()
|
content = factories["common.Content"]()
|
||||||
artist = factories["music.Artist"](
|
artist = factories["music.Artist"](
|
||||||
description=content, attributed=True, set_tags=["Punk", "Rock"]
|
description=content, attributed=True, set_tags=["Punk", "Rock"], with_cover=True
|
||||||
)
|
)
|
||||||
expected = {
|
expected = {
|
||||||
"@context": jsonld.get_default_context(),
|
"@context": jsonld.get_default_context(),
|
||||||
|
@ -756,7 +756,7 @@ def test_activity_pub_artist_serializer_from_ap_update(factories, faker, now, mo
|
||||||
def test_activity_pub_album_serializer_to_ap(factories):
|
def test_activity_pub_album_serializer_to_ap(factories):
|
||||||
content = factories["common.Content"]()
|
content = factories["common.Content"]()
|
||||||
album = factories["music.Album"](
|
album = factories["music.Album"](
|
||||||
description=content, attributed=True, set_tags=["Punk", "Rock"]
|
description=content, attributed=True, set_tags=["Punk", "Rock"], with_cover=True
|
||||||
)
|
)
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -886,6 +886,7 @@ def test_activity_pub_track_serializer_to_ap(factories):
|
||||||
disc_number=3,
|
disc_number=3,
|
||||||
attributed=True,
|
attributed=True,
|
||||||
set_tags=["Punk", "Rock"],
|
set_tags=["Punk", "Rock"],
|
||||||
|
with_cover=True,
|
||||||
)
|
)
|
||||||
expected = {
|
expected = {
|
||||||
"@context": jsonld.get_default_context(),
|
"@context": jsonld.get_default_context(),
|
||||||
|
@ -1210,7 +1211,7 @@ def test_activity_pub_upload_serializer_from_ap(factories, mocker, r_mock):
|
||||||
|
|
||||||
def test_activity_pub_upload_serializer_from_ap_update(factories, mocker, now, r_mock):
|
def test_activity_pub_upload_serializer_from_ap_update(factories, mocker, now, r_mock):
|
||||||
library = factories["music.Library"]()
|
library = factories["music.Library"]()
|
||||||
upload = factories["music.Upload"](library=library)
|
upload = factories["music.Upload"](library=library, track__album__with_cover=True)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"@context": jsonld.get_default_context(),
|
"@context": jsonld.get_default_context(),
|
||||||
|
@ -1393,7 +1394,9 @@ def test_track_serializer_update_license(factories):
|
||||||
|
|
||||||
|
|
||||||
def test_channel_actor_serializer(factories):
|
def test_channel_actor_serializer(factories):
|
||||||
channel = factories["audio.Channel"](actor__attachment_icon=None)
|
channel = factories["audio.Channel"](
|
||||||
|
actor__attachment_icon=None, artist__with_cover=True
|
||||||
|
)
|
||||||
|
|
||||||
serializer = serializers.ActorSerializer(channel.actor)
|
serializer = serializers.ActorSerializer(channel.actor)
|
||||||
expected_url = [
|
expected_url = [
|
||||||
|
|
|
@ -286,7 +286,7 @@ def test_instance_policy_serializer_purges_target_actor(
|
||||||
|
|
||||||
|
|
||||||
def test_manage_artist_serializer(factories, now, to_api_date):
|
def test_manage_artist_serializer(factories, now, to_api_date):
|
||||||
artist = factories["music.Artist"](attributed=True)
|
artist = factories["music.Artist"](attributed=True, with_cover=True)
|
||||||
track = factories["music.Track"](artist=artist)
|
track = factories["music.Track"](artist=artist)
|
||||||
album = factories["music.Album"](artist=artist)
|
album = factories["music.Album"](artist=artist)
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -331,7 +331,7 @@ def test_manage_nested_track_serializer(factories, now, to_api_date):
|
||||||
|
|
||||||
|
|
||||||
def test_manage_nested_album_serializer(factories, now, to_api_date):
|
def test_manage_nested_album_serializer(factories, now, to_api_date):
|
||||||
album = factories["music.Album"]()
|
album = factories["music.Album"](with_cover=True)
|
||||||
setattr(album, "tracks_count", 44)
|
setattr(album, "tracks_count", 44)
|
||||||
expected = {
|
expected = {
|
||||||
"id": album.id,
|
"id": album.id,
|
||||||
|
@ -367,7 +367,7 @@ def test_manage_nested_artist_serializer(factories, now, to_api_date):
|
||||||
|
|
||||||
|
|
||||||
def test_manage_album_serializer(factories, now, to_api_date):
|
def test_manage_album_serializer(factories, now, to_api_date):
|
||||||
album = factories["music.Album"](attributed=True)
|
album = factories["music.Album"](attributed=True, with_cover=True)
|
||||||
track = factories["music.Track"](album=album)
|
track = factories["music.Track"](album=album)
|
||||||
expected = {
|
expected = {
|
||||||
"id": album.id,
|
"id": album.id,
|
||||||
|
@ -392,7 +392,7 @@ def test_manage_album_serializer(factories, now, to_api_date):
|
||||||
|
|
||||||
|
|
||||||
def test_manage_track_serializer(factories, now, to_api_date):
|
def test_manage_track_serializer(factories, now, to_api_date):
|
||||||
track = factories["music.Track"](attributed=True)
|
track = factories["music.Track"](attributed=True, with_cover=True)
|
||||||
setattr(track, "uploads_count", 44)
|
setattr(track, "uploads_count", 44)
|
||||||
expected = {
|
expected = {
|
||||||
"id": track.id,
|
"id": track.id,
|
||||||
|
|
|
@ -182,7 +182,7 @@ def test_perm_checkers_can_approve(
|
||||||
@pytest.mark.parametrize("factory_name", ["music.Artist", "music.Track", "music.Album"])
|
@pytest.mark.parametrize("factory_name", ["music.Artist", "music.Track", "music.Album"])
|
||||||
def test_mutation_set_attachment_cover(factory_name, factories, now, mocker):
|
def test_mutation_set_attachment_cover(factory_name, factories, now, mocker):
|
||||||
new_attachment = factories["common.Attachment"](actor__local=True)
|
new_attachment = factories["common.Attachment"](actor__local=True)
|
||||||
obj = factories[factory_name]()
|
obj = factories[factory_name](with_cover=True)
|
||||||
old_attachment = obj.attachment_cover
|
old_attachment = obj.attachment_cover
|
||||||
mutation = factories["common.Mutation"](
|
mutation = factories["common.Mutation"](
|
||||||
type="update", target=obj, payload={"cover": new_attachment.uuid}
|
type="update", target=obj, payload={"cover": new_attachment.uuid}
|
||||||
|
|
|
@ -32,7 +32,7 @@ def test_license_serializer():
|
||||||
|
|
||||||
|
|
||||||
def test_artist_album_serializer(factories, to_api_date):
|
def test_artist_album_serializer(factories, to_api_date):
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
album = track.album
|
album = track.album
|
||||||
album = album.__class__.objects.with_tracks_count().get(pk=album.pk)
|
album = album.__class__.objects.with_tracks_count().get(pk=album.pk)
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -55,7 +55,9 @@ def test_artist_album_serializer(factories, to_api_date):
|
||||||
|
|
||||||
def test_artist_with_albums_serializer(factories, to_api_date):
|
def test_artist_with_albums_serializer(factories, to_api_date):
|
||||||
actor = factories["federation.Actor"]()
|
actor = factories["federation.Actor"]()
|
||||||
track = factories["music.Track"](album__artist__attributed_to=actor)
|
track = factories["music.Track"](
|
||||||
|
album__artist__attributed_to=actor, album__artist__with_cover=True
|
||||||
|
)
|
||||||
artist = track.artist
|
artist = track.artist
|
||||||
artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
|
artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
|
||||||
album = list(artist.albums.all())[0]
|
album = list(artist.albums.all())[0]
|
||||||
|
@ -81,7 +83,7 @@ def test_artist_with_albums_serializer(factories, to_api_date):
|
||||||
|
|
||||||
def test_artist_with_albums_serializer_channel(factories, to_api_date):
|
def test_artist_with_albums_serializer_channel(factories, to_api_date):
|
||||||
actor = factories["federation.Actor"]()
|
actor = factories["federation.Actor"]()
|
||||||
channel = factories["audio.Channel"](attributed_to=actor)
|
channel = factories["audio.Channel"](attributed_to=actor, artist__with_cover=True)
|
||||||
track = factories["music.Track"](album__artist=channel.artist)
|
track = factories["music.Track"](album__artist=channel.artist)
|
||||||
artist = track.artist
|
artist = track.artist
|
||||||
artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
|
artist = artist.__class__.objects.with_albums().get(pk=artist.pk)
|
||||||
|
@ -195,7 +197,9 @@ def test_upload_owner_serializer(factories, to_api_date):
|
||||||
|
|
||||||
def test_album_serializer(factories, to_api_date):
|
def test_album_serializer(factories, to_api_date):
|
||||||
actor = factories["federation.Actor"]()
|
actor = factories["federation.Actor"]()
|
||||||
track1 = factories["music.Track"](position=2, album__attributed_to=actor)
|
track1 = factories["music.Track"](
|
||||||
|
position=2, album__attributed_to=actor, album__with_cover=True
|
||||||
|
)
|
||||||
track2 = factories["music.Track"](position=1, album=track1.album)
|
track2 = factories["music.Track"](position=1, album=track1.album)
|
||||||
album = track1.album
|
album = track1.album
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -215,8 +219,6 @@ def test_album_serializer(factories, to_api_date):
|
||||||
}
|
}
|
||||||
serializer = serializers.AlbumSerializer(album)
|
serializer = serializers.AlbumSerializer(album)
|
||||||
|
|
||||||
for t in expected["tracks"]:
|
|
||||||
t["artist"].pop("cover")
|
|
||||||
assert serializer.data == expected
|
assert serializer.data == expected
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,6 +238,7 @@ def test_track_serializer(factories, to_api_date):
|
||||||
track__copyright="test",
|
track__copyright="test",
|
||||||
track__disc_number=2,
|
track__disc_number=2,
|
||||||
track__attributed_to=actor,
|
track__attributed_to=actor,
|
||||||
|
track__with_cover=True,
|
||||||
)
|
)
|
||||||
track = upload.track
|
track = upload.track
|
||||||
setattr(track, "playable_uploads", [upload])
|
setattr(track, "playable_uploads", [upload])
|
||||||
|
|
|
@ -8,7 +8,10 @@ from funkwhale_api.music import serializers
|
||||||
|
|
||||||
def test_library_track(spa_html, no_api_auth, client, factories, settings):
|
def test_library_track(spa_html, no_api_auth, client, factories, settings):
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
playable=True, track__disc_number=1, track__attachment_cover=None
|
playable=True,
|
||||||
|
track__disc_number=1,
|
||||||
|
track__attachment_cover=None,
|
||||||
|
track__album__with_cover=True,
|
||||||
)
|
)
|
||||||
track = upload.track
|
track = upload.track
|
||||||
url = "/library/tracks/{}".format(track.pk)
|
url = "/library/tracks/{}".format(track.pk)
|
||||||
|
@ -93,7 +96,9 @@ def test_library_track(spa_html, no_api_auth, client, factories, settings):
|
||||||
|
|
||||||
|
|
||||||
def test_library_album(spa_html, no_api_auth, client, factories, settings):
|
def test_library_album(spa_html, no_api_auth, client, factories, settings):
|
||||||
track = factories["music.Upload"](playable=True, track__disc_number=1).track
|
track = factories["music.Upload"](
|
||||||
|
playable=True, track__disc_number=1, track__album__with_cover=True
|
||||||
|
).track
|
||||||
album = track.album
|
album = track.album
|
||||||
url = "/library/albums/{}".format(album.pk)
|
url = "/library/albums/{}".format(album.pk)
|
||||||
|
|
||||||
|
@ -159,7 +164,7 @@ def test_library_album(spa_html, no_api_auth, client, factories, settings):
|
||||||
|
|
||||||
|
|
||||||
def test_library_artist(spa_html, no_api_auth, client, factories, settings):
|
def test_library_artist(spa_html, no_api_auth, client, factories, settings):
|
||||||
album = factories["music.Album"]()
|
album = factories["music.Album"](with_cover=True)
|
||||||
factories["music.Upload"](playable=True, track__album=album)
|
factories["music.Upload"](playable=True, track__album=album)
|
||||||
artist = album.artist
|
artist = album.artist
|
||||||
url = "/library/artists/{}".format(artist.pk)
|
url = "/library/artists/{}".format(artist.pk)
|
||||||
|
@ -214,7 +219,9 @@ def test_library_artist(spa_html, no_api_auth, client, factories, settings):
|
||||||
|
|
||||||
def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
|
def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
|
||||||
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
||||||
track = factories["music.Upload"](playable=True).track
|
track = factories["music.Upload"](
|
||||||
|
playable=True, track__album__with_cover=True
|
||||||
|
).track
|
||||||
playlist.insert_many([track])
|
playlist.insert_many([track])
|
||||||
|
|
||||||
url = "/library/playlists/{}".format(playlist.pk)
|
url = "/library/playlists/{}".format(playlist.pk)
|
||||||
|
|
|
@ -379,7 +379,7 @@ def test_upload_import_get_audio_data(factories, mocker):
|
||||||
"funkwhale_api.music.models.Upload.get_audio_data",
|
"funkwhale_api.music.models.Upload.get_audio_data",
|
||||||
return_value={"size": 23, "duration": 42, "bitrate": 66},
|
return_value={"size": 23, "duration": 42, "bitrate": 66},
|
||||||
)
|
)
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
track=None, import_metadata={"funkwhale": {"track": {"uuid": track.uuid}}}
|
track=None, import_metadata={"funkwhale": {"track": {"uuid": track.uuid}}}
|
||||||
)
|
)
|
||||||
|
@ -459,7 +459,7 @@ def test_process_upload_picks_ignore_non_pending_uploads(import_status, factorie
|
||||||
|
|
||||||
|
|
||||||
def test_upload_import_track_uuid(now, factories):
|
def test_upload_import_track_uuid(now, factories):
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
track=None, import_metadata={"funkwhale": {"track": {"uuid": track.uuid}}}
|
track=None, import_metadata={"funkwhale": {"track": {"uuid": track.uuid}}}
|
||||||
)
|
)
|
||||||
|
@ -475,7 +475,7 @@ def test_upload_import_track_uuid(now, factories):
|
||||||
|
|
||||||
def test_upload_import_skip_federation(now, factories, mocker):
|
def test_upload_import_skip_federation(now, factories, mocker):
|
||||||
outbox = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
|
outbox = mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
track=None,
|
track=None,
|
||||||
import_metadata={
|
import_metadata={
|
||||||
|
@ -493,7 +493,7 @@ def test_upload_import_skip_federation(now, factories, mocker):
|
||||||
|
|
||||||
def test_upload_import_skip_broadcast(now, factories, mocker):
|
def test_upload_import_skip_broadcast(now, factories, mocker):
|
||||||
group_send = mocker.patch("funkwhale_api.common.channels.group_send")
|
group_send = mocker.patch("funkwhale_api.common.channels.group_send")
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
library__actor__local=True,
|
library__actor__local=True,
|
||||||
track=None,
|
track=None,
|
||||||
|
@ -792,6 +792,7 @@ def test_scan_page_fetches_page_and_creates_tracks(now, mocker, factories, r_moc
|
||||||
bitrate=66,
|
bitrate=66,
|
||||||
duration=99,
|
duration=99,
|
||||||
library=scan.library,
|
library=scan.library,
|
||||||
|
track__album__with_cover=True,
|
||||||
)
|
)
|
||||||
for i in range(5)
|
for i in range(5)
|
||||||
]
|
]
|
||||||
|
@ -1019,7 +1020,7 @@ def test_get_track_from_import_metadata_with_forced_values_album(
|
||||||
factories, mocker, faker
|
factories, mocker, faker
|
||||||
):
|
):
|
||||||
channel = factories["audio.Channel"]()
|
channel = factories["audio.Channel"]()
|
||||||
album = factories["music.Album"](artist=channel.artist)
|
album = factories["music.Album"](artist=channel.artist, with_cover=True)
|
||||||
|
|
||||||
forced_values = {
|
forced_values = {
|
||||||
"title": "Real title",
|
"title": "Real title",
|
||||||
|
@ -1088,7 +1089,7 @@ def test_process_channel_upload_forces_artist_and_attributed_to(
|
||||||
|
|
||||||
|
|
||||||
def test_process_upload_uses_import_metadata_if_valid(factories, mocker):
|
def test_process_upload_uses_import_metadata_if_valid(factories, mocker):
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
import_metadata = {"title": "hello", "funkwhale": {"foo": "bar"}}
|
import_metadata = {"title": "hello", "funkwhale": {"foo": "bar"}}
|
||||||
upload = factories["music.Upload"](track=None, import_metadata=import_metadata)
|
upload = factories["music.Upload"](track=None, import_metadata=import_metadata)
|
||||||
get_track_from_import_metadata = mocker.patch.object(
|
get_track_from_import_metadata = mocker.patch.object(
|
||||||
|
@ -1113,7 +1114,7 @@ def test_process_upload_uses_import_metadata_if_valid(factories, mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_process_upload_skips_import_metadata_if_invalid(factories, mocker):
|
def test_process_upload_skips_import_metadata_if_invalid(factories, mocker):
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
import_metadata = {"title": None, "funkwhale": {"foo": "bar"}}
|
import_metadata = {"title": None, "funkwhale": {"foo": "bar"}}
|
||||||
upload = factories["music.Upload"](track=None, import_metadata=import_metadata)
|
upload = factories["music.Upload"](track=None, import_metadata=import_metadata)
|
||||||
get_track_from_import_metadata = mocker.patch.object(
|
get_track_from_import_metadata = mocker.patch.object(
|
||||||
|
|
|
@ -979,7 +979,7 @@ def test_detail_license(api_client, preferences):
|
||||||
def test_oembed_track(factories, no_api_auth, api_client, settings):
|
def test_oembed_track(factories, no_api_auth, api_client, settings):
|
||||||
settings.FUNKWHALE_URL = "http://test"
|
settings.FUNKWHALE_URL = "http://test"
|
||||||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
url = reverse("api:v1:oembed")
|
url = reverse("api:v1:oembed")
|
||||||
track_url = "https://test.com/library/tracks/{}".format(track.pk)
|
track_url = "https://test.com/library/tracks/{}".format(track.pk)
|
||||||
iframe_src = "http://embed?type=track&id={}".format(track.pk)
|
iframe_src = "http://embed?type=track&id={}".format(track.pk)
|
||||||
|
@ -1014,7 +1014,7 @@ def test_oembed_track(factories, no_api_auth, api_client, settings):
|
||||||
def test_oembed_album(factories, no_api_auth, api_client, settings):
|
def test_oembed_album(factories, no_api_auth, api_client, settings):
|
||||||
settings.FUNKWHALE_URL = "http://test"
|
settings.FUNKWHALE_URL = "http://test"
|
||||||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
album = track.album
|
album = track.album
|
||||||
url = reverse("api:v1:oembed")
|
url = reverse("api:v1:oembed")
|
||||||
album_url = "https://test.com/library/albums/{}".format(album.pk)
|
album_url = "https://test.com/library/albums/{}".format(album.pk)
|
||||||
|
@ -1050,7 +1050,7 @@ def test_oembed_album(factories, no_api_auth, api_client, settings):
|
||||||
def test_oembed_artist(factories, no_api_auth, api_client, settings):
|
def test_oembed_artist(factories, no_api_auth, api_client, settings):
|
||||||
settings.FUNKWHALE_URL = "http://test"
|
settings.FUNKWHALE_URL = "http://test"
|
||||||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||||
track = factories["music.Track"]()
|
track = factories["music.Track"](album__with_cover=True)
|
||||||
album = track.album
|
album = track.album
|
||||||
artist = track.artist
|
artist = track.artist
|
||||||
url = reverse("api:v1:oembed")
|
url = reverse("api:v1:oembed")
|
||||||
|
@ -1088,7 +1088,9 @@ def test_oembed_playlist(factories, no_api_auth, api_client, settings):
|
||||||
settings.FUNKWHALE_URL = "http://test"
|
settings.FUNKWHALE_URL = "http://test"
|
||||||
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
settings.FUNKWHALE_EMBED_URL = "http://embed"
|
||||||
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
||||||
track = factories["music.Upload"](playable=True).track
|
track = factories["music.Upload"](
|
||||||
|
playable=True, track__album__with_cover=True
|
||||||
|
).track
|
||||||
playlist.insert_many([track])
|
playlist.insert_many([track])
|
||||||
url = reverse("api:v1:oembed")
|
url = reverse("api:v1:oembed")
|
||||||
playlist_url = "https://test.com/library/playlists/{}".format(playlist.pk)
|
playlist_url = "https://test.com/library/playlists/{}".format(playlist.pk)
|
||||||
|
@ -1307,12 +1309,6 @@ def test_search_get(use_fts, settings, logged_in_api_client, factories):
|
||||||
"tracks": [serializers.TrackSerializer(track).data],
|
"tracks": [serializers.TrackSerializer(track).data],
|
||||||
"tags": [views.TagSerializer(tag).data],
|
"tags": [views.TagSerializer(tag).data],
|
||||||
}
|
}
|
||||||
for album in expected["albums"]:
|
|
||||||
album["artist"].pop("cover")
|
|
||||||
|
|
||||||
for track in expected["tracks"]:
|
|
||||||
track["artist"].pop("cover")
|
|
||||||
track["album"]["artist"].pop("cover")
|
|
||||||
|
|
||||||
response = logged_in_api_client.get(url, {"q": "foo"})
|
response = logged_in_api_client.get(url, {"q": "foo"})
|
||||||
|
|
||||||
|
@ -1380,7 +1376,7 @@ def test_detail_includes_description_key(
|
||||||
|
|
||||||
def test_channel_owner_can_create_album(factories, logged_in_api_client):
|
def test_channel_owner_can_create_album(factories, logged_in_api_client):
|
||||||
actor = logged_in_api_client.user.create_actor()
|
actor = logged_in_api_client.user.create_actor()
|
||||||
channel = factories["audio.Channel"](attributed_to=actor)
|
channel = factories["audio.Channel"](attributed_to=actor, artist__with_cover=True)
|
||||||
attachment = factories["common.Attachment"](actor=actor)
|
attachment = factories["common.Attachment"](actor=actor)
|
||||||
url = reverse("api:v1:albums-list")
|
url = reverse("api:v1:albums-list")
|
||||||
|
|
||||||
|
|
|
@ -93,13 +93,13 @@ def test_update_insert_is_called_with_duplicate_override_when_duplicates_allowed
|
||||||
|
|
||||||
def test_playlist_serializer_include_covers(factories, api_request):
|
def test_playlist_serializer_include_covers(factories, api_request):
|
||||||
playlist = factories["playlists.Playlist"]()
|
playlist = factories["playlists.Playlist"]()
|
||||||
t1 = factories["music.Track"]()
|
t1 = factories["music.Track"](album__with_cover=True)
|
||||||
t2 = factories["music.Track"]()
|
t2 = factories["music.Track"](album__with_cover=True)
|
||||||
t3 = factories["music.Track"](album__attachment_cover=None)
|
t3 = factories["music.Track"](album__attachment_cover=None)
|
||||||
t4 = factories["music.Track"]()
|
t4 = factories["music.Track"](album__with_cover=True)
|
||||||
t5 = factories["music.Track"]()
|
t5 = factories["music.Track"](album__with_cover=True)
|
||||||
t6 = factories["music.Track"]()
|
t6 = factories["music.Track"](album__with_cover=True)
|
||||||
t7 = factories["music.Track"]()
|
t7 = factories["music.Track"](album__with_cover=True)
|
||||||
|
|
||||||
playlist.insert_many([t1, t2, t3, t4, t5, t6, t7])
|
playlist.insert_many([t1, t2, t3, t4, t5, t6, t7])
|
||||||
request = api_request.get("/")
|
request = api_request.get("/")
|
||||||
|
|
|
@ -157,8 +157,6 @@ def test_can_list_tracks_from_playlist(level, factories, logged_in_api_client):
|
||||||
url = reverse("api:v1:playlists-tracks", kwargs={"pk": plt.playlist.pk})
|
url = reverse("api:v1:playlists-tracks", kwargs={"pk": plt.playlist.pk})
|
||||||
response = logged_in_api_client.get(url)
|
response = logged_in_api_client.get(url)
|
||||||
serialized_plt = serializers.PlaylistTrackSerializer(plt).data
|
serialized_plt = serializers.PlaylistTrackSerializer(plt).data
|
||||||
serialized_plt["track"]["artist"].pop("cover")
|
|
||||||
serialized_plt["track"]["album"]["artist"].pop("cover")
|
|
||||||
|
|
||||||
assert response.data["count"] == 1
|
assert response.data["count"] == 1
|
||||||
assert response.data["results"][0] == serialized_plt
|
assert response.data["results"][0] == serialized_plt
|
||||||
|
|
|
@ -36,8 +36,6 @@ def test_can_validate_config(logged_in_api_client, factories):
|
||||||
"count": candidates.count(),
|
"count": candidates.count(),
|
||||||
"sample": TrackSerializer(candidates, many=True).data,
|
"sample": TrackSerializer(candidates, many=True).data,
|
||||||
}
|
}
|
||||||
for s in expected["sample"]:
|
|
||||||
s["artist"].pop("cover")
|
|
||||||
|
|
||||||
assert payload["filters"][0]["candidates"] == expected
|
assert payload["filters"][0]["candidates"] == expected
|
||||||
assert payload["filters"][0]["errors"] == []
|
assert payload["filters"][0]["errors"] == []
|
||||||
|
|
|
@ -101,7 +101,7 @@ def test_get_artists_serializer(factories):
|
||||||
|
|
||||||
def test_get_artist_serializer(factories):
|
def test_get_artist_serializer(factories):
|
||||||
artist = factories["music.Artist"]()
|
artist = factories["music.Artist"]()
|
||||||
album = factories["music.Album"](artist=artist)
|
album = factories["music.Album"](artist=artist, with_cover=True)
|
||||||
tracks = factories["music.Track"].create_batch(size=3, album=album)
|
tracks = factories["music.Track"].create_batch(size=3, album=album)
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -148,7 +148,7 @@ def test_get_track_data_content_type(mimetype, extension, expected, factories):
|
||||||
|
|
||||||
def test_get_album_serializer(factories):
|
def test_get_album_serializer(factories):
|
||||||
artist = factories["music.Artist"]()
|
artist = factories["music.Artist"]()
|
||||||
album = factories["music.Album"](artist=artist)
|
album = factories["music.Album"](artist=artist, with_cover=True)
|
||||||
track = factories["music.Track"](album=album, disc_number=42)
|
track = factories["music.Track"](album=album, disc_number=42)
|
||||||
upload = factories["music.Upload"](track=track, bitrate=42000, duration=43, size=44)
|
upload = factories["music.Upload"](track=track, bitrate=42000, duration=43, size=44)
|
||||||
|
|
||||||
|
@ -306,7 +306,9 @@ def test_scrobble_serializer(factories):
|
||||||
|
|
||||||
def test_channel_serializer(factories):
|
def test_channel_serializer(factories):
|
||||||
description = factories["common.Content"]()
|
description = factories["common.Content"]()
|
||||||
channel = factories["audio.Channel"](external=True, artist__description=description)
|
channel = factories["audio.Channel"](
|
||||||
|
external=True, artist__description=description, artist__with_cover=True
|
||||||
|
)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
playable=True, library=channel.library, duration=42
|
playable=True, library=channel.library, duration=42
|
||||||
)
|
)
|
||||||
|
@ -328,7 +330,9 @@ def test_channel_serializer(factories):
|
||||||
def test_channel_episode_serializer(factories):
|
def test_channel_episode_serializer(factories):
|
||||||
description = factories["common.Content"]()
|
description = factories["common.Content"]()
|
||||||
channel = factories["audio.Channel"]()
|
channel = factories["audio.Channel"]()
|
||||||
track = factories["music.Track"](description=description, artist=channel.artist)
|
track = factories["music.Track"](
|
||||||
|
description=description, artist=channel.artist, with_cover=True
|
||||||
|
)
|
||||||
upload = factories["music.Upload"](
|
upload = factories["music.Upload"](
|
||||||
playable=True, track=track, bitrate=128000, duration=42
|
playable=True, track=track, bitrate=128000, duration=42
|
||||||
)
|
)
|
||||||
|
|
|
@ -721,7 +721,7 @@ def test_get_indexes(
|
||||||
def test_get_cover_art_album(factories, logged_in_api_client):
|
def test_get_cover_art_album(factories, logged_in_api_client):
|
||||||
url = reverse("api:subsonic-get_cover_art")
|
url = reverse("api:subsonic-get_cover_art")
|
||||||
assert url.endswith("getCoverArt") is True
|
assert url.endswith("getCoverArt") is True
|
||||||
album = factories["music.Album"]()
|
album = factories["music.Album"](with_cover=True)
|
||||||
response = logged_in_api_client.get(url, {"id": "al-{}".format(album.pk)})
|
response = logged_in_api_client.get(url, {"id": "al-{}".format(album.pk)})
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
Loading…
Reference in New Issue