Exemple #1
0
def test_library_playlist_empty(spa_html, no_api_auth, client, factories,
                                settings):
    playlist = factories["playlists.Playlist"](privacy_level="everyone")

    url = "/library/playlists/{}".format(playlist.pk)

    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
def test_channel_detail(spa_html, no_api_auth, client, factories, settings):
    icon = factories["common.Attachment"]()
    actor = factories["federation.Actor"](local=True, attachment_icon=icon)
    url = "/@{}".format(actor.preferred_username)

    response = client.get(url)

    assert response.status_code == 200
    expected_metas = [
        {
            "tag": "meta",
            "property": "og:url",
            "content": utils.join_url(settings.FUNKWHALE_URL, url),
        },
        {
            "tag": "meta",
            "property": "og:title",
            "content": actor.display_name
        },
        {
            "tag": "meta",
            "property": "og:type",
            "content": "profile"
        },
        {
            "tag": "meta",
            "property": "og:image",
            "content": actor.attachment_icon.download_url_medium_square_crop,
        },
        {
            "tag": "link",
            "rel": "alternate",
            "type": "application/activity+json",
            "href": actor.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
Exemple #3
0
def test_library_library(spa_html, no_api_auth, client, factories, settings):
    library = factories["music.Library"]()
    url = "/library/{}".format(library.uuid)

    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
Exemple #4
0
def test_channel_detail(attribute, spa_html, no_api_auth, client, factories,
                        settings):
    channel = factories["audio.Channel"](library__privacy_level="everyone",
                                         artist__with_cover=True)
    factories["music.Upload"](playable=True, library=channel.library)
    url = "/channels/{}".format(utils.recursive_getattr(channel, attribute))
    detail_url = "/channels/{}".format(channel.actor.full_username)

    response = client.get(url)

    assert response.status_code == 200
    expected_metas = [
        {
            "tag": "meta",
            "property": "og:url",
            "content": utils.join_url(settings.FUNKWHALE_URL, detail_url),
        },
        {
            "tag": "meta",
            "property": "og:title",
            "content": channel.artist.name
        },
        {
            "tag": "meta",
            "property": "og:type",
            "content": "profile"
        },
        {
            "tag":
            "meta",
            "property":
            "og:image",
            "content":
            channel.artist.attachment_cover.download_url_medium_square_crop,
        },
        {
            "tag": "link",
            "rel": "alternate",
            "type": "application/activity+json",
            "href": channel.actor.fid,
        },
        {
            "tag": "link",
            "rel": "alternate",
            "type": "application/rss+xml",
            "href": channel.get_rss_url(),
            "title": "{} - RSS Podcast Feed".format(channel.artist.name),
        },
        {
            "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, detail_url)))),
        },
        {
            "tag": "meta",
            "property": "twitter:card",
            "content": "player"
        },
        {
            "tag": "meta",
            "property": "twitter:player",
            "content": serializers.get_embed_url("channel", id=channel.uuid),
        },
        {
            "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
Exemple #5
0
def test_library_track(spa_html, no_api_auth, client, factories, settings):
    upload = factories["music.Upload"](
        playable=True,
        track__disc_number=1,
        track__attachment_cover=None,
        track__album__with_cover=True,
    )
    track = upload.track
    url = "/library/tracks/{}".format(track.pk)

    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",
            "content":
            track.album.attachment_cover.download_url_medium_square_crop,
        },
        {
            "tag": "meta",
            "property": "og:audio",
            "content": utils.join_url(settings.FUNKWHALE_URL,
                                      track.listen_url),
        },
        {
            "tag": "link",
            "rel": "alternate",
            "type": "application/activity+json",
            "href": upload.fid,
        },
        {
            "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("track", id=track.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
Exemple #6
0
def test_library_playlist(spa_html, no_api_auth, client, factories, settings):
    playlist = factories["playlists.Playlist"](privacy_level="everyone")
    track = factories["music.Upload"](playable=True,
                                      track__album__with_cover=True).track
    playlist.insert_many([track])

    url = "/library/playlists/{}".format(playlist.pk)

    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",
            "content":
            track.album.attachment_cover.download_url_medium_square_crop,
        },
        {
            "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