2017-11-19 16:49:31 +00:00
|
|
|
#!/usr/bin/env python
|
2018-03-04 20:49:56 +00:00
|
|
|
# coding: utf-8
|
2017-11-19 16:49:31 +00:00
|
|
|
#
|
|
|
|
# This file is part of Supysonic.
|
|
|
|
# Supysonic is a Python implementation of the Subsonic server API.
|
|
|
|
#
|
2019-04-22 15:48:44 +00:00
|
|
|
# Copyright (C) 2017-2019 Alban 'spl0k' Féron
|
2017-11-19 16:49:31 +00:00
|
|
|
#
|
|
|
|
# Distributed under terms of the GNU AGPLv3 license.
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
|
2018-08-11 14:16:34 +00:00
|
|
|
from pony.orm import db_session
|
|
|
|
|
|
|
|
from supysonic.db import Folder
|
2017-11-19 16:49:31 +00:00
|
|
|
|
|
|
|
from .frontendtestbase import FrontendTestBase
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2017-11-19 16:49:31 +00:00
|
|
|
class FolderTestCase(FrontendTestBase):
|
|
|
|
def test_index(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("bob", "B0b")
|
|
|
|
rv = self.client.get("/folder", follow_redirects=True)
|
|
|
|
self.assertIn("There's nothing much to see", rv.data)
|
|
|
|
self.assertNotIn("Music folders", rv.data)
|
2017-11-19 16:49:31 +00:00
|
|
|
self._logout()
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("alice", "Alic3")
|
|
|
|
rv = self.client.get("/folder")
|
|
|
|
self.assertIn("Music folders", rv.data)
|
2017-11-19 16:49:31 +00:00
|
|
|
|
|
|
|
def test_add_get(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("bob", "B0b")
|
|
|
|
rv = self.client.get("/folder/add", follow_redirects=True)
|
|
|
|
self.assertIn("There's nothing much to see", rv.data)
|
|
|
|
self.assertNotIn("Add Folder", rv.data)
|
2017-11-19 16:49:31 +00:00
|
|
|
self._logout()
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("alice", "Alic3")
|
|
|
|
rv = self.client.get("/folder/add")
|
|
|
|
self.assertIn("Add Folder", rv.data)
|
2017-11-19 16:49:31 +00:00
|
|
|
|
|
|
|
def test_add_post(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("alice", "Alic3")
|
|
|
|
rv = self.client.post("/folder/add")
|
|
|
|
self.assertIn("required", rv.data)
|
|
|
|
rv = self.client.post("/folder/add", data={"name": "name"})
|
|
|
|
self.assertIn("required", rv.data)
|
|
|
|
rv = self.client.post("/folder/add", data={"path": "path"})
|
|
|
|
self.assertIn("required", rv.data)
|
|
|
|
rv = self.client.post("/folder/add", data={"name": "name", "path": "path"})
|
|
|
|
self.assertIn("Add Folder", rv.data)
|
|
|
|
rv = self.client.post(
|
|
|
|
"/folder/add",
|
|
|
|
data={"name": "name", "path": "tests/assets"},
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
self.assertIn("created", rv.data)
|
2017-12-19 22:16:55 +00:00
|
|
|
with db_session:
|
|
|
|
self.assertEqual(Folder.select().count(), 1)
|
2017-11-19 16:49:31 +00:00
|
|
|
|
|
|
|
def test_delete(self):
|
2017-12-19 22:16:55 +00:00
|
|
|
with db_session:
|
2019-06-29 15:25:44 +00:00
|
|
|
folder = Folder(name="folder", path="tests/assets", root=True)
|
|
|
|
|
|
|
|
self._login("bob", "B0b")
|
|
|
|
rv = self.client.get("/folder/del/" + str(folder.id), follow_redirects=True)
|
|
|
|
self.assertIn("There's nothing much to see", rv.data)
|
2017-12-19 22:16:55 +00:00
|
|
|
with db_session:
|
|
|
|
self.assertEqual(Folder.select().count(), 1)
|
2017-11-19 16:49:31 +00:00
|
|
|
self._logout()
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
self._login("alice", "Alic3")
|
|
|
|
rv = self.client.get("/folder/del/string", follow_redirects=True)
|
|
|
|
self.assertIn("badly formed", rv.data)
|
|
|
|
rv = self.client.get("/folder/del/" + str(uuid.uuid4()), follow_redirects=True)
|
|
|
|
self.assertIn("No such folder", rv.data)
|
|
|
|
rv = self.client.get("/folder/del/" + str(folder.id), follow_redirects=True)
|
|
|
|
self.assertIn("Music folders", rv.data)
|
2017-12-19 22:16:55 +00:00
|
|
|
with db_session:
|
|
|
|
self.assertEqual(Folder.select().count(), 0)
|
2017-11-19 16:49:31 +00:00
|
|
|
|
|
|
|
def test_scan(self):
|
2017-12-19 22:16:55 +00:00
|
|
|
with db_session:
|
2019-06-29 15:25:44 +00:00
|
|
|
folder = Folder(name="folder", path="tests/assets/folder", root=True)
|
|
|
|
|
|
|
|
self._login("alice", "Alic3")
|
|
|
|
|
|
|
|
rv = self.client.get("/folder/scan/string", follow_redirects=True)
|
|
|
|
self.assertIn("badly formed", rv.data)
|
|
|
|
rv = self.client.get("/folder/scan/" + str(uuid.uuid4()), follow_redirects=True)
|
|
|
|
self.assertIn("No such folder", rv.data)
|
|
|
|
rv = self.client.get("/folder/scan/" + str(folder.id), follow_redirects=True)
|
|
|
|
self.assertIn("start", rv.data)
|
|
|
|
rv = self.client.get("/folder/scan", follow_redirects=True)
|
|
|
|
self.assertIn("start", rv.data)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-11-19 16:49:31 +00:00
|
|
|
unittest.main()
|