[bug] Fix issue with Ref objects
Some checks failed
Some checks failed
This commit is contained in:
@ -265,7 +265,7 @@ class StatusHandler(tornado.web.RequestHandler):
|
|||||||
|
|
||||||
def get(self) -> None:
|
def get(self) -> None:
|
||||||
try:
|
try:
|
||||||
result = self.core.playlists.as_list().get()
|
refs = self.core.playlists.as_list().get()
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Failed to list playlists")
|
logger.exception("Failed to list playlists")
|
||||||
self.set_status(500)
|
self.set_status(500)
|
||||||
@ -275,21 +275,22 @@ class StatusHandler(tornado.web.RequestHandler):
|
|||||||
"count": 0,
|
"count": 0,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
result_typed = cast("list[Playlist]", result)
|
smart = []
|
||||||
smart = [p for p in result_typed if p.name and p.name.startswith(self.prefix)]
|
for ref in refs:
|
||||||
self.write(
|
if ref.name and ref.name.startswith(self.prefix):
|
||||||
{
|
try:
|
||||||
"smart_playlists": [
|
pl = self.core.playlists.lookup(cast("Uri", ref.uri)).get()
|
||||||
{
|
except Exception:
|
||||||
"name": p.name,
|
logger.exception("Failed to lookup playlist %s", ref.uri)
|
||||||
"uri": p.uri,
|
continue
|
||||||
"tracks": len(p.tracks) if p.tracks else 0,
|
if pl is None:
|
||||||
}
|
continue
|
||||||
for p in smart
|
smart.append({
|
||||||
],
|
"name": pl.name,
|
||||||
"count": len(smart),
|
"uri": pl.uri,
|
||||||
}
|
"tracks": len(pl.tracks) if pl.tracks else 0,
|
||||||
)
|
})
|
||||||
|
self.write({"smart_playlists": smart, "count": len(smart)})
|
||||||
|
|
||||||
|
|
||||||
def _parse_search_uris(config: Config) -> list[Uri] | None:
|
def _parse_search_uris(config: Config) -> list[Uri] | None:
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from unittest import mock
|
|||||||
|
|
||||||
import tornado.testing
|
import tornado.testing
|
||||||
import tornado.web
|
import tornado.web
|
||||||
from mopidy.models import Playlist, Track
|
from mopidy.models import Playlist, Ref, Track
|
||||||
|
|
||||||
from mopidy_smartplaylists.web import (
|
from mopidy_smartplaylists.web import (
|
||||||
AlbumMixHandler,
|
AlbumMixHandler,
|
||||||
@ -236,18 +236,24 @@ class TestStatusHandler:
|
|||||||
def test_returns_smart_playlists(self):
|
def test_returns_smart_playlists(self):
|
||||||
core = mock.Mock()
|
core = mock.Mock()
|
||||||
core.playlists.as_list.return_value.get.return_value = [
|
core.playlists.as_list.return_value.get.return_value = [
|
||||||
Playlist(
|
Ref(uri="mopidy:smartplaylists:jazz_mix", name="[Smart] Jazz Mix", type="playlist"),
|
||||||
name="[Smart] Jazz Mix",
|
Ref(uri="mopidy:playlist:normal", name="Normal Playlist", type="playlist"),
|
||||||
uri="mopidy:smartplaylists:jazz_mix",
|
|
||||||
tracks=[Track(uri="dummy:1", name="T")],
|
|
||||||
),
|
|
||||||
Playlist(
|
|
||||||
name="Normal Playlist",
|
|
||||||
uri="mopidy:playlist:normal",
|
|
||||||
tracks=[],
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def lookup_side_effect(uri):
|
||||||
|
result = mock.Mock()
|
||||||
|
playlists = {
|
||||||
|
"mopidy:smartplaylists:jazz_mix": Playlist(
|
||||||
|
name="[Smart] Jazz Mix",
|
||||||
|
uri="mopidy:smartplaylists:jazz_mix",
|
||||||
|
tracks=[Track(uri="dummy:1", name="T")],
|
||||||
|
),
|
||||||
|
}
|
||||||
|
result.get.return_value = playlists.get(uri)
|
||||||
|
return result
|
||||||
|
|
||||||
|
core.playlists.lookup.side_effect = lookup_side_effect
|
||||||
|
|
||||||
app = tornado.web.Application(
|
app = tornado.web.Application(
|
||||||
[
|
[
|
||||||
(r"/status", StatusHandler, {"core": core, "prefix": "[Smart]"}),
|
(r"/status", StatusHandler, {"core": core, "prefix": "[Smart]"}),
|
||||||
|
|||||||
Reference in New Issue
Block a user