From e51abfe80ff42741e2626899380b7491eb28da83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sat, 31 Dec 2022 17:17:49 +0100 Subject: [PATCH] Fix independent tests --- tests/issue101.py | 21 ++++++++------------- tests/issue129.py | 35 +++++++++++++++-------------------- tests/issue133.py | 8 ++------ tests/issue139.py | 8 ++------ tests/issue148.py | 7 ++----- tests/issue221.py | 46 +++++++++++++++++++++------------------------- tests/issue85.py | 14 +++++--------- 7 files changed, 55 insertions(+), 84 deletions(-) diff --git a/tests/issue101.py b/tests/issue101.py index 0801a98..6c41525 100644 --- a/tests/issue101.py +++ b/tests/issue101.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # 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. @@ -10,8 +10,6 @@ import shutil import tempfile import unittest -from pony.orm import db_session - from supysonic.db import init_database, release_database from supysonic.managers.folder import FolderManager from supysonic.scanner import Scanner @@ -21,8 +19,7 @@ class Issue101TestCase(unittest.TestCase): def setUp(self): self.__dir = tempfile.mkdtemp() init_database("sqlite:") - with db_session: - FolderManager.add("folder", self.__dir) + FolderManager.add("folder", self.__dir) def tearDown(self): release_database() @@ -37,17 +34,15 @@ class Issue101TestCase(unittest.TestCase): "tests/assets/folder/silence.mp3", os.path.join(subdir, "silence.mp3") ) - with db_session: - scanner = Scanner() - scanner.queue_folder("folder") - scanner.run() + scanner = Scanner() + scanner.queue_folder("folder") + scanner.run() shutil.rmtree(firstsubdir) - with db_session: - scanner = Scanner() - scanner.queue_folder("folder") - scanner.run() + scanner = Scanner() + scanner.queue_folder("folder") + scanner.run() if __name__ == "__main__": diff --git a/tests/issue129.py b/tests/issue129.py index dbc6ace..872c584 100644 --- a/tests/issue129.py +++ b/tests/issue129.py @@ -1,15 +1,13 @@ # This file is part of Supysonic. # 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. import os.path import unittest -from pony.orm import db_session - from supysonic.db import User, Track, StarredTrack, RatingTrack from supysonic.managers.folder import FolderManager from supysonic.scanner import Scanner @@ -21,30 +19,27 @@ class Issue129TestCase(TestBase): def setUp(self): super().setUp() - with db_session: - FolderManager.add("folder", os.path.abspath("tests/assets/folder")) - scanner = Scanner() - scanner.queue_folder("folder") - scanner.run() + FolderManager.add("folder", os.path.abspath("tests/assets/folder")) + scanner = Scanner() + scanner.queue_folder("folder") + scanner.run() - self.trackid = Track.select().first().id - self.userid = User.get(name="alice").id + self.trackid = Track.select().first().id + self.userid = User.get(name="alice").id def test_last_play(self): - with db_session: - User[self.userid].last_play = Track[self.trackid] - with db_session: - FolderManager.delete_by_name("folder") + user = User[self.userid] + user.last_play = Track[self.trackid] + user.save() + FolderManager.delete_by_name("folder") def test_starred(self): - with db_session: - StarredTrack(user=self.userid, starred=self.trackid) - FolderManager.delete_by_name("folder") + StarredTrack.create(user=self.userid, starred=self.trackid) + FolderManager.delete_by_name("folder") def test_rating(self): - with db_session: - RatingTrack(user=self.userid, rated=self.trackid, rating=5) - FolderManager.delete_by_name("folder") + RatingTrack.create(user=self.userid, rated=self.trackid, rating=5) + FolderManager.delete_by_name("folder") if __name__ == "__main__": diff --git a/tests/issue133.py b/tests/issue133.py index 3e7257b..f0d89f2 100644 --- a/tests/issue133.py +++ b/tests/issue133.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # 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. @@ -9,8 +9,6 @@ import shutil import tempfile import unittest -from pony.orm import db_session - from supysonic.db import init_database, release_database from supysonic.db import Track from supysonic.managers.folder import FolderManager @@ -22,14 +20,12 @@ class Issue133TestCase(unittest.TestCase): self.__dir = tempfile.mkdtemp() shutil.copy("tests/assets/issue133.flac", self.__dir) init_database("sqlite:") - with db_session: - FolderManager.add("folder", self.__dir) + FolderManager.add("folder", self.__dir) def tearDown(self): release_database() shutil.rmtree(self.__dir) - @db_session def test_issue133(self): scanner = Scanner() scanner.queue_folder("folder") diff --git a/tests/issue139.py b/tests/issue139.py index db135a0..26e644b 100644 --- a/tests/issue139.py +++ b/tests/issue139.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # 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. @@ -9,8 +9,6 @@ import shutil import tempfile import unittest -from pony.orm import db_session - from supysonic.db import init_database, release_database from supysonic.managers.folder import FolderManager from supysonic.scanner import Scanner @@ -20,14 +18,12 @@ class Issue139TestCase(unittest.TestCase): def setUp(self): self.__dir = tempfile.mkdtemp() init_database("sqlite:") - with db_session: - FolderManager.add("folder", self.__dir) + FolderManager.add("folder", self.__dir) def tearDown(self): release_database() shutil.rmtree(self.__dir) - @db_session def do_scan(self): scanner = Scanner() scanner.queue_folder("folder") diff --git a/tests/issue148.py b/tests/issue148.py index 595b5d8..6fddf1d 100644 --- a/tests/issue148.py +++ b/tests/issue148.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # 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. @@ -11,8 +11,6 @@ import sys import tempfile import unittest -from pony.orm import db_session - from supysonic.db import init_database, release_database from supysonic.managers.folder import FolderManager from supysonic.scanner import Scanner @@ -23,8 +21,7 @@ class Issue148TestCase(unittest.TestCase): def setUp(self): self.__dir = tempfile.mkdtemp() init_database("sqlite:") - with db_session: - FolderManager.add("folder", self.__dir) + FolderManager.add("folder", self.__dir) def tearDown(self): release_database() diff --git a/tests/issue221.py b/tests/issue221.py index 2825d19..a895e03 100644 --- a/tests/issue221.py +++ b/tests/issue221.py @@ -1,48 +1,44 @@ # This file is part of Supysonic. # 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. import unittest -from pony.orm import db_session - from supysonic import db class Issue221TestCase(unittest.TestCase): def setUp(self): db.init_database("sqlite:") - with db_session: - root = db.Folder(root=True, name="Folder", path="tests") - artist = db.Artist(name="Artist") - album = db.Album(artist=artist, name="Album") + root = db.Folder.create(root=True, name="Folder", path="tests") + artist = db.Artist.create(name="Artist") + album = db.Album.create(artist=artist, name="Album") - for i in range(3): - db.Track( - title="Track {}".format(i), - album=album, - artist=artist, - disc=1, - number=i + 1, - duration=3, - has_art=False, - bitrate=64, - path="tests/track{}".format(i), - last_modification=2, - root_folder=root, - folder=root, - genre="Genre", - ) + for i in range(3): + db.Track.create( + title="Track {}".format(i), + album=album, + artist=artist, + disc=1, + number=i + 1, + duration=3, + has_art=False, + bitrate=64, + path="tests/track{}".format(i), + last_modification=2, + root_folder=root, + folder=root, + genre="Genre", + ) - db.User(name="user", password="secret", salt="sugar") + db.User.create(name="user", password="secret", salt="sugar") def tearDown(self): db.release_database() - @db_session def test_issue(self): data = db.Album.get().as_subsonic_album(db.User.get()) self.assertIn("genre", data) diff --git a/tests/issue85.py b/tests/issue85.py index 84d630c..7f57550 100644 --- a/tests/issue85.py +++ b/tests/issue85.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # 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. @@ -12,8 +12,6 @@ import sys import tempfile import unittest -from pony.orm import db_session - from supysonic.db import init_database, release_database from supysonic.managers.folder import FolderManager from supysonic.scanner import Scanner @@ -26,8 +24,7 @@ class Issue85TestCase(unittest.TestCase): def setUp(self): self.__dir = tempfile.mkdtemp() init_database("sqlite:") - with db_session: - FolderManager.add("folder", self.__dir) + FolderManager.add("folder", self.__dir) def tearDown(self): release_database() @@ -40,10 +37,9 @@ class Issue85TestCase(unittest.TestCase): os.path.join(self.__dir.encode(), b"\xe6", b"silence.mp3"), ) - with db_session: - scanner = Scanner() - scanner.queue_folder("folder") - scanner.run() + scanner = Scanner() + scanner.queue_folder("folder") + scanner.run() if __name__ == "__main__":