mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 13:19:16 +02:00
Resolve "Per-user libraries" (use !368 instead)
This commit is contained in:
parent
b0ca181016
commit
2ea21994ee
144 changed files with 6749 additions and 5347 deletions
53
api/tests/federation/test_api_serializers.py
Normal file
53
api/tests/federation/test_api_serializers.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
from funkwhale_api.federation import api_serializers
|
||||
from funkwhale_api.federation import serializers
|
||||
|
||||
|
||||
def test_library_serializer(factories):
|
||||
library = factories["music.Library"](files_count=5678)
|
||||
expected = {
|
||||
"fid": library.fid,
|
||||
"uuid": str(library.uuid),
|
||||
"actor": serializers.APIActorSerializer(library.actor).data,
|
||||
"name": library.name,
|
||||
"description": library.description,
|
||||
"creation_date": library.creation_date.isoformat().split("+")[0] + "Z",
|
||||
"files_count": library.files_count,
|
||||
"privacy_level": library.privacy_level,
|
||||
"follow": None,
|
||||
}
|
||||
|
||||
serializer = api_serializers.LibrarySerializer(library)
|
||||
|
||||
assert serializer.data == expected
|
||||
|
||||
|
||||
def test_library_serializer_with_follow(factories):
|
||||
library = factories["music.Library"](files_count=5678)
|
||||
follow = factories["federation.LibraryFollow"](target=library)
|
||||
|
||||
setattr(library, "_follows", [follow])
|
||||
expected = {
|
||||
"fid": library.fid,
|
||||
"uuid": str(library.uuid),
|
||||
"actor": serializers.APIActorSerializer(library.actor).data,
|
||||
"name": library.name,
|
||||
"description": library.description,
|
||||
"creation_date": library.creation_date.isoformat().split("+")[0] + "Z",
|
||||
"files_count": library.files_count,
|
||||
"privacy_level": library.privacy_level,
|
||||
"follow": api_serializers.NestedLibraryFollowSerializer(follow).data,
|
||||
}
|
||||
|
||||
serializer = api_serializers.LibrarySerializer(library)
|
||||
|
||||
assert serializer.data == expected
|
||||
|
||||
|
||||
def test_library_serializer_validates_existing_follow(factories):
|
||||
follow = factories["federation.LibraryFollow"]()
|
||||
serializer = api_serializers.LibraryFollowSerializer(
|
||||
data={"target": follow.target.uuid}, context={"actor": follow.actor}
|
||||
)
|
||||
|
||||
assert serializer.is_valid() is False
|
||||
assert "target" in serializer.errors
|
Loading…
Add table
Add a link
Reference in a new issue