1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-13 21:52:18 +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.
#
2020-11-28 14:15:24 +00:00
# Copyright (C) 2020 Alban 'spl0k' Féron
2020-11-24 12:44:36 +00:00
#
# Distributed under terms of the GNU AGPLv3 license.
from pony.orm import db_session
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
with db_session:
Folder(name="Root", root=True, path="tests/assets")
2020-11-28 14:15:24 +00:00
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()
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)