See #170: include subscriptions count in channels API

This commit is contained in:
Eliot Berriot 2020-01-20 09:58:04 +01:00
commit 3674d1235d
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
4 changed files with 27 additions and 1 deletions

View file

@ -90,6 +90,16 @@ def test_channel_serializer_representation(factories, to_api_date):
assert serializers.ChannelSerializer(channel).data == expected
def test_channel_serializer_representation_subscriptions_count(factories, to_api_date):
channel = factories["audio.Channel"]()
factories["federation.Follow"](target=channel.actor)
factories["federation.Follow"](target=channel.actor, approved=False)
serializer = serializers.ChannelSerializer(
channel, context={"subscriptions_count": True}
)
assert serializer.data["subscriptions_count"] == 1
def test_subscription_serializer(factories, to_api_date):
subscription = factories["audio.Subscription"]()
expected = {

View file

@ -41,7 +41,9 @@ def test_channel_create(logged_in_api_client):
def test_channel_detail(factories, logged_in_api_client):
channel = factories["audio.Channel"](artist__description=None)
url = reverse("api:v1:channels-detail", kwargs={"uuid": channel.uuid})
expected = serializers.ChannelSerializer(channel).data
expected = serializers.ChannelSerializer(
channel, context={"subscriptions_count": True}
).data
response = logged_in_api_client.get(url)
assert response.status_code == 200