1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-15 06:32:16 +00:00
supysonic/tests/api/test_scan.py

56 lines
1.7 KiB
Python
Raw Normal View History

2020-11-24 12:44:36 +00:00
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
2022-12-30 14:21:30 +00:00
# Copyright (C) 2020-2022 Alban 'spl0k' Féron
2020-11-24 12:44:36 +00:00
#
# Distributed under terms of the GNU AGPLv3 license.
2021-12-04 16:43:08 +00:00
from time import sleep
2020-11-28 14:15:24 +00:00
from threading import Thread
2020-11-24 12:44:36 +00:00
2020-11-28 14:15:24 +00:00
from supysonic.daemon.server import Daemon
2020-11-24 12:44:36 +00:00
from supysonic.db import Folder
from .apitestbase import ApiTestBase
2020-11-28 14:15:24 +00:00
class ScanTestCase(ApiTestBase):
def setUp(self):
super().setUp(apiVersion="1.16.0")
2020-11-24 12:44:36 +00:00
2020-11-28 14:15:24 +00:00
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)
2020-11-24 12:44:36 +00:00
2020-11-28 14:15:24 +00:00
def test_unavailable(self):
self._make_request("startScan", error=0)
self._make_request("getScanStatus", error=0)
2020-11-24 12:44:36 +00:00
2020-11-28 14:15:24 +00:00
class ScanWithDaemonTestCase(ApiTestBase):
2020-11-24 12:44:36 +00:00
def setUp(self):
2020-11-28 14:15:24 +00:00
super().setUp(apiVersion="1.16.0")
2020-11-24 12:44:36 +00:00
2022-12-30 14:21:30 +00:00
Folder.create(name="Root", root=True, path="tests/assets")
2020-11-24 12:44:36 +00:00
2020-11-28 14:15:24 +00:00
self._daemon = Daemon(self.config)
self._thread = Thread(target=self._daemon.run)
self._thread.start()
2021-12-04 16:43:08 +00:00
sleep(0.2) # Wait a bit for the daemon thread to initialize
2020-11-28 14:15:24 +00:00
def tearDown(self):
self._daemon.terminate()
self._thread.join()
super().tearDown()
2020-11-24 12:44:36 +00:00
def test_startScan(self):
2021-11-21 11:20:48 +00:00
rv, child = self._make_request("startScan", tag="scanStatus", skip_post=True)
2020-11-28 14:15:24 +00:00
self.assertEqual(child.get("scanning"), "true")
2020-11-24 12:44:36 +00:00
self.assertGreaterEqual(int(child.get("count")), 0)
def test_getScanStatus(self):
rv, child = self._make_request("getScanStatus", tag="scanStatus")
2020-11-28 14:15:24 +00:00
self.assertEqual(child.get("scanning"), "false")
self.assertEqual(int(child.get("count")), 0)