1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-14 14:12:17 +00:00
supysonic/tests/frontend/test_playlist.py

125 lines
4.1 KiB
Python
Raw Normal View History

2017-11-20 20:33:38 +00:00
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
2018-03-04 20:49:56 +00:00
# Copyright (C) 2017-2018 Alban 'spl0k' Féron
2017-11-20 20:33:38 +00:00
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
2017-11-20 20:33:38 +00:00
import uuid
from pony.orm import db_session
from supysonic.db import Folder, Artist, Album, Track, Playlist, User
2017-11-20 20:33:38 +00:00
from .frontendtestbase import FrontendTestBase
2019-06-29 15:25:44 +00:00
2017-11-20 20:33:38 +00:00
class PlaylistTestCase(FrontendTestBase):
def setUp(self):
2020-11-22 15:12:14 +00:00
super().setUp()
2017-11-20 20:33:38 +00:00
2017-12-19 22:16:55 +00:00
with db_session:
2019-06-29 15:25:44 +00:00
folder = Folder(name="Root", path="tests/assets", root=True)
artist = Artist(name="Artist!")
album = Album(name="Album!", artist=artist)
2017-12-19 22:16:55 +00:00
track = Track(
2019-06-29 15:25:44 +00:00
path="tests/assets/23bytes",
title="23bytes",
artist=artist,
album=album,
folder=folder,
root_folder=folder,
duration=2,
disc=1,
number=1,
bitrate=320,
last_modification=0,
2017-12-19 22:16:55 +00:00
)
2019-06-29 15:25:44 +00:00
playlist = Playlist(name="Playlist!", user=User.get(name="alice"))
2017-12-19 22:16:55 +00:00
for _ in range(4):
playlist.add(track)
self.playlistid = playlist.id
2017-11-20 20:33:38 +00:00
def test_index(self):
2019-06-29 15:25:44 +00:00
self._login("alice", "Alic3")
rv = self.client.get("/playlist")
self.assertIn("My playlists", rv.data)
2017-11-20 20:33:38 +00:00
def test_details(self):
2019-06-29 15:25:44 +00:00
self._login("alice", "Alic3")
rv = self.client.get("/playlist/string", follow_redirects=True)
self.assertIn("Invalid", rv.data)
rv = self.client.get("/playlist/" + str(uuid.uuid4()), follow_redirects=True)
self.assertIn("Unknown", rv.data)
rv = self.client.get("/playlist/" + str(self.playlistid))
self.assertIn("Playlist!", rv.data)
self.assertIn("23bytes", rv.data)
self.assertIn("Artist!", rv.data)
self.assertIn("Album!", rv.data)
2017-11-20 20:33:38 +00:00
def test_update(self):
2019-06-29 15:25:44 +00:00
self._login("bob", "B0b")
rv = self.client.post("/playlist/string", follow_redirects=True)
self.assertIn("Invalid", rv.data)
rv = self.client.post("/playlist/" + str(uuid.uuid4()), follow_redirects=True)
self.assertIn("Unknown", rv.data)
rv = self.client.post(
"/playlist/" + str(self.playlistid), follow_redirects=True
)
self.assertNotIn("updated", rv.data)
self.assertIn("not allowed", rv.data)
2017-11-20 20:33:38 +00:00
self._logout()
2019-06-29 15:25:44 +00:00
self._login("alice", "Alic3")
rv = self.client.post(
"/playlist/" + str(self.playlistid), follow_redirects=True
)
self.assertNotIn("updated", rv.data)
self.assertIn("Missing", rv.data)
2017-12-19 22:16:55 +00:00
with db_session:
2019-06-29 15:25:44 +00:00
self.assertEqual(Playlist[self.playlistid].name, "Playlist!")
rv = self.client.post(
"/playlist/" + str(self.playlistid),
data={"name": "abc", "public": True},
follow_redirects=True,
)
self.assertIn("updated", rv.data)
self.assertNotIn("not allowed", rv.data)
2017-12-19 22:16:55 +00:00
with db_session:
playlist = Playlist[self.playlistid]
2019-06-29 15:25:44 +00:00
self.assertEqual(playlist.name, "abc")
2017-12-19 22:16:55 +00:00
self.assertTrue(playlist.public)
2017-11-20 20:33:38 +00:00
def test_delete(self):
2019-06-29 15:25:44 +00:00
self._login("bob", "B0b")
rv = self.client.get("/playlist/del/string", follow_redirects=True)
self.assertIn("Invalid", rv.data)
rv = self.client.get(
"/playlist/del/" + str(uuid.uuid4()), follow_redirects=True
)
self.assertIn("Unknown", rv.data)
rv = self.client.get(
"/playlist/del/" + str(self.playlistid), follow_redirects=True
)
self.assertIn("not allowed", rv.data)
2017-12-19 22:16:55 +00:00
with db_session:
self.assertEqual(Playlist.select().count(), 1)
2017-11-20 20:33:38 +00:00
self._logout()
2019-06-29 15:25:44 +00:00
self._login("alice", "Alic3")
rv = self.client.get(
"/playlist/del/" + str(self.playlistid), follow_redirects=True
)
self.assertIn("deleted", rv.data)
2017-12-19 22:16:55 +00:00
with db_session:
self.assertEqual(Playlist.select().count(), 0)
2017-11-20 20:33:38 +00:00
2019-06-29 15:25:44 +00:00
if __name__ == "__main__":
unittest.main()