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)
|
|
|
|
setattr(domain, "last_activity_date", now)
|
|
|
|
expected = {
|
|
|
|
"name": domain.name,
|
|
|
|
"creation_date": domain.creation_date.isoformat().split("+")[0] + "Z",
|
|
|
|
"last_activity_date": now,
|
|
|
|
"actors_count": 42,
|
|
|
|
"outbox_activities_count": 23,
|
|
|
|
}
|
|
|
|
s = serializers.ManageDomainSerializer(domain)
|
|
|
|
|
|
|
|
assert s.data == expected
|