See #170: limit the amount of channels allowed per user

This commit is contained in:
Eliot Berriot 2020-02-14 11:50:30 +01:00
commit a3505d2099
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
5 changed files with 52 additions and 2 deletions

View file

@ -23,7 +23,9 @@ def test_channel_serializer_create(factories):
"content_category": "other",
}
serializer = serializers.ChannelCreateSerializer(data=data)
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)
@ -49,6 +51,26 @@ def test_channel_serializer_create(factories):
assert channel.library.actor == attributed_to
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 = {
# TODO: cover
"name": "My channel",
"username": "mychannel",
"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)
def test_channel_serializer_create_podcast(factories):
attributed_to = factories["federation.Actor"](local=True)
@ -62,7 +84,9 @@ def test_channel_serializer_create_podcast(factories):
"metadata": {"itunes_category": "Sports", "language": "en"},
}
serializer = serializers.ChannelCreateSerializer(data=data)
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)