Пример #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"
Пример #2
0
def test_channel_upload_retrieve_activity(factories, api_client):
    channel = factories["audio.Channel"](local=True)
    upload = factories["music.Upload"](library=channel.library, playable=True)
    url = reverse("federation:music:uploads-activity",
                  kwargs={"uuid": upload.uuid})

    expected = serializers.ChannelCreateUploadSerializer(upload).data

    response = api_client.get(url)

    assert response.status_code == 200
    assert response.data == expected
Пример #3
0
def test_outbox_update_audio(factories, faker, mocker):
    fake_uuid = faker.uuid4()
    mocker.patch("uuid.uuid4", return_value=fake_uuid)
    upload = factories["music.Upload"](channel=True)
    activity = list(routes.outbox_update_audio({"upload": upload}))[0]
    expected = serializers.ChannelCreateUploadSerializer(upload).data

    expected["type"] = "Update"
    expected["id"] += "/" + fake_uuid[:8]
    expected["to"] = [contexts.AS.Public, {"type": "instances_with_followers"}]

    assert dict(activity["payload"]) == dict(expected)
    assert activity["actor"] == upload.library.channel.actor
Пример #4
0
def test_outbox_create_audio_channel(factories, mocker):
    channel = factories["audio.Channel"]()
    upload = factories["music.Upload"](library=channel.library)
    activity = list(routes.outbox_create_audio({"upload": upload}))[0]
    serializer = serializers.ChannelCreateUploadSerializer(upload)
    expected = serializer.data
    expected["to"] = [{
        "type": "followers",
        "target": upload.library.channel.actor
    }]

    assert dict(activity["payload"]) == dict(expected)
    assert activity["actor"] == channel.actor
    assert activity["target"] is None
    assert activity["object"] == upload
def test_reel2bits_upload_create(factories):
    channel = factories["audio.Channel"]()
    payload = {
        "id":
        "https://r2b.example/outbox/cb89c969224d7c9d",
        "to": ["https://www.w3.org/ns/activitystreams#Public"],
        "type":
        "Create",
        "actor":
        "https://r2b.example/user/anna",
        "object": {
            "cc": ["https://r2b.example/user/anna/followers"],
            "id":
            "https://r2b.example/outbox/cb89c969224d7c9d/activity",
            "to": ["https://www.w3.org/ns/activitystreams#Public"],
            "url": {
                "href": "https://r2b.example/uploads/sounds/anna/test.mp3",
                "type": "Link",
                "mediaType": "audio/mpeg",
            },
            "name":
            "nya",
            "tag": [
                {
                    "name": "#nya",
                    "type": "Hashtag"
                },
                {
                    "name": "#cat",
                    "type": "Hashtag"
                },
                {
                    "name": "#paws",
                    "type": "Hashtag"
                },
            ],
            "type":
            "Audio",
            "genre":
            "cat",
            "image": {
                "url":
                "https://r2b.example/uploads/artwork_sounds/anna/test.jpg",
                "type": "Image",
                "mediaType": "image/jpeg",
            },
            "content":
            "nya nya",
            "licence": {
                "id": "0",
                "icon": "",
                "link": "",
                "name": "Not Specified"
            },
            "mediaType":
            "text/plain",
            "published":
            "2020-04-08T12:47:29Z",
            "attributedTo":
            "https://r2b.example/user/anna",
        },
        "@context": [
            "https://www.w3.org/ns/activitystreams",
            "https://w3id.org/security/v1",
            {
                "toot": "http://joinmastodon.org/ns#",
                "Hashtag": "as:Hashtag",
                "featured": "toot:featured",
                "sensitive": "as:sensitive",
            },
        ],
        "published":
        "2020-04-08T12:47:29Z",
    }
    serializer = serializers.ChannelCreateUploadSerializer(
        data=payload, context={"channel": channel})
    assert serializer.is_valid(raise_exception=True) is True

    serializer.save()