Commit 6c7ee54d authored by Eliot Berriot's avatar Eliot Berriot 💬

Merge branch '573-subsonic-type' into 'develop'

Fix #573: Added "type: funkwhale" and "funkwhale-version" in Subsonic responses

Closes #573

See merge request funkwhale/funkwhale!456
parents c96d182d 941f2f66
......@@ -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
......
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
......
......@@ -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)
......
Added "type: funkwhale" and "funkwhale-version" in Subsonic responses (#573)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment