mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Improving scan tests
This commit is contained in:
parent
6bb3cd71cf
commit
36cea89b26
@ -1,19 +1,30 @@
|
|||||||
from . import api
|
# This file is part of Supysonic.
|
||||||
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2020 Alban 'spl0k' Féron
|
||||||
|
# 2020 Vincent Ducamps
|
||||||
|
#
|
||||||
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
|
from ..daemon.client import DaemonClient
|
||||||
|
from ..daemon.exceptions import DaemonUnavailableError
|
||||||
|
|
||||||
|
from . import api
|
||||||
from .user import admin_only
|
from .user import admin_only
|
||||||
from .exceptions import ServerError
|
from .exceptions import ServerError
|
||||||
from ..daemon.client import DaemonClient
|
|
||||||
|
|
||||||
|
|
||||||
@api.route("/startScan.view", methods=["GET", "POST"])
|
@api.route("/startScan.view", methods=["GET", "POST"])
|
||||||
@admin_only
|
@admin_only
|
||||||
def startScan():
|
def startScan():
|
||||||
try:
|
try:
|
||||||
daeomonclient = DaemonClient(current_app.config["DAEMON"]["socket"])
|
daemonclient = DaemonClient(current_app.config["DAEMON"]["socket"])
|
||||||
daeomonclient.scan()
|
daemonclient.scan()
|
||||||
scanned = daeomonclient.get_scanning_progress()
|
scanned = daemonclient.get_scanning_progress()
|
||||||
except Exception as e:
|
except DaemonUnavailableError as e:
|
||||||
raise ServerError(str(e))
|
raise ServerError(str(e))
|
||||||
return request.formatter(
|
return request.formatter(
|
||||||
"scanStatus",
|
"scanStatus",
|
||||||
@ -31,7 +42,7 @@ def getScanStatus():
|
|||||||
scanned = DaemonClient(
|
scanned = DaemonClient(
|
||||||
current_app.config["DAEMON"]["socket"]
|
current_app.config["DAEMON"]["socket"]
|
||||||
).get_scanning_progress()
|
).get_scanning_progress()
|
||||||
except Exception as e:
|
except DaemonUnavailableError as e:
|
||||||
raise ServerError(str(e))
|
raise ServerError(str(e))
|
||||||
return request.formatter(
|
return request.formatter(
|
||||||
"scanStatus",
|
"scanStatus",
|
||||||
|
@ -1,53 +1,55 @@
|
|||||||
# This file is part of Supysonic.
|
# This file is part of Supysonic.
|
||||||
# Supysonic is a Python implementation of the Subsonic server API.
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2017-2020 Alban 'spl0k' Féron
|
# Copyright (C) 2020 Alban 'spl0k' Féron
|
||||||
#
|
#
|
||||||
# Distributed under terms of the GNU AGPLv3 license.
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
from pony.orm import db_session
|
from pony.orm import db_session
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
from supysonic.daemon.server import Daemon
|
||||||
from supysonic.db import Folder
|
from supysonic.db import Folder
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
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):
|
class ScanTestCase(ApiTestBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ScanTestCase, self).setUp(apiVersion="1.16.0")
|
super().setUp(apiVersion="1.16.0")
|
||||||
|
|
||||||
|
def test_unauthorized(self):
|
||||||
|
self._make_request("startScan", args={"u": "bob", "p": "B0b"}, error=50)
|
||||||
|
self._make_request("getScanStatus", args={"u": "bob", "p": "B0b"}, error=50)
|
||||||
|
|
||||||
|
def test_unavailable(self):
|
||||||
|
self._make_request("startScan", error=0)
|
||||||
|
self._make_request("getScanStatus", error=0)
|
||||||
|
|
||||||
|
|
||||||
|
class ScanWithDaemonTestCase(ApiTestBase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp(apiVersion="1.16.0")
|
||||||
|
|
||||||
with db_session:
|
with db_session:
|
||||||
Folder(name="Root", root=True, path="tests/assets")
|
Folder(name="Root", root=True, path="tests/assets")
|
||||||
|
|
||||||
|
self._daemon = Daemon(self.config)
|
||||||
|
self._thread = Thread(target=self._daemon.run)
|
||||||
|
self._thread.start()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self._daemon.terminate()
|
||||||
|
self._thread.join()
|
||||||
|
|
||||||
|
super().tearDown()
|
||||||
|
|
||||||
def test_startScan(self):
|
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")
|
rv, child = self._make_request("startScan", tag="scanStatus")
|
||||||
self.assertTrue(child.get("scanning"))
|
self.assertEqual(child.get("scanning"), "true")
|
||||||
self.assertGreaterEqual(int(child.get("count")), 0)
|
self.assertGreaterEqual(int(child.get("count")), 0)
|
||||||
daemon.terminate()
|
|
||||||
|
|
||||||
def test_getScanStatus(self):
|
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")
|
rv, child = self._make_request("getScanStatus", tag="scanStatus")
|
||||||
self.assertIn(child.get("scanning"), ["true", "false"])
|
self.assertEqual(child.get("scanning"), "false")
|
||||||
self.assertGreaterEqual(int(child.get("count")), 0)
|
self.assertEqual(int(child.get("count")), 0)
|
||||||
daemon.terminate()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user