File: test_scan.py

package info (click to toggle)
supysonic 0.7.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,716 kB
  • sloc: python: 9,315; sql: 1,029; sh: 25; makefile: 19; javascript: 6
file content (57 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2020 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.

from pony.orm import db_session
from time import sleep
from threading import Thread

from supysonic.daemon.server import Daemon
from supysonic.db import Folder

from .apitestbase import ApiTestBase


class ScanTestCase(ApiTestBase):
    def setUp(self):
        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:
            Folder(name="Root", root=True, path="tests/assets")

        self._daemon = Daemon(self.config)
        self._thread = Thread(target=self._daemon.run)
        self._thread.start()
        sleep(0.2)  # Wait a bit for the daemon thread to initialize

    def tearDown(self):
        self._daemon.terminate()
        self._thread.join()

        super().tearDown()

    def test_startScan(self):
        rv, child = self._make_request("startScan", tag="scanStatus", skip_post=True)
        self.assertEqual(child.get("scanning"), "true")
        self.assertGreaterEqual(int(child.get("count")), 0)

    def test_getScanStatus(self):
        rv, child = self._make_request("getScanStatus", tag="scanStatus")
        self.assertEqual(child.get("scanning"), "false")
        self.assertEqual(int(child.get("count")), 0)