Esempio n. 1
0
def test_inbox_update_audio(factories, mocker, r_mock):
    channel = factories["audio.Channel"]()
    upload = factories["music.Upload"](
        library=channel.library,
        track__artist=channel.artist,
        track__attributed_to=channel.actor,
    )
    upload.track.fid = upload.fid
    upload.track.save()
    r_mock.get(
        upload.track.album.fid,
        json=serializers.AlbumSerializer(upload.track.album).data,
    )
    data = serializers.ChannelCreateUploadSerializer(upload).data
    data["object"]["name"] = "New title"

    routes.inbox_update_audio(data,
                              context={
                                  "actor": channel.actor,
                                  "raise_exception": True
                              })

    upload.track.refresh_from_db()

    assert upload.track.title == "New title"
Esempio n. 2
0
def test_activity_pub_track_serializer_to_ap(factories):
    track = factories["music.Track"]()
    expected = {
        "@context":
        serializers.AP_CONTEXT,
        "published":
        track.creation_date.isoformat(),
        "type":
        "Track",
        "musicbrainzId":
        track.mbid,
        "id":
        track.fid,
        "name":
        track.title,
        "position":
        track.position,
        "artists": [
            serializers.ArtistSerializer(track.artist,
                                         context={
                                             "include_ap_context": False
                                         }).data
        ],
        "album":
        serializers.AlbumSerializer(track.album,
                                    context={
                                        "include_ap_context": False
                                    }).data,
    }
    serializer = serializers.TrackSerializer(track)

    assert serializer.data == expected
Esempio n. 3
0
def test_activity_pub_album_serializer_to_ap(factories):
    album = factories["music.Album"]()

    expected = {
        "@context":
        serializers.AP_CONTEXT,
        "type":
        "Album",
        "id":
        album.fid,
        "name":
        album.title,
        "cover": {
            "type": "Link",
            "mediaType": "image/jpeg",
            "href": utils.full_url(album.cover.url),
        },
        "musicbrainzId":
        album.mbid,
        "published":
        album.creation_date.isoformat(),
        "released":
        album.release_date.isoformat(),
        "artists": [
            serializers.ArtistSerializer(album.artist,
                                         context={
                                             "include_ap_context": False
                                         }).data
        ],
    }
    serializer = serializers.AlbumSerializer(album)

    assert serializer.data == expected
Esempio n. 4
0
def test_outbox_update_album(factories):
    album = factories["music.Album"]()
    activity = list(routes.outbox_update_album({"album": album}))[0]
    expected = serializers.ActivitySerializer({
        "type":
        "Update",
        "object":
        serializers.AlbumSerializer(album).data
    }).data

    expected["to"] = [contexts.AS.Public, {"type": "instances_with_followers"}]

    assert dict(activity["payload"]) == dict(expected)
    assert activity["actor"] == actors.get_service_actor()
Esempio n. 5
0
def test_inbox_update_album(factories, mocker):
    update_library_entity = mocker.patch(
        "funkwhale_api.music.tasks.update_library_entity")
    activity = factories["federation.Activity"]()
    obj = factories["music.Album"](attributed=True, attachment_cover=None)
    actor = obj.attributed_to
    data = serializers.AlbumSerializer(obj).data
    data["name"] = "New title"
    payload = {"type": "Update", "actor": actor, "object": data}

    routes.inbox_update_album(payload,
                              context={
                                  "actor": actor,
                                  "raise_exception": True,
                                  "activity": activity
                              })

    update_library_entity.assert_called_once_with(obj, {"title": "New title"})