Ejemplo n.º 1
0
def test_subscribe_to_rss_feed_existing_channel(
    factories, logged_in_api_client, mocker
):
    actor = logged_in_api_client.user.create_actor()
    rss_url = "http://example.test/rss.url"
    channel = factories["audio.Channel"](rss_url=rss_url, external=True)
    url = reverse("api:v1:channels-rss_subscribe")

    response = logged_in_api_client.post(url, {"url": rss_url})

    assert response.status_code == 201

    subscription = actor.emitted_follows.select_related(
        "target__channel__artist__description",
        "target__channel__artist__attachment_cover",
    ).latest("id")

    assert subscription.target == channel.actor
    assert subscription.approved is True
    assert subscription.fid == subscription.get_federation_id()

    setattr(subscription.target.channel.artist, "_tracks_count", 0)
    setattr(subscription.target.channel.artist, "_prefetched_tagged_items", [])

    expected = serializers.SubscriptionSerializer(subscription).data

    assert response.data == expected
Ejemplo n.º 2
0
def test_subscription_serializer(factories, to_api_date):
    subscription = factories["audio.Subscription"]()
    expected = {
        "channel":
        serializers.ChannelSerializer(subscription.target.channel).data,
        "uuid": str(subscription.uuid),
        "creation_date": to_api_date(subscription.creation_date),
        "approved": subscription.approved,
        "fid": subscription.fid,
    }

    assert serializers.SubscriptionSerializer(subscription).data == expected
Ejemplo n.º 3
0
def test_channel_subscribe(factories, logged_in_api_client):
    actor = logged_in_api_client.user.create_actor()
    channel = factories["audio.Channel"](artist__description=None)
    url = reverse("api:v1:channels-subscribe", kwargs={"composite": channel.uuid})

    response = logged_in_api_client.post(url)

    assert response.status_code == 201

    subscription = actor.emitted_follows.select_related(
        "target__channel__artist__description",
        "target__channel__artist__attachment_cover",
    ).latest("id")
    setattr(subscription.target.channel.artist, "_tracks_count", 0)
    setattr(subscription.target.channel.artist, "_prefetched_tagged_items", [])
    assert subscription.fid == subscription.get_federation_id()
    expected = serializers.SubscriptionSerializer(subscription).data
    assert response.data == expected
    assert subscription.target == channel.actor
Ejemplo n.º 4
0
def test_subscriptions_list(factories, logged_in_api_client):
    actor = logged_in_api_client.user.create_actor()
    channel = factories["audio.Channel"](
        artist__description=None, artist__with_cover=True
    )
    subscription = factories["audio.Subscription"](target=channel.actor, actor=actor)
    setattr(subscription.target.channel.artist, "_tracks_count", 0)
    setattr(subscription.target.channel.artist, "_prefetched_tagged_items", [])
    factories["audio.Subscription"](target=channel.actor)
    url = reverse("api:v1:subscriptions-list")
    expected = serializers.SubscriptionSerializer(subscription).data
    response = logged_in_api_client.get(url)

    assert response.status_code == 200
    assert response.data["results"][0] == expected
    assert response.data == {
        "results": [expected],
        "count": 1,
        "next": None,
        "previous": None,
    }