mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
add test for api scan endpoint
This commit is contained in:
parent
13b7c4b3de
commit
d08db741bc
53
tests/api/test_scan.py
Normal file
53
tests/api/test_scan.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# This file is part of Supysonic.
|
||||||
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017-2020 Alban 'spl0k' Féron
|
||||||
|
#
|
||||||
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
|
from pony.orm import db_session
|
||||||
|
|
||||||
|
from supysonic.db import Folder
|
||||||
|
|
||||||
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
from supysonic.daemon.server import Daemon
|
||||||
|
from threading import Thread
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class DaemonThread(Thread):
|
||||||
|
def __init__(self, daemon):
|
||||||
|
super(DaemonThread, self).__init__(target=daemon.run)
|
||||||
|
self.daemon = True
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
|
||||||
|
class ScanTestCase(ApiTestBase):
|
||||||
|
def setUp(self):
|
||||||
|
super(ScanTestCase, self).setUp(apiVersion="1.16.0")
|
||||||
|
|
||||||
|
with db_session:
|
||||||
|
Folder(name="Root", root=True, path="tests/assets")
|
||||||
|
|
||||||
|
def test_startScan(self):
|
||||||
|
self._make_request("startScan", error=0)
|
||||||
|
daemon = Daemon(self.config)
|
||||||
|
with db_session:
|
||||||
|
daemonThread = DaemonThread(daemon)
|
||||||
|
rv, child = self._make_request("startScan", tag="scanStatus")
|
||||||
|
self.assertTrue(child.get("scanning"))
|
||||||
|
self.assertGreaterEqual(int(child.get("count")), 0)
|
||||||
|
daemon.terminate()
|
||||||
|
|
||||||
|
def test_getScanStatus(self):
|
||||||
|
self._make_request("getScanStatus", error=0)
|
||||||
|
daemon = Daemon(self.config)
|
||||||
|
with db_session:
|
||||||
|
daemonThread = DaemonThread(daemon)
|
||||||
|
rv, child = self._make_request("getScanStatus", tag="scanStatus")
|
||||||
|
self.assertIn(child.get("scanning"), ["true", "false"])
|
||||||
|
self.assertGreaterEqual(int(child.get("count")), 0)
|
||||||
|
daemon.terminate()
|
@ -83,14 +83,14 @@ class TestBase(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.__db = tempfile.mkstemp()
|
self.__db = tempfile.mkstemp()
|
||||||
self.__dir = tempfile.mkdtemp()
|
self.__dir = tempfile.mkdtemp()
|
||||||
config = TestConfig(self.__with_webui__, self.__with_api__)
|
self.config = TestConfig(self.__with_webui__, self.__with_api__)
|
||||||
config.BASE["database_uri"] = "sqlite:///" + self.__db[1]
|
self.config.BASE["database_uri"] = "sqlite:///" + self.__db[1]
|
||||||
config.WEBAPP["cache_dir"] = self.__dir
|
self.config.WEBAPP["cache_dir"] = self.__dir
|
||||||
|
|
||||||
init_database(config.BASE["database_uri"])
|
init_database(self.config.BASE["database_uri"])
|
||||||
release_database()
|
release_database()
|
||||||
|
|
||||||
self.__app = create_application(config)
|
self.__app = create_application(self.config)
|
||||||
self.client = self.__app.test_client()
|
self.client = self.__app.test_client()
|
||||||
|
|
||||||
with db_session:
|
with db_session:
|
||||||
|
Loading…
Reference in New Issue
Block a user