From 941f2f667749e5192f0480814664604c548803d4 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Sun, 21 Oct 2018 17:34:52 +0200 Subject: [PATCH] Fix #573: Added "type: funkwhale" and "funkwhale-version" in Subsonic responses --- api/funkwhale_api/subsonic/renderers.py | 11 ++++++++++- api/tests/subsonic/test_renderers.py | 10 +++++++++- api/tests/subsonic/test_views.py | 9 ++++++++- changes/changelog.d/573.enhancement | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 changes/changelog.d/573.enhancement diff --git a/api/funkwhale_api/subsonic/renderers.py b/api/funkwhale_api/subsonic/renderers.py index fac12d6c1..fd98633aa 100644 --- a/api/funkwhale_api/subsonic/renderers.py +++ b/api/funkwhale_api/subsonic/renderers.py @@ -2,13 +2,22 @@ import xml.etree.ElementTree as ET from rest_framework import renderers +import funkwhale_api + class SubsonicJSONRenderer(renderers.JSONRenderer): def render(self, data, accepted_media_type=None, renderer_context=None): if not data: # when stream view is called, we don't have any data return super().render(data, accepted_media_type, renderer_context) - final = {"subsonic-response": {"status": "ok", "version": "1.16.0"}} + final = { + "subsonic-response": { + "status": "ok", + "version": "1.16.0", + "type": "funkwhale", + "funkwhale-version": funkwhale_api.__version__, + } + } final["subsonic-response"].update(data) if "error" in final: # an error was returned diff --git a/api/tests/subsonic/test_renderers.py b/api/tests/subsonic/test_renderers.py index 301fee8b5..e234a993a 100644 --- a/api/tests/subsonic/test_renderers.py +++ b/api/tests/subsonic/test_renderers.py @@ -1,13 +1,21 @@ import json import xml.etree.ElementTree as ET +import funkwhale_api + from funkwhale_api.subsonic import renderers def test_json_renderer(): data = {"hello": "world"} expected = { - "subsonic-response": {"status": "ok", "version": "1.16.0", "hello": "world"} + "subsonic-response": { + "status": "ok", + "version": "1.16.0", + "type": "funkwhale", + "funkwhale-version": funkwhale_api.__version__, + "hello": "world", + } } renderer = renderers.SubsonicJSONRenderer() assert json.loads(renderer.render(data)) == expected diff --git a/api/tests/subsonic/test_views.py b/api/tests/subsonic/test_views.py index 94cbd8c16..f856146ec 100644 --- a/api/tests/subsonic/test_views.py +++ b/api/tests/subsonic/test_views.py @@ -5,6 +5,8 @@ import pytest from django.urls import reverse from django.utils import timezone +import funkwhale_api + from funkwhale_api.music import models as music_models from funkwhale_api.music import views as music_views from funkwhale_api.subsonic import renderers, serializers @@ -18,7 +20,12 @@ def test_render_content_json(db, api_client): url = reverse("api:subsonic-ping") response = api_client.get(url, {"f": "json"}) - expected = {"status": "ok", "version": "1.16.0"} + expected = { + "status": "ok", + "version": "1.16.0", + "type": "funkwhale", + "funkwhale-version": funkwhale_api.__version__, + } assert response.status_code == 200 assert json.loads(response.content) == render_json(expected) diff --git a/changes/changelog.d/573.enhancement b/changes/changelog.d/573.enhancement new file mode 100644 index 000000000..45a29e809 --- /dev/null +++ b/changes/changelog.d/573.enhancement @@ -0,0 +1 @@ +Added "type: funkwhale" and "funkwhale-version" in Subsonic responses (#573)