2019-01-05 17:21:35 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-05-28 22:07:20 +00:00
|
|
|
from funkwhale_api.manage import serializers
|
|
|
|
|
|
|
|
|
2018-09-22 12:29:30 +00:00
|
|
|
def test_manage_upload_action_delete(factories):
|
|
|
|
uploads = factories["music.Upload"](size=5)
|
|
|
|
s = serializers.ManageUploadActionSerializer(queryset=None)
|
2018-05-28 22:07:20 +00:00
|
|
|
|
2018-09-22 12:29:30 +00:00
|
|
|
s.handle_delete(uploads.__class__.objects.all())
|
2018-05-28 22:07:20 +00:00
|
|
|
|
2018-09-22 12:29:30 +00:00
|
|
|
assert uploads.__class__.objects.count() == 0
|
2018-06-19 18:11:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_user_update_permission(factories):
|
|
|
|
user = factories["users.User"](
|
|
|
|
permission_library=False,
|
2018-12-06 10:18:09 +00:00
|
|
|
permission_moderation=False,
|
2018-06-19 18:11:40 +00:00
|
|
|
permission_settings=True,
|
|
|
|
is_active=True,
|
|
|
|
)
|
|
|
|
s = serializers.ManageUserSerializer(
|
|
|
|
user,
|
2018-09-28 19:05:43 +00:00
|
|
|
data={
|
|
|
|
"is_active": False,
|
2018-12-26 22:03:27 +00:00
|
|
|
"permissions": {"moderation": True, "settings": False},
|
2018-09-28 19:05:43 +00:00
|
|
|
"upload_quota": 12,
|
|
|
|
},
|
2018-06-19 18:11:40 +00:00
|
|
|
)
|
|
|
|
s.is_valid(raise_exception=True)
|
|
|
|
s.save()
|
|
|
|
user.refresh_from_db()
|
|
|
|
|
|
|
|
assert user.is_active is False
|
2018-09-28 19:05:43 +00:00
|
|
|
assert user.upload_quota == 12
|
2018-12-06 10:18:09 +00:00
|
|
|
assert user.permission_moderation is True
|
2018-06-19 18:11:40 +00:00
|
|
|
assert user.permission_library is False
|
2018-12-26 22:03:27 +00:00
|
|
|
assert user.permission_settings is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_manage_domain_serializer(factories, now):
|
|
|
|
domain = factories["federation.Domain"]()
|
|
|
|
setattr(domain, "actors_count", 42)
|
|
|
|
setattr(domain, "outbox_activities_count", 23)
|
|
|
|
expected = {
|
|
|
|
"name": domain.name,
|
|
|
|
"creation_date": domain.creation_date.isoformat().split("+")[0] + "Z",
|
|
|
|
"actors_count": 42,
|
|
|
|
"outbox_activities_count": 23,
|
2018-12-27 16:42:43 +00:00
|
|
|
"nodeinfo": {},
|
|
|
|
"nodeinfo_fetch_date": None,
|
2018-12-26 22:03:27 +00:00
|
|
|
}
|
|
|
|
s = serializers.ManageDomainSerializer(domain)
|
|
|
|
|
|
|
|
assert s.data == expected
|
2019-01-03 10:47:29 +00:00
|
|
|
|
|
|
|
|
2019-01-05 17:21:35 +00:00
|
|
|
def test_manage_domain_serializer_validates_hostname(db):
|
|
|
|
s = serializers.ManageDomainSerializer(data={"name": "hello world"})
|
|
|
|
|
|
|
|
with pytest.raises(serializers.serializers.ValidationError):
|
|
|
|
s.is_valid(raise_exception=True)
|
|
|
|
|
|
|
|
|
2019-01-03 10:47:29 +00:00
|
|
|
def test_manage_actor_serializer(factories, now):
|
|
|
|
actor = factories["federation.Actor"]()
|
|
|
|
setattr(actor, "uploads_count", 66)
|
|
|
|
expected = {
|
|
|
|
"id": actor.id,
|
|
|
|
"name": actor.name,
|
|
|
|
"creation_date": actor.creation_date.isoformat().split("+")[0] + "Z",
|
|
|
|
"last_fetch_date": actor.last_fetch_date.isoformat().split("+")[0] + "Z",
|
|
|
|
"uploads_count": 66,
|
|
|
|
"fid": actor.fid,
|
|
|
|
"url": actor.url,
|
|
|
|
"outbox_url": actor.outbox_url,
|
|
|
|
"shared_inbox_url": actor.shared_inbox_url,
|
|
|
|
"inbox_url": actor.inbox_url,
|
|
|
|
"domain": actor.domain_id,
|
|
|
|
"type": actor.type,
|
|
|
|
"summary": actor.summary,
|
|
|
|
"preferred_username": actor.preferred_username,
|
|
|
|
"manually_approves_followers": actor.manually_approves_followers,
|
2019-01-03 16:10:02 +00:00
|
|
|
"full_username": actor.full_username,
|
|
|
|
"user": None,
|
2019-01-03 10:47:29 +00:00
|
|
|
}
|
|
|
|
s = serializers.ManageActorSerializer(actor)
|
|
|
|
|
|
|
|
assert s.data == expected
|