2017-11-14 22:19:54 +00:00
|
|
|
# This file is part of Supysonic.
|
|
|
|
# Supysonic is a Python implementation of the Subsonic server API.
|
|
|
|
#
|
2024-06-02 10:33:08 +00:00
|
|
|
# Copyright (C) 2017-2024 Alban 'spl0k' Féron
|
2017-11-14 22:19:54 +00:00
|
|
|
#
|
|
|
|
# Distributed under terms of the GNU AGPLv3 license.
|
|
|
|
|
2020-11-29 16:24:28 +00:00
|
|
|
import unittest
|
2017-11-14 22:19:54 +00:00
|
|
|
import uuid
|
|
|
|
|
2018-08-11 14:16:34 +00:00
|
|
|
from supysonic.db import Folder, Artist, Album, Track, User, ClientPrefs
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
from .apitestbase import ApiTestBase
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2017-11-14 22:19:54 +00:00
|
|
|
class AnnotationTestCase(ApiTestBase):
|
|
|
|
def setUp(self):
|
2020-11-22 15:12:14 +00:00
|
|
|
super().setUp()
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2022-12-18 16:24:05 +00:00
|
|
|
root = Folder.create(name="Root", root=True, path="tests")
|
|
|
|
folder = Folder.create(
|
|
|
|
name="Folder", root=False, path="tests/assets", parent=root
|
|
|
|
)
|
|
|
|
artist = Artist.create(name="Artist")
|
|
|
|
album = Album.create(name="Album", artist=artist)
|
|
|
|
|
|
|
|
# Populate folder ids
|
|
|
|
root = Folder.get(name="Root")
|
|
|
|
folder = Folder.get(name="Folder")
|
|
|
|
|
|
|
|
track = Track.create(
|
|
|
|
title="Track",
|
|
|
|
album=album,
|
|
|
|
artist=artist,
|
|
|
|
disc=1,
|
|
|
|
number=1,
|
|
|
|
path="tests/assets/empty",
|
|
|
|
folder=folder,
|
|
|
|
root_folder=root,
|
|
|
|
duration=2,
|
|
|
|
bitrate=320,
|
|
|
|
last_modification=0,
|
|
|
|
)
|
2017-12-23 21:59:04 +00:00
|
|
|
|
2022-12-18 16:24:05 +00:00
|
|
|
self.folderid = folder.id
|
|
|
|
self.artistid = artist.id
|
|
|
|
self.albumid = album.id
|
|
|
|
self.trackid = track.id
|
|
|
|
self.user = User.get(name="alice")
|
|
|
|
self.prefs = ClientPrefs.create(user=self.user, client_name="tests")
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
def test_star(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", error=10)
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("star", {"id": "unknown"}, error=0)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"albumId": "unknown"}, error=0)
|
|
|
|
self._make_request("star", {"artistId": "unknown"}, error=0)
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("star", {"id": str(uuid.uuid4())}, error=70)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"albumId": str(uuid.uuid4())}, error=70)
|
|
|
|
self._make_request("star", {"artistId": str(uuid.uuid4())}, error=70)
|
|
|
|
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("star", {"id": str(self.artistid)}, error=70)
|
|
|
|
self._make_request("star", {"id": str(self.albumid)}, error=70)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"id": str(self.trackid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertIn(
|
|
|
|
"starred", Track[self.trackid].as_subsonic_child(self.user, self.prefs)
|
|
|
|
)
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("star", {"id": str(self.trackid)}, error=0)
|
2017-12-23 21:59:04 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"id": str(self.folderid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertIn("starred", Folder[self.folderid].as_subsonic_child(self.user))
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("star", {"id": str(self.folderid)}, error=0)
|
2017-12-23 21:59:04 +00:00
|
|
|
|
2019-10-01 14:55:23 +00:00
|
|
|
self._make_request("star", {"albumId": str(self.folderid)}, error=0)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"albumId": str(self.artistid)}, error=70)
|
|
|
|
self._make_request("star", {"albumId": str(self.trackid)}, error=70)
|
|
|
|
self._make_request("star", {"albumId": str(self.albumid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertIn("starred", Album[self.albumid].as_subsonic_album(self.user))
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"albumId": str(self.albumid)}, error=0)
|
2017-12-23 21:59:04 +00:00
|
|
|
|
2019-10-01 14:55:23 +00:00
|
|
|
self._make_request("star", {"artistId": str(self.folderid)}, error=0)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"artistId": str(self.albumid)}, error=70)
|
|
|
|
self._make_request("star", {"artistId": str(self.trackid)}, error=70)
|
|
|
|
self._make_request("star", {"artistId": str(self.artistid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertIn("starred", Artist[self.artistid].as_subsonic_artist(self.user))
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("star", {"artistId": str(self.artistid)}, error=0)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
def test_unstar(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
|
|
|
"star",
|
|
|
|
{
|
|
|
|
"id": [str(self.folderid), str(self.trackid)],
|
|
|
|
"artistId": str(self.artistid),
|
|
|
|
"albumId": str(self.albumid),
|
|
|
|
},
|
|
|
|
skip_post=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
self._make_request("unstar", error=10)
|
2020-11-09 11:03:05 +00:00
|
|
|
self._make_request("unstar", {"id": "unknown"}, error=0)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("unstar", {"albumId": "unknown"}, error=0)
|
|
|
|
self._make_request("unstar", {"artistId": "unknown"}, error=0)
|
|
|
|
|
|
|
|
self._make_request("unstar", {"id": str(self.trackid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn(
|
|
|
|
"starred", Track[self.trackid].as_subsonic_child(self.user, self.prefs)
|
|
|
|
)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("unstar", {"id": str(self.folderid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn("starred", Folder[self.folderid].as_subsonic_child(self.user))
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("unstar", {"albumId": str(self.albumid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn("starred", Album[self.albumid].as_subsonic_album(self.user))
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("unstar", {"artistId": str(self.artistid)}, skip_post=True)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn("starred", Artist[self.artistid].as_subsonic_artist(self.user))
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
def test_set_rating(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("setRating", error=10)
|
|
|
|
self._make_request("setRating", {"id": str(self.trackid)}, error=10)
|
|
|
|
self._make_request("setRating", {"rating": 3}, error=10)
|
|
|
|
self._make_request("setRating", {"id": "string", "rating": 3}, error=0)
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(uuid.uuid4()), "rating": 3}, error=70
|
|
|
|
)
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.artistid), "rating": 3}, error=70
|
|
|
|
)
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.albumid), "rating": 3}, error=70
|
|
|
|
)
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.trackid), "rating": "string"}, error=0
|
|
|
|
)
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.trackid), "rating": -1}, error=0
|
|
|
|
)
|
|
|
|
self._make_request("setRating", {"id": str(self.trackid), "rating": 6}, error=0)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn(
|
|
|
|
"userRating", Track[self.trackid].as_subsonic_child(self.user, self.prefs)
|
|
|
|
)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
for i in range(1, 6):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.trackid), "rating": i}, skip_post=True
|
|
|
|
)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertEqual(
|
|
|
|
Track[self.trackid].as_subsonic_child(self.user, self.prefs)[
|
|
|
|
"userRating"
|
|
|
|
],
|
|
|
|
i,
|
|
|
|
)
|
2019-06-29 15:25:44 +00:00
|
|
|
|
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.trackid), "rating": 0}, skip_post=True
|
|
|
|
)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn(
|
|
|
|
"userRating", Track[self.trackid].as_subsonic_child(self.user, self.prefs)
|
|
|
|
)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn(
|
|
|
|
"userRating", Folder[self.folderid].as_subsonic_child(self.user)
|
|
|
|
)
|
2017-11-14 22:19:54 +00:00
|
|
|
for i in range(1, 6):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.folderid), "rating": i}, skip_post=True
|
|
|
|
)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertEqual(
|
|
|
|
Folder[self.folderid].as_subsonic_child(self.user)["userRating"], i
|
|
|
|
)
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
|
|
|
"setRating", {"id": str(self.folderid), "rating": 0}, skip_post=True
|
|
|
|
)
|
2022-12-18 16:24:05 +00:00
|
|
|
self.assertNotIn(
|
|
|
|
"userRating", Folder[self.folderid].as_subsonic_child(self.user)
|
|
|
|
)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
def test_scrobble(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("scrobble", error=10)
|
|
|
|
self._make_request("scrobble", {"id": "song"}, error=0)
|
|
|
|
self._make_request("scrobble", {"id": str(uuid.uuid4())}, error=70)
|
2019-10-01 14:55:23 +00:00
|
|
|
self._make_request("scrobble", {"id": str(self.folderid)}, error=0)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("scrobble", {"id": str(self.trackid)})
|
|
|
|
self._make_request("scrobble", {"id": str(self.trackid), "submission": True})
|
|
|
|
self._make_request("scrobble", {"id": str(self.trackid), "submission": False})
|
2024-06-02 10:33:08 +00:00
|
|
|
self.assertEqual(
|
|
|
|
Track[self.trackid].play_count, 4
|
|
|
|
) # (GET+POST) * (missing submission + submission False)
|
2017-11-14 22:19:54 +00:00
|
|
|
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|