Beispiel #1
0
def test_channel_serializer_create_podcast(factories):
    attributed_to = factories["federation.Actor"](local=True)

    data = {
        # TODO: cover
        "name": "My channel",
        "username": "******",
        "description": {
            "text": "This is my channel",
            "content_type": "text/markdown"
        },
        "tags": ["hello", "world"],
        "content_category": "podcast",
        "metadata": {
            "itunes_category": "Sports",
            "language": "en"
        },
    }

    serializer = serializers.ChannelCreateSerializer(
        data=data, context={"actor": attributed_to})
    assert serializer.is_valid(raise_exception=True) is True

    channel = serializer.save(attributed_to=attributed_to)
    assert channel.metadata == data["metadata"]
Beispiel #2
0
def test_channel_serializer_create_validates_username_uniqueness(factories):
    attributed_to = factories["federation.Actor"](local=True)
    data = {
        "name": "My channel",
        "username": attributed_to.preferred_username.upper(),
        "description": {
            "text": "This is my channel",
            "content_type": "text/markdown"
        },
        "tags": ["hello", "world"],
        "content_category": "other",
    }

    serializer = serializers.ChannelCreateSerializer(
        data=data, context={"actor": attributed_to})
    with pytest.raises(serializers.serializers.ValidationError,
                       match=r".*username is already taken.*"):
        assert serializer.is_valid(raise_exception=True)
Beispiel #3
0
def test_channel_serializer_create_validates_blacklisted_username(
        factories, settings):
    settings.ACCOUNT_USERNAME_BLACKLIST = ["forBidden"]
    attributed_to = factories["federation.Actor"](local=True)
    data = {
        "name": "My channel",
        "username": "******",
        "description": {
            "text": "This is my channel",
            "content_type": "text/markdown"
        },
        "tags": ["hello", "world"],
        "content_category": "other",
    }

    serializer = serializers.ChannelCreateSerializer(
        data=data, context={"actor": attributed_to})
    with pytest.raises(serializers.serializers.ValidationError,
                       match=r".*username is already taken.*"):
        assert serializer.is_valid(raise_exception=True)
Beispiel #4
0
def test_channel_serializer_create(factories, mocker):
    attributed_to = factories["federation.Actor"](local=True)
    attachment = factories["common.Attachment"](actor=attributed_to)
    request = mocker.Mock(user=mocker.Mock(actor=attributed_to))
    data = {
        "name": "My channel",
        "username": "******",
        "description": {
            "text": "This is my channel",
            "content_type": "text/markdown"
        },
        "tags": ["hello", "world"],
        "content_category": "other",
        "cover": attachment.uuid,
    }

    serializer = serializers.ChannelCreateSerializer(data=data,
                                                     context={
                                                         "actor":
                                                         attributed_to,
                                                         "request": request
                                                     })
    assert serializer.is_valid(raise_exception=True) is True

    channel = serializer.save(attributed_to=attributed_to)

    assert channel.artist.name == data["name"]
    assert channel.artist.attributed_to == attributed_to
    assert (sorted(
        channel.artist.tagged_items.values_list("tag__name",
                                                flat=True)) == data["tags"])
    assert channel.artist.description.text == data["description"]["text"]
    assert channel.artist.attachment_cover == attachment
    assert channel.artist.content_category == data["content_category"]
    assert (channel.artist.description.content_type == data["description"]
            ["content_type"])
    assert channel.attributed_to == attributed_to
    assert channel.actor.preferred_username == data["username"]
    assert channel.actor.name == data["name"]
    assert channel.library.privacy_level == "everyone"
    assert channel.library.actor == attributed_to
Beispiel #5
0
def test_channel_serializer_create_honor_max_channels_setting(
        factories, preferences):
    preferences["audio__max_channels"] = 1
    attributed_to = factories["federation.Actor"](local=True)
    factories["audio.Channel"](attributed_to=attributed_to)
    data = {
        "name": "My channel",
        "username": "******",
        "description": {
            "text": "This is my channel",
            "content_type": "text/markdown"
        },
        "tags": ["hello", "world"],
        "content_category": "other",
    }

    serializer = serializers.ChannelCreateSerializer(
        data=data, context={"actor": attributed_to})
    with pytest.raises(serializers.serializers.ValidationError,
                       match=r".*max.*"):
        assert serializer.is_valid(raise_exception=True)