1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix independent tests

This commit is contained in:
Alban Féron 2022-12-31 17:17:49 +01:00
parent ee8165bb03
commit e51abfe80f
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
7 changed files with 55 additions and 84 deletions

View File

@ -1,7 +1,7 @@
# 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) 2018 Alban 'spl0k' Féron # Copyright (C) 2018-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -10,8 +10,6 @@ import shutil
import tempfile import tempfile
import unittest import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner from supysonic.scanner import Scanner
@ -21,8 +19,7 @@ class Issue101TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
init_database("sqlite:") init_database("sqlite:")
with db_session: FolderManager.add("folder", self.__dir)
FolderManager.add("folder", self.__dir)
def tearDown(self): def tearDown(self):
release_database() release_database()
@ -37,17 +34,15 @@ class Issue101TestCase(unittest.TestCase):
"tests/assets/folder/silence.mp3", os.path.join(subdir, "silence.mp3") "tests/assets/folder/silence.mp3", os.path.join(subdir, "silence.mp3")
) )
with db_session: scanner = Scanner()
scanner = Scanner() scanner.queue_folder("folder")
scanner.queue_folder("folder") scanner.run()
scanner.run()
shutil.rmtree(firstsubdir) shutil.rmtree(firstsubdir)
with db_session: scanner = Scanner()
scanner = Scanner() scanner.queue_folder("folder")
scanner.queue_folder("folder") scanner.run()
scanner.run()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,15 +1,13 @@
# 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) 2018 Alban 'spl0k' Féron # Copyright (C) 2018-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import os.path import os.path
import unittest import unittest
from pony.orm import db_session
from supysonic.db import User, Track, StarredTrack, RatingTrack from supysonic.db import User, Track, StarredTrack, RatingTrack
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner from supysonic.scanner import Scanner
@ -21,30 +19,27 @@ class Issue129TestCase(TestBase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
with db_session: FolderManager.add("folder", os.path.abspath("tests/assets/folder"))
FolderManager.add("folder", os.path.abspath("tests/assets/folder")) scanner = Scanner()
scanner = Scanner() scanner.queue_folder("folder")
scanner.queue_folder("folder") scanner.run()
scanner.run()
self.trackid = Track.select().first().id self.trackid = Track.select().first().id
self.userid = User.get(name="alice").id self.userid = User.get(name="alice").id
def test_last_play(self): def test_last_play(self):
with db_session: user = User[self.userid]
User[self.userid].last_play = Track[self.trackid] user.last_play = Track[self.trackid]
with db_session: user.save()
FolderManager.delete_by_name("folder") FolderManager.delete_by_name("folder")
def test_starred(self): def test_starred(self):
with db_session: StarredTrack.create(user=self.userid, starred=self.trackid)
StarredTrack(user=self.userid, starred=self.trackid) FolderManager.delete_by_name("folder")
FolderManager.delete_by_name("folder")
def test_rating(self): def test_rating(self):
with db_session: RatingTrack.create(user=self.userid, rated=self.trackid, rating=5)
RatingTrack(user=self.userid, rated=self.trackid, rating=5) FolderManager.delete_by_name("folder")
FolderManager.delete_by_name("folder")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,7 +1,7 @@
# 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) 2019 Alban 'spl0k' Féron # Copyright (C) 2019-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -9,8 +9,6 @@ import shutil
import tempfile import tempfile
import unittest import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.db import Track from supysonic.db import Track
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
@ -22,14 +20,12 @@ class Issue133TestCase(unittest.TestCase):
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
shutil.copy("tests/assets/issue133.flac", self.__dir) shutil.copy("tests/assets/issue133.flac", self.__dir)
init_database("sqlite:") init_database("sqlite:")
with db_session: FolderManager.add("folder", self.__dir)
FolderManager.add("folder", self.__dir)
def tearDown(self): def tearDown(self):
release_database() release_database()
shutil.rmtree(self.__dir) shutil.rmtree(self.__dir)
@db_session
def test_issue133(self): def test_issue133(self):
scanner = Scanner() scanner = Scanner()
scanner.queue_folder("folder") scanner.queue_folder("folder")

View File

@ -1,7 +1,7 @@
# 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) 2019 Alban 'spl0k' Féron # Copyright (C) 2019-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -9,8 +9,6 @@ import shutil
import tempfile import tempfile
import unittest import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner from supysonic.scanner import Scanner
@ -20,14 +18,12 @@ class Issue139TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
init_database("sqlite:") init_database("sqlite:")
with db_session: FolderManager.add("folder", self.__dir)
FolderManager.add("folder", self.__dir)
def tearDown(self): def tearDown(self):
release_database() release_database()
shutil.rmtree(self.__dir) shutil.rmtree(self.__dir)
@db_session
def do_scan(self): def do_scan(self):
scanner = Scanner() scanner = Scanner()
scanner.queue_folder("folder") scanner.queue_folder("folder")

View File

@ -1,7 +1,7 @@
# 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) 2019-2020 Alban 'spl0k' Féron # Copyright (C) 2019-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -11,8 +11,6 @@ import sys
import tempfile import tempfile
import unittest import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner from supysonic.scanner import Scanner
@ -23,8 +21,7 @@ class Issue148TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
init_database("sqlite:") init_database("sqlite:")
with db_session: FolderManager.add("folder", self.__dir)
FolderManager.add("folder", self.__dir)
def tearDown(self): def tearDown(self):
release_database() release_database()

View File

@ -1,48 +1,44 @@
# 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) 2021 Alban 'spl0k' Féron # Copyright (C) 2021-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import unittest import unittest
from pony.orm import db_session
from supysonic import db from supysonic import db
class Issue221TestCase(unittest.TestCase): class Issue221TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
db.init_database("sqlite:") db.init_database("sqlite:")
with db_session: root = db.Folder.create(root=True, name="Folder", path="tests")
root = db.Folder(root=True, name="Folder", path="tests") artist = db.Artist.create(name="Artist")
artist = db.Artist(name="Artist") album = db.Album.create(artist=artist, name="Album")
album = db.Album(artist=artist, name="Album")
for i in range(3): for i in range(3):
db.Track( db.Track.create(
title="Track {}".format(i), title="Track {}".format(i),
album=album, album=album,
artist=artist, artist=artist,
disc=1, disc=1,
number=i + 1, number=i + 1,
duration=3, duration=3,
has_art=False, has_art=False,
bitrate=64, bitrate=64,
path="tests/track{}".format(i), path="tests/track{}".format(i),
last_modification=2, last_modification=2,
root_folder=root, root_folder=root,
folder=root, folder=root,
genre="Genre", genre="Genre",
) )
db.User(name="user", password="secret", salt="sugar") db.User.create(name="user", password="secret", salt="sugar")
def tearDown(self): def tearDown(self):
db.release_database() db.release_database()
@db_session
def test_issue(self): def test_issue(self):
data = db.Album.get().as_subsonic_album(db.User.get()) data = db.Album.get().as_subsonic_album(db.User.get())
self.assertIn("genre", data) self.assertIn("genre", data)

View File

@ -1,7 +1,7 @@
# 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) 2020 Alban 'spl0k' Féron # Copyright (C) 2020-2022 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -12,8 +12,6 @@ import sys
import tempfile import tempfile
import unittest import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.managers.folder import FolderManager from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner from supysonic.scanner import Scanner
@ -26,8 +24,7 @@ class Issue85TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
init_database("sqlite:") init_database("sqlite:")
with db_session: FolderManager.add("folder", self.__dir)
FolderManager.add("folder", self.__dir)
def tearDown(self): def tearDown(self):
release_database() release_database()
@ -40,10 +37,9 @@ class Issue85TestCase(unittest.TestCase):
os.path.join(self.__dir.encode(), b"\xe6", b"silence.mp3"), os.path.join(self.__dir.encode(), b"\xe6", b"silence.mp3"),
) )
with db_session: scanner = Scanner()
scanner = Scanner() scanner.queue_folder("folder")
scanner.queue_folder("folder") scanner.run()
scanner.run()
if __name__ == "__main__": if __name__ == "__main__":