예제 #1
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
예제 #2
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
예제 #3
0
def test_activity_pub_artist_serializer_to_ap(factories):
    artist = factories["music.Artist"]()
    expected = {
        "@context": serializers.AP_CONTEXT,
        "type": "Artist",
        "id": artist.fid,
        "name": artist.name,
        "musicbrainzId": artist.mbid,
        "published": artist.creation_date.isoformat(),
    }
    serializer = serializers.ArtistSerializer(artist)

    assert serializer.data == expected
예제 #4
0
def test_outbox_update_artist(factories):
    artist = factories["music.Artist"]()
    activity = list(routes.outbox_update_artist({"artist": artist}))[0]
    expected = serializers.ActivitySerializer({
        "type":
        "Update",
        "object":
        serializers.ArtistSerializer(artist).data
    }).data

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

    assert dict(activity["payload"]) == dict(expected)
    assert activity["actor"] == actors.get_service_actor()
예제 #5
0
def test_fetch_success(factories, r_mock, mocker):
    artist = factories["music.Artist"]()
    fetch = factories["federation.Fetch"](url=artist.fid)
    payload = serializers.ArtistSerializer(artist).data
    init = mocker.spy(serializers.ArtistSerializer, "__init__")
    save = mocker.spy(serializers.ArtistSerializer, "save")

    r_mock.get(artist.fid, json=payload)

    tasks.fetch(fetch_id=fetch.pk)

    fetch.refresh_from_db()

    assert fetch.status == "finished"
    assert init.call_count == 1
    assert init.call_args[0][1] == artist
    assert init.call_args[1]["data"] == payload
    assert save.call_count == 1
예제 #6
0
def test_inbox_update_artist(factories, mocker):
    update_library_entity = mocker.patch(
        "funkwhale_api.music.tasks.update_library_entity")
    activity = factories["federation.Activity"]()
    obj = factories["music.Artist"](attributed=True, attachment_cover=None)
    actor = obj.attributed_to
    data = serializers.ArtistSerializer(obj).data
    data["name"] = "New name"
    payload = {"type": "Update", "actor": actor, "object": data}

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

    update_library_entity.assert_called_once_with(obj, {"name": "New name"})
예제 #7
0
def test_handle_library_entry_update_can_manage(factories, mocker):
    update_library_entity = mocker.patch(
        "funkwhale_api.music.tasks.update_library_entity")
    activity = factories["federation.Activity"]()
    obj = factories["music.Artist"]()
    actor = factories["federation.Actor"]()
    mocker.patch.object(actor, "can_manage", return_value=False)
    data = serializers.ArtistSerializer(obj).data
    data["name"] = "New name"
    payload = {"type": "Update", "actor": actor, "object": data}

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

    update_library_entity.assert_not_called()