kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Fix #573: Added "type: funkwhale" and "funkwhale-version" in Subsonic responses
rodzic
a6264d7deb
commit
941f2f6677
|
@ -2,13 +2,22 @@ import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from rest_framework import renderers
|
from rest_framework import renderers
|
||||||
|
|
||||||
|
import funkwhale_api
|
||||||
|
|
||||||
|
|
||||||
class SubsonicJSONRenderer(renderers.JSONRenderer):
|
class SubsonicJSONRenderer(renderers.JSONRenderer):
|
||||||
def render(self, data, accepted_media_type=None, renderer_context=None):
|
def render(self, data, accepted_media_type=None, renderer_context=None):
|
||||||
if not data:
|
if not data:
|
||||||
# when stream view is called, we don't have any data
|
# when stream view is called, we don't have any data
|
||||||
return super().render(data, accepted_media_type, renderer_context)
|
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)
|
final["subsonic-response"].update(data)
|
||||||
if "error" in final:
|
if "error" in final:
|
||||||
# an error was returned
|
# an error was returned
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
import json
|
import json
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
import funkwhale_api
|
||||||
|
|
||||||
from funkwhale_api.subsonic import renderers
|
from funkwhale_api.subsonic import renderers
|
||||||
|
|
||||||
|
|
||||||
def test_json_renderer():
|
def test_json_renderer():
|
||||||
data = {"hello": "world"}
|
data = {"hello": "world"}
|
||||||
expected = {
|
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()
|
renderer = renderers.SubsonicJSONRenderer()
|
||||||
assert json.loads(renderer.render(data)) == expected
|
assert json.loads(renderer.render(data)) == expected
|
||||||
|
|
|
@ -5,6 +5,8 @@ import pytest
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
import funkwhale_api
|
||||||
|
|
||||||
from funkwhale_api.music import models as music_models
|
from funkwhale_api.music import models as music_models
|
||||||
from funkwhale_api.music import views as music_views
|
from funkwhale_api.music import views as music_views
|
||||||
from funkwhale_api.subsonic import renderers, serializers
|
from funkwhale_api.subsonic import renderers, serializers
|
||||||
|
@ -18,7 +20,12 @@ def test_render_content_json(db, api_client):
|
||||||
url = reverse("api:subsonic-ping")
|
url = reverse("api:subsonic-ping")
|
||||||
response = api_client.get(url, {"f": "json"})
|
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 response.status_code == 200
|
||||||
assert json.loads(response.content) == render_json(expected)
|
assert json.loads(response.content) == render_json(expected)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added "type: funkwhale" and "funkwhale-version" in Subsonic responses (#573)
|
Ładowanie…
Reference in New Issue