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",
|
|
|
|
[
|
2018-09-22 12:29:30 +00:00
|
|
|
(views.ManageUploadViewSet, ["library"], "and"),
|
2018-06-19 16:48:43 +00:00
|
|
|
(views.ManageUserViewSet, ["settings"], "and"),
|
2018-06-19 21:27:21 +00:00
|
|
|
(views.ManageInvitationViewSet, ["settings"], "and"),
|
2018-06-19 16:48:43 +00:00
|
|
|
],
|
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)
|
|
|
|
|
|
|
|
|
2018-09-06 18:35:02 +00:00
|
|
|
@pytest.mark.skip(reason="Refactoring in progress")
|
2018-09-22 12:29:30 +00:00
|
|
|
def test_upload_view(factories, superuser_api_client):
|
|
|
|
uploads = factories["music.Upload"].create_batch(size=5)
|
|
|
|
qs = uploads[0].__class__.objects.order_by("-creation_date")
|
|
|
|
url = reverse("api:v1:manage:library:uploads-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-09-22 12:29:30 +00:00
|
|
|
expected = serializers.ManageUploadSerializer(
|
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-09-22 12:29:30 +00:00
|
|
|
assert response.data["count"] == len(uploads)
|
2018-06-09 13:36:16 +00:00
|
|
|
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
|
2018-06-19 21:27:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_invitation_view(factories, superuser_api_client, mocker):
|
|
|
|
invitations = factories["users.Invitation"].create_batch(size=5)
|
|
|
|
qs = invitations[0].__class__.objects.order_by("-id")
|
|
|
|
url = reverse("api:v1:manage:users:invitations-list")
|
|
|
|
|
|
|
|
response = superuser_api_client.get(url, {"sort": "-id"})
|
|
|
|
expected = serializers.ManageInvitationSerializer(qs, many=True).data
|
|
|
|
|
|
|
|
assert response.data["count"] == len(invitations)
|
|
|
|
assert response.data["results"] == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_invitation_view_create(factories, superuser_api_client, mocker):
|
|
|
|
url = reverse("api:v1:manage:users:invitations-list")
|
|
|
|
response = superuser_api_client.post(url)
|
|
|
|
|
|
|
|
assert response.status_code == 201
|
|
|
|
assert superuser_api_client.user.invitations.latest("id") is not None
|