funkwhale/api/tests/manage/test_serializers.py

75 wiersze
2.4 KiB
Python
Czysty Zwykły widok Historia

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-09-22 12:29:30 +00:00
s.handle_delete(uploads.__class__.objects.all())
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,
permission_upload=False,
permission_federation=True,
permission_settings=True,
is_active=True,
)
s = serializers.ManageUserSerializer(
user,
data={"is_active": False, "permissions": {"federation": False, "upload": True}},
)
s.is_valid(raise_exception=True)
s.save()
user.refresh_from_db()
assert user.is_active is False
assert user.permission_federation is False
assert user.permission_upload is True
assert user.permission_library is False
assert user.permission_settings is True
def test_manage_import_request_mark_closed(factories):
affected = factories["requests.ImportRequest"].create_batch(
size=5, status="pending"
)
# we do not update imported requests
factories["requests.ImportRequest"].create_batch(size=5, status="imported")
s = serializers.ManageImportRequestActionSerializer(
queryset=affected[0].__class__.objects.all(),
data={"objects": "all", "action": "mark_closed"},
)
assert s.is_valid(raise_exception=True) is True
s.save()
assert affected[0].__class__.objects.filter(status="imported").count() == 5
for ir in affected:
ir.refresh_from_db()
assert ir.status == "closed"
def test_manage_import_request_mark_imported(factories, now):
affected = factories["requests.ImportRequest"].create_batch(
size=5, status="pending"
)
# we do not update closed requests
factories["requests.ImportRequest"].create_batch(size=5, status="closed")
s = serializers.ManageImportRequestActionSerializer(
queryset=affected[0].__class__.objects.all(),
data={"objects": "all", "action": "mark_imported"},
)
assert s.is_valid(raise_exception=True) is True
s.save()
assert affected[0].__class__.objects.filter(status="closed").count() == 5
for ir in affected:
ir.refresh_from_db()
assert ir.status == "imported"
assert ir.imported_date == now