2018-05-28 22:07:20 +00:00
|
|
|
import pytest
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2018-06-10 08:55:16 +00:00
|
|
|
from funkwhale_api.manage import serializers, views
|
2018-05-28 22:07:20 +00:00
|
|
|
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
@pytest.mark.parametrize(
|
2018-06-19 16:48:43 +00:00
|
|
|
"view,permissions,operator",
|
|
|
|
[
|
|
|
|
(views.ManageTrackFileViewSet, ["library"], "and"),
|
|
|
|
(views.ManageUserViewSet, ["settings"], "and"),
|
|
|
|
],
|
2018-06-09 13:36:16 +00:00
|
|
|
)
|
2018-05-28 22:07:20 +00:00
|
|
|
def test_permissions(assert_user_permission, view, permissions, operator):
|
|
|
|
assert_user_permission(view, permissions, operator)
|
|
|
|
|
|
|
|
|
|
|
|
def test_track_file_view(factories, superuser_api_client):
|
2018-06-09 13:36:16 +00:00
|
|
|
tfs = factories["music.TrackFile"].create_batch(size=5)
|
|
|
|
qs = tfs[0].__class__.objects.order_by("-creation_date")
|
|
|
|
url = reverse("api:v1:manage:library:track-files-list")
|
2018-05-28 22:07:20 +00:00
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
response = superuser_api_client.get(url, {"sort": "-creation_date"})
|
2018-05-29 20:54:53 +00:00
|
|
|
expected = serializers.ManageTrackFileSerializer(
|
2018-06-09 13:36:16 +00:00
|
|
|
qs, many=True, context={"request": response.wsgi_request}
|
|
|
|
).data
|
2018-05-28 22:07:20 +00:00
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
assert response.data["count"] == len(tfs)
|
|
|
|
assert response.data["results"] == expected
|
2018-06-19 16:48:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_user_view(factories, superuser_api_client, mocker):
|
|
|
|
mocker.patch("funkwhale_api.users.models.User.record_activity")
|
|
|
|
users = factories["users.User"].create_batch(size=5) + [superuser_api_client.user]
|
|
|
|
qs = users[0].__class__.objects.order_by("-id")
|
|
|
|
url = reverse("api:v1:manage:users:users-list")
|
|
|
|
|
|
|
|
response = superuser_api_client.get(url, {"sort": "-id"})
|
|
|
|
expected = serializers.ManageUserSerializer(
|
|
|
|
qs, many=True, context={"request": response.wsgi_request}
|
|
|
|
).data
|
|
|
|
|
|
|
|
assert response.data["count"] == len(users)
|
|
|
|
assert response.data["results"] == expected
|