2018-12-19 15:45:40 +00:00
|
|
|
import urllib.parse
|
|
|
|
|
2018-12-19 13:04:26 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
from funkwhale_api.common import utils
|
2019-02-21 13:27:14 +00:00
|
|
|
from funkwhale_api.music import serializers
|
2018-12-19 13:04:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_track(spa_html, no_api_auth, client, factories, settings):
|
2020-02-23 14:31:03 +00:00
|
|
|
upload = factories["music.Upload"](
|
2020-03-23 13:29:01 +00:00
|
|
|
playable=True,
|
|
|
|
track__disc_number=1,
|
|
|
|
track__attachment_cover=None,
|
|
|
|
track__album__with_cover=True,
|
2020-02-23 14:31:03 +00:00
|
|
|
)
|
2019-12-09 12:59:54 +00:00
|
|
|
track = upload.track
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/tracks/{track.pk}"
|
2018-12-19 13:04:26 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": track.title},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "music.song"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:album:disc",
|
|
|
|
"content": str(track.disc_number),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:album:track",
|
|
|
|
"content": str(track.position),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:musician",
|
|
|
|
"content": utils.join_url(
|
|
|
|
settings.FUNKWHALE_URL,
|
|
|
|
utils.spa_reverse("library_artist", kwargs={"pk": track.artist.pk}),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:album",
|
|
|
|
"content": utils.join_url(
|
|
|
|
settings.FUNKWHALE_URL,
|
|
|
|
utils.spa_reverse("library_album", kwargs={"pk": track.album.pk}),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:image",
|
2019-11-25 08:49:06 +00:00
|
|
|
"content": track.album.attachment_cover.download_url_medium_square_crop,
|
2018-12-19 13:04:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:audio",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, track.listen_url),
|
|
|
|
},
|
2019-12-09 12:59:54 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": upload.fid,
|
|
|
|
},
|
2018-12-19 13:04:26 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/json+oembed",
|
|
|
|
"href": (
|
|
|
|
utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed"))
|
2018-12-19 15:45:40 +00:00
|
|
|
+ "?format=json&url={}".format(
|
|
|
|
urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url))
|
2018-12-19 14:53:54 +00:00
|
|
|
)
|
2018-12-19 13:04:26 +00:00
|
|
|
),
|
|
|
|
},
|
2019-02-21 13:27:14 +00:00
|
|
|
{"tag": "meta", "property": "twitter:card", "content": "player"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "twitter:player",
|
|
|
|
"content": serializers.get_embed_url("track", id=track.id),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
|
|
|
|
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
|
2018-12-19 13:04:26 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_album(spa_html, no_api_auth, client, factories, settings):
|
2020-03-23 13:29:01 +00:00
|
|
|
track = factories["music.Upload"](
|
|
|
|
playable=True, track__disc_number=1, track__album__with_cover=True
|
|
|
|
).track
|
2018-12-19 13:04:26 +00:00
|
|
|
album = track.album
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/albums/{album.pk}"
|
2018-12-19 13:04:26 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": album.title},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "music.album"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:musician",
|
|
|
|
"content": utils.join_url(
|
|
|
|
settings.FUNKWHALE_URL,
|
|
|
|
utils.spa_reverse("library_artist", kwargs={"pk": album.artist.pk}),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "music:release_date",
|
|
|
|
"content": str(album.release_date),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:image",
|
2019-11-25 08:49:06 +00:00
|
|
|
"content": album.attachment_cover.download_url_medium_square_crop,
|
2018-12-19 13:04:26 +00:00
|
|
|
},
|
2019-12-09 12:59:54 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": album.fid,
|
|
|
|
},
|
2018-12-19 13:04:26 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/json+oembed",
|
|
|
|
"href": (
|
|
|
|
utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed"))
|
2018-12-19 15:45:40 +00:00
|
|
|
+ "?format=json&url={}".format(
|
|
|
|
urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url))
|
2018-12-19 14:53:54 +00:00
|
|
|
)
|
2018-12-19 13:04:26 +00:00
|
|
|
),
|
|
|
|
},
|
2019-02-21 13:27:14 +00:00
|
|
|
{"tag": "meta", "property": "twitter:card", "content": "player"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "twitter:player",
|
|
|
|
"content": serializers.get_embed_url("album", id=album.id),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
|
|
|
|
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
|
2018-12-19 13:04:26 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_artist(spa_html, no_api_auth, client, factories, settings):
|
2020-03-23 13:29:01 +00:00
|
|
|
album = factories["music.Album"](with_cover=True)
|
2019-03-08 09:30:04 +00:00
|
|
|
factories["music.Upload"](playable=True, track__album=album)
|
2018-12-19 13:04:26 +00:00
|
|
|
artist = album.artist
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/artists/{artist.pk}"
|
2018-12-19 13:04:26 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": artist.name},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "profile"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:image",
|
2019-11-25 08:49:06 +00:00
|
|
|
"content": album.attachment_cover.download_url_medium_square_crop,
|
2018-12-19 13:04:26 +00:00
|
|
|
},
|
2019-12-09 12:59:54 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": artist.fid,
|
|
|
|
},
|
2019-03-08 09:30:04 +00:00
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/json+oembed",
|
|
|
|
"href": (
|
|
|
|
utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed"))
|
|
|
|
+ "?format=json&url={}".format(
|
|
|
|
urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url))
|
|
|
|
)
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:card", "content": "player"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "twitter:player",
|
|
|
|
"content": serializers.get_embed_url("artist", id=artist.id),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
|
|
|
|
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
|
2018-12-19 13:04:26 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|
2019-09-12 07:48:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
|
|
|
|
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
2020-03-23 13:29:01 +00:00
|
|
|
track = factories["music.Upload"](
|
|
|
|
playable=True, track__album__with_cover=True
|
|
|
|
).track
|
2019-09-12 07:48:28 +00:00
|
|
|
playlist.insert_many([track])
|
|
|
|
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/playlists/{playlist.pk}"
|
2019-09-12 07:48:28 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": playlist.name},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "music.playlist"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:image",
|
2019-11-25 08:49:06 +00:00
|
|
|
"content": track.album.attachment_cover.download_url_medium_square_crop,
|
2019-09-12 07:48:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/json+oembed",
|
|
|
|
"href": (
|
|
|
|
utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed"))
|
|
|
|
+ "?format=json&url={}".format(
|
|
|
|
urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url))
|
|
|
|
)
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:card", "content": "player"},
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "twitter:player",
|
|
|
|
"content": serializers.get_embed_url("playlist", id=playlist.id),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "twitter:player:width", "content": "600"},
|
|
|
|
{"tag": "meta", "property": "twitter:player:height", "content": "400"},
|
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_playlist_empty(spa_html, no_api_auth, client, factories, settings):
|
|
|
|
playlist = factories["playlists.Playlist"](privacy_level="everyone")
|
|
|
|
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/playlists/{playlist.pk}"
|
2019-09-12 07:48:28 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": playlist.name},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "music.playlist"},
|
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|
2020-03-04 21:18:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_library(spa_html, no_api_auth, client, factories, settings):
|
|
|
|
library = factories["music.Library"]()
|
2022-11-23 21:36:56 +00:00
|
|
|
url = f"/library/{library.uuid}"
|
2020-03-04 21:18:28 +00:00
|
|
|
|
|
|
|
response = client.get(url)
|
|
|
|
|
|
|
|
expected_metas = [
|
|
|
|
{
|
|
|
|
"tag": "meta",
|
|
|
|
"property": "og:url",
|
|
|
|
"content": utils.join_url(settings.FUNKWHALE_URL, url),
|
|
|
|
},
|
|
|
|
{"tag": "meta", "property": "og:type", "content": "website"},
|
|
|
|
{"tag": "meta", "property": "og:title", "content": library.name},
|
|
|
|
{"tag": "meta", "property": "og:description", "content": library.description},
|
|
|
|
{
|
|
|
|
"tag": "link",
|
|
|
|
"rel": "alternate",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": library.fid,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
metas = utils.parse_meta(response.content.decode())
|
|
|
|
|
|
|
|
# we only test our custom metas, not the default ones
|
|
|
|
assert metas[: len(expected_metas)] == expected_metas
|