See #1100: clean compat and XXX in the code
This commit is contained in:
parent
b7f1c02c6f
commit
e271851f67
67 changed files with 203 additions and 328 deletions
|
|
@ -1,30 +0,0 @@
|
|||
import pytest
|
||||
from rest_framework_jwt.settings import api_settings
|
||||
|
||||
from funkwhale_api.common.auth import TokenAuthMiddleware
|
||||
|
||||
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
|
||||
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
|
||||
|
||||
|
||||
@pytest.mark.parametrize("query_string", [b"token=wrong", b""])
|
||||
def test_header_anonymous(query_string, factories):
|
||||
def callback(scope):
|
||||
assert scope["user"].is_anonymous
|
||||
|
||||
scope = {"query_string": query_string}
|
||||
consumer = TokenAuthMiddleware(callback)
|
||||
consumer(scope)
|
||||
|
||||
|
||||
def test_header_correct_token(factories):
|
||||
user = factories["users.User"]()
|
||||
payload = jwt_payload_handler(user)
|
||||
token = jwt_encode_handler(payload)
|
||||
|
||||
def callback(scope):
|
||||
assert scope["user"] == user
|
||||
|
||||
scope = {"query_string": "token={}".format(token).encode("utf-8")}
|
||||
consumer = TokenAuthMiddleware(callback)
|
||||
consumer(scope)
|
||||
|
|
@ -17,7 +17,7 @@ from django import urls
|
|||
"/api/v1/auth/registration/account-confirm-email/key",
|
||||
"/api/v1/history/listenings",
|
||||
"/api/v1/radios/sessions",
|
||||
"/api/v1/users/users/me",
|
||||
"/api/v1/users/me",
|
||||
"/api/v1/federation/follows/library",
|
||||
"/api/v1/manage/accounts",
|
||||
"/api/v1/oauth/apps",
|
||||
|
|
|
|||
|
|
@ -201,15 +201,6 @@ def test_attachment_serializer_existing_file(factories, to_api_date):
|
|||
attachment.file.crop["200x200"].url
|
||||
),
|
||||
},
|
||||
# XXX: BACKWARD COMPATIBILITY
|
||||
"original": federation_utils.full_url(attachment.file.url),
|
||||
"medium_square_crop": federation_utils.full_url(
|
||||
attachment.file.crop["200x200"].url
|
||||
),
|
||||
"small_square_crop": federation_utils.full_url(
|
||||
attachment.file.crop["200x200"].url
|
||||
),
|
||||
"square_crop": federation_utils.full_url(attachment.file.crop["200x200"].url),
|
||||
}
|
||||
|
||||
serializer = serializers.AttachmentSerializer(attachment)
|
||||
|
|
@ -237,17 +228,6 @@ def test_attachment_serializer_remote_file(factories, to_api_date):
|
|||
proxy_url + "?next=medium_square_crop"
|
||||
),
|
||||
},
|
||||
# XXX: BACKWARD COMPATIBILITY
|
||||
"original": federation_utils.full_url(proxy_url + "?next=original"),
|
||||
"medium_square_crop": federation_utils.full_url(
|
||||
proxy_url + "?next=medium_square_crop"
|
||||
),
|
||||
"square_crop": federation_utils.full_url(
|
||||
proxy_url + "?next=medium_square_crop"
|
||||
),
|
||||
"small_square_crop": federation_utils.full_url(
|
||||
proxy_url + "?next=medium_square_crop"
|
||||
),
|
||||
}
|
||||
|
||||
serializer = serializers.AttachmentSerializer(attachment)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ def test_user_can_get_his_favorites(
|
|||
api_request, factories, logged_in_api_client, client
|
||||
):
|
||||
request = api_request.get("/")
|
||||
logged_in_api_client.user.create_actor()
|
||||
favorite = factories["favorites.TrackFavorite"](user=logged_in_api_client.user)
|
||||
factories["favorites.TrackFavorite"]()
|
||||
url = reverse("api:v1:favorites:tracks-list")
|
||||
response = logged_in_api_client.get(url, {"user": logged_in_api_client.user.pk})
|
||||
response = logged_in_api_client.get(url, {"scope": "me"})
|
||||
expected = [
|
||||
serializers.UserTrackFavoriteSerializer(
|
||||
favorite, context={"request": request}
|
||||
|
|
|
|||
|
|
@ -388,7 +388,6 @@ def test_paginated_collection_serializer(factories):
|
|||
"@context": jsonld.get_default_context(),
|
||||
"type": "Collection",
|
||||
"id": conf["id"],
|
||||
"actor": actor.fid,
|
||||
"attributedTo": actor.fid,
|
||||
"totalItems": len(uploads),
|
||||
"current": conf["id"] + "?page=1",
|
||||
|
|
@ -486,7 +485,6 @@ def test_collection_page_serializer(factories):
|
|||
"@context": jsonld.get_default_context(),
|
||||
"type": "CollectionPage",
|
||||
"id": conf["id"] + "?page=2",
|
||||
"actor": actor.fid,
|
||||
"attributedTo": actor.fid,
|
||||
"totalItems": len(uploads),
|
||||
"partOf": conf["id"],
|
||||
|
|
@ -521,7 +519,6 @@ def test_music_library_serializer_to_ap(factories):
|
|||
"id": library.fid,
|
||||
"name": library.name,
|
||||
"summary": library.description,
|
||||
"actor": library.actor.fid,
|
||||
"attributedTo": library.actor.fid,
|
||||
"totalItems": 0,
|
||||
"current": library.fid + "?page=1",
|
||||
|
|
@ -764,11 +761,6 @@ def test_activity_pub_album_serializer_to_ap(factories):
|
|||
"type": "Album",
|
||||
"id": album.fid,
|
||||
"name": album.title,
|
||||
"cover": {
|
||||
"type": "Link",
|
||||
"mediaType": "image/jpeg",
|
||||
"href": utils.full_url(album.attachment_cover.file.url),
|
||||
},
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
|
|
@ -815,7 +807,7 @@ def test_activity_pub_album_serializer_from_ap_create(factories, faker, now):
|
|||
"type": "Album",
|
||||
"id": "https://album.example",
|
||||
"name": faker.sentence(),
|
||||
"cover": {"type": "Link", "mediaType": "image/jpeg", "href": faker.url()},
|
||||
"image": {"type": "Link", "mediaType": "image/jpeg", "href": faker.url()},
|
||||
"musicbrainzId": faker.uuid4(),
|
||||
"published": now.isoformat(),
|
||||
"released": released.isoformat(),
|
||||
|
|
@ -839,8 +831,8 @@ def test_activity_pub_album_serializer_from_ap_create(factories, faker, now):
|
|||
assert str(album.mbid) == payload["musicbrainzId"]
|
||||
assert album.release_date == released
|
||||
assert album.artist == artist
|
||||
assert album.attachment_cover.url == payload["cover"]["href"]
|
||||
assert album.attachment_cover.mimetype == payload["cover"]["mediaType"]
|
||||
assert album.attachment_cover.url == payload["image"]["href"]
|
||||
assert album.attachment_cover.mimetype == payload["image"]["mediaType"]
|
||||
assert sorted(album.tagged_items.values_list("tag__name", flat=True)) == [
|
||||
"Punk",
|
||||
"Rock",
|
||||
|
|
@ -879,7 +871,7 @@ def test_activity_pub_album_serializer_from_ap_update(factories, faker):
|
|||
"type": "Album",
|
||||
"id": album.fid,
|
||||
"name": faker.sentence(),
|
||||
"cover": {"type": "Link", "mediaType": "image/jpeg", "href": faker.url()},
|
||||
"image": {"type": "Link", "mediaType": "image/jpeg", "href": faker.url()},
|
||||
"musicbrainzId": faker.uuid4(),
|
||||
"published": album.creation_date.isoformat(),
|
||||
"released": released.isoformat(),
|
||||
|
|
@ -904,8 +896,8 @@ def test_activity_pub_album_serializer_from_ap_update(factories, faker):
|
|||
assert album.title == payload["name"]
|
||||
assert str(album.mbid) == payload["musicbrainzId"]
|
||||
assert album.release_date == released
|
||||
assert album.attachment_cover.url == payload["cover"]["href"]
|
||||
assert album.attachment_cover.mimetype == payload["cover"]["mediaType"]
|
||||
assert album.attachment_cover.url == payload["image"]["href"]
|
||||
assert album.attachment_cover.mimetype == payload["image"]["mediaType"]
|
||||
assert sorted(album.tagged_items.values_list("tag__name", flat=True)) == [
|
||||
"Punk",
|
||||
"Rock",
|
||||
|
|
@ -996,7 +988,7 @@ def test_activity_pub_track_serializer_from_ap(factories, r_mock, mocker):
|
|||
"content": "Album summary",
|
||||
"mediaType": "text/markdown",
|
||||
"attributedTo": album_attributed_to.fid,
|
||||
"cover": {
|
||||
"image": {
|
||||
"type": "Link",
|
||||
"href": "https://cover.image/test.png",
|
||||
"mediaType": "image/png",
|
||||
|
|
@ -1066,8 +1058,8 @@ def test_activity_pub_track_serializer_from_ap(factories, r_mock, mocker):
|
|||
assert track.attachment_cover.mimetype == data["image"]["mediaType"]
|
||||
|
||||
assert album.from_activity == activity
|
||||
assert album.attachment_cover.url == data["album"]["cover"]["href"]
|
||||
assert album.attachment_cover.mimetype == data["album"]["cover"]["mediaType"]
|
||||
assert album.attachment_cover.url == data["album"]["image"]["href"]
|
||||
assert album.attachment_cover.mimetype == data["album"]["image"]["mediaType"]
|
||||
assert album.title == data["album"]["name"]
|
||||
assert album.fid == data["album"]["id"]
|
||||
assert str(album.mbid) == data["album"]["musicbrainzId"]
|
||||
|
|
@ -1196,7 +1188,7 @@ def test_activity_pub_upload_serializer_from_ap(factories, mocker, r_mock):
|
|||
"musicbrainzId": str(uuid.uuid4()),
|
||||
"published": published.isoformat(),
|
||||
"released": released.isoformat(),
|
||||
"cover": {
|
||||
"image": {
|
||||
"type": "Link",
|
||||
"href": "https://cover.image/test.png",
|
||||
"mediaType": "image/png",
|
||||
|
|
@ -1222,7 +1214,7 @@ def test_activity_pub_upload_serializer_from_ap(factories, mocker, r_mock):
|
|||
],
|
||||
},
|
||||
}
|
||||
r_mock.get(data["track"]["album"]["cover"]["href"], body=io.BytesIO(b"coucou"))
|
||||
r_mock.get(data["track"]["album"]["image"]["href"], body=io.BytesIO(b"coucou"))
|
||||
|
||||
serializer = serializers.UploadSerializer(data=data, context={"activity": activity})
|
||||
assert serializer.is_valid(raise_exception=True)
|
||||
|
|
@ -1266,7 +1258,7 @@ def test_activity_pub_upload_serializer_from_ap_update(factories, mocker, now, r
|
|||
"library": library.fid,
|
||||
"track": serializers.TrackSerializer(upload.track).data,
|
||||
}
|
||||
r_mock.get(data["track"]["album"]["cover"]["href"], body=io.BytesIO(b"coucou"))
|
||||
r_mock.get(data["track"]["album"]["image"]["url"], body=io.BytesIO(b"coucou"))
|
||||
|
||||
serializer = serializers.UploadSerializer(upload, data=data)
|
||||
assert serializer.is_valid(raise_exception=True)
|
||||
|
|
@ -1628,7 +1620,6 @@ def test_channel_actor_outbox_serializer(factories):
|
|||
"@context": jsonld.get_default_context(),
|
||||
"type": "OrderedCollection",
|
||||
"id": channel.actor.outbox_url,
|
||||
"actor": channel.actor.fid,
|
||||
"attributedTo": channel.actor.fid,
|
||||
"totalItems": len(uploads),
|
||||
"first": channel.actor.outbox_url + "?page=1",
|
||||
|
|
|
|||
|
|
@ -384,11 +384,6 @@ def test_music_upload_detail_private_approved_follow(
|
|||
("text/html,application/xhtml+xml", True, True),
|
||||
("text/html,application/json", True, True),
|
||||
("", True, False),
|
||||
(
|
||||
"*/*",
|
||||
True,
|
||||
False,
|
||||
), # XXX: compat with older versions of Funkwhale that miss the Accept header
|
||||
(None, True, False),
|
||||
("application/json", True, False),
|
||||
("application/activity+json", True, False),
|
||||
|
|
|
|||
|
|
@ -196,15 +196,6 @@ def test_album_serializer(factories, to_api_date):
|
|||
assert serializer.data == expected
|
||||
|
||||
|
||||
def test_album_serializer_empty_cover(factories, to_api_date):
|
||||
# XXX: BACKWARD COMPATIBILITY
|
||||
album = factories["music.Album"](attachment_cover=None)
|
||||
|
||||
serializer = serializers.AlbumSerializer(album)
|
||||
|
||||
assert serializer.data["cover"] == {}
|
||||
|
||||
|
||||
def test_track_serializer(factories, to_api_date):
|
||||
actor = factories["federation.Actor"]()
|
||||
upload = factories["music.Upload"](
|
||||
|
|
|
|||
|
|
@ -660,7 +660,7 @@ def test_federation_audio_track_to_metadata(now, mocker):
|
|||
},
|
||||
}
|
||||
],
|
||||
"cover": {
|
||||
"image": {
|
||||
"type": "Link",
|
||||
"href": "http://cover.test",
|
||||
"mediaType": "image/png",
|
||||
|
|
@ -713,8 +713,8 @@ def test_federation_audio_track_to_metadata(now, mocker):
|
|||
"tags": ["AlbumTag"],
|
||||
"description": {"content_type": "text/plain", "text": "album desc"},
|
||||
"cover_data": {
|
||||
"mimetype": serializer.validated_data["album"]["cover"]["mediaType"],
|
||||
"url": serializer.validated_data["album"]["cover"]["href"],
|
||||
"mimetype": serializer.validated_data["album"]["image"]["mediaType"],
|
||||
"url": serializer.validated_data["album"]["image"]["href"],
|
||||
},
|
||||
"artists": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1307,9 +1307,7 @@ def test_get_upload_audio_metadata(logged_in_api_client, factories):
|
|||
assert response.data == serializer.validated_data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_fts", [True, False])
|
||||
def test_search_get(use_fts, settings, logged_in_api_client, factories):
|
||||
settings.USE_FULL_TEXT_SEARCH = use_fts
|
||||
def test_search_get(logged_in_api_client, factories):
|
||||
artist = factories["music.Artist"](name="Foo Fighters")
|
||||
album = factories["music.Album"](title="Foo Bar")
|
||||
track = factories["music.Track"](title="Foo Baz")
|
||||
|
|
@ -1332,8 +1330,7 @@ def test_search_get(use_fts, settings, logged_in_api_client, factories):
|
|||
assert response.data == expected
|
||||
|
||||
|
||||
def test_search_get_fts_advanced(settings, logged_in_api_client, factories):
|
||||
settings.USE_FULL_TEXT_SEARCH = True
|
||||
def test_search_get_fts_advanced(logged_in_api_client, factories):
|
||||
artist1 = factories["music.Artist"](name="Foo Bighters")
|
||||
artist2 = factories["music.Artist"](name="Bar Fighter")
|
||||
factories["music.Artist"]()
|
||||
|
|
@ -1353,8 +1350,7 @@ def test_search_get_fts_advanced(settings, logged_in_api_client, factories):
|
|||
assert response.data == expected
|
||||
|
||||
|
||||
def test_search_get_fts_stop_words(settings, logged_in_api_client, factories):
|
||||
settings.USE_FULL_TEXT_SEARCH = True
|
||||
def test_search_get_fts_stop_words(logged_in_api_client, factories):
|
||||
artist = factories["music.Artist"](name="she")
|
||||
factories["music.Artist"](name="something else")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue