diff --git a/tests/api/test_scan.py b/tests/api/test_scan.py new file mode 100644 index 0000000..9e33071 --- /dev/null +++ b/tests/api/test_scan.py @@ -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() diff --git a/tests/testbase.py b/tests/testbase.py index 3b78d9d..e22eb4d 100644 --- a/tests/testbase.py +++ b/tests/testbase.py @@ -83,14 +83,14 @@ class TestBase(unittest.TestCase): def setUp(self): self.__db = tempfile.mkstemp() self.__dir = tempfile.mkdtemp() - config = TestConfig(self.__with_webui__, self.__with_api__) - config.BASE["database_uri"] = "sqlite:///" + self.__db[1] - config.WEBAPP["cache_dir"] = self.__dir + self.config = TestConfig(self.__with_webui__, self.__with_api__) + self.config.BASE["database_uri"] = "sqlite:///" + self.__db[1] + self.config.WEBAPP["cache_dir"] = self.__dir - init_database(config.BASE["database_uri"]) + init_database(self.config.BASE["database_uri"]) release_database() - self.__app = create_application(config) + self.__app = create_application(self.config) self.client = self.__app.test_client() with db_session: