test_views.py 1.03 KB
Newer Older
1
2
3
4
import pytest

from django.urls import reverse

5
6
from funkwhale_api import plugins

7
8
9
10
11
12
13
14
15

@pytest.mark.parametrize("level", ["instance", "me", "followers"])
def test_privacy_filter(preferences, level, factories, api_client):
    preferences["common__api_authentication_required"] = False
    factories["history.Listening"](user__privacy_level=level)
    url = reverse("api:v1:history:listenings-list")
    response = api_client.get(url)
    assert response.status_code == 200
    assert response.data["count"] == 0
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


def test_now(factories, logged_in_api_client, plugins_conf, mocker):
    track = factories["music.Track"]()
    url = reverse("api:v1:history:listenings-now")
    on_commit = mocker.patch("funkwhale_api.common.utils.on_commit")
    response = logged_in_api_client.post(url, {"track": track.pk})

    on_commit.assert_called_once_with(
        plugins.hooks.dispatch,
        "history.listening.now",
        track=track,
        user=logged_in_api_client.user,
        plugins_conf=plugins_conf,
    )

    assert response.status_code == 204