Files
musicdl-catalog-sync-suite/Music_Server/tests/test_plugin_routes.py
T

134 lines
5.4 KiB
Python

import unittest
from fastapi.testclient import TestClient
from music_server.app import create_app
class PluginRouteTests(unittest.TestCase):
def test_plugin_js_route_returns_importable_plugin_asset(self):
client = TestClient(create_app())
response = client.get("/plugins/music_server.js")
self.assertEqual(200, response.status_code)
self.assertIn("javascript", response.headers.get("content-type", ""))
body = response.text
self.assertIn('platform: "Music_Server"', body)
self.assertIn('srcUrl: "http://testserver/plugins/music_server.js"', body)
self.assertNotIn("__MUSIC_SERVER_PLUGIN_SRC_URL__", body)
self.assertEqual(
"no-store, no-cache, must-revalidate, max-age=0",
response.headers.get("cache-control"),
)
def test_lan_plugin_js_route_returns_importable_plugin_asset(self):
client = TestClient(create_app())
response = client.get("/plugins/music_server_lan.js")
self.assertEqual(200, response.status_code)
self.assertIn("javascript", response.headers.get("content-type", ""))
body = response.text
self.assertIn('platform: "Music_Server_LAN"', body)
self.assertIn('srcUrl: "http://testserver/plugins/music_server_lan.js"', body)
self.assertNotIn("__MUSIC_SERVER_PLUGIN_SRC_URL__", body)
self.assertEqual(
"no-store, no-cache, must-revalidate, max-age=0",
response.headers.get("cache-control"),
)
def test_private_plugin_asset_exposes_artist_and_sheet_support(self):
client = TestClient(create_app())
response = client.get("/plugins/music_server.js")
self.assertEqual(200, response.status_code)
body = response.text
self.assertIn('supportedSearchType: ["music", "artist", "sheet"]', body)
self.assertIn("/mf/v1/search/artists", body)
self.assertIn("/mf/v1/search/sheets", body)
self.assertIn("function getArtistWorks(", body)
def test_lan_plugin_asset_exposes_artist_and_sheet_support(self):
client = TestClient(create_app())
response = client.get("/plugins/music_server_lan.js")
self.assertEqual(200, response.status_code)
body = response.text
self.assertIn('supportedSearchType: ["music", "artist", "sheet"]', body)
self.assertIn("/mf/v1/search/artists", body)
self.assertIn("/mf/v1/search/sheets", body)
self.assertIn("function getArtistWorks(", body)
def test_plugin_assets_preserve_raw_lrc_field(self):
client = TestClient(create_app())
private_response = client.get("/plugins/music_server.js")
lan_response = client.get("/plugins/music_server_lan.js")
self.assertEqual(200, private_response.status_code)
self.assertEqual(200, lan_response.status_code)
self.assertIn("rawLrc", private_response.text)
self.assertIn("rawLrc", lan_response.text)
def test_plugin_assets_use_play_count_field_only(self):
client = TestClient(create_app())
private_response = client.get("/plugins/music_server.js")
lan_response = client.get("/plugins/music_server_lan.js")
self.assertEqual(200, private_response.status_code)
self.assertEqual(200, lan_response.status_code)
self.assertIn("item.play_count", private_response.text)
self.assertIn("result.play_count", private_response.text)
self.assertNotIn("item.playCount", private_response.text)
self.assertNotIn("result.playCount", private_response.text)
self.assertIn("item.play_count", lan_response.text)
self.assertIn("result.play_count", lan_response.text)
self.assertNotIn("item.playCount", lan_response.text)
self.assertNotIn("result.playCount", lan_response.text)
def test_plugin_assets_expose_get_lyric_method(self):
client = TestClient(create_app())
private_response = client.get("/plugins/music_server.js")
lan_response = client.get("/plugins/music_server_lan.js")
self.assertEqual(200, private_response.status_code)
self.assertEqual(200, lan_response.status_code)
self.assertIn("async function getLyric(", private_response.text)
self.assertIn('"/mf/v1/songs/" + songId + "/lyric"', private_response.text)
self.assertIn("getLyric: getLyric", private_response.text)
self.assertIn("async function getLyric(", lan_response.text)
self.assertIn('"/mf/v1/songs/" + songId + "/lyric"', lan_response.text)
self.assertIn("getLyric: getLyric", lan_response.text)
def test_plugin_manifest_route_returns_plugin_url(self):
client = TestClient(create_app())
response = client.get("/plugins/music_server.json")
self.assertEqual(200, response.status_code)
self.assertIn("application/json", response.headers.get("content-type", ""))
payload = response.json()
self.assertEqual(2, len(payload["plugins"]))
self.assertEqual(
[
{
"name": "Music_Server",
"url": "http://testserver/plugins/music_server.js",
},
{
"name": "Music_Server LAN",
"url": "http://testserver/plugins/music_server_lan.js",
},
],
payload["plugins"],
)
if __name__ == "__main__":
unittest.main()