1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Updated tests

This commit is contained in:
spl0k 2019-05-11 17:13:58 +02:00
parent 58b7888ba9
commit bb36b38d52
6 changed files with 32 additions and 43 deletions

View File

@ -26,8 +26,8 @@ class TranscodingTestCase(ApiTestBase):
with db_session: with db_session:
folder = FolderManager.add('Folder', 'tests/assets/folder') folder = FolderManager.add('Folder', 'tests/assets/folder')
scanner = Scanner() scanner = Scanner()
scanner.scan(folder) scanner.queue_folder('Folder')
scanner.finish() scanner.run()
self.trackid = Track.get().id self.trackid = Track.get().id

View File

@ -30,11 +30,9 @@ class ScannerTestCase(unittest.TestCase):
self.assertIsNotNone(folder) self.assertIsNotNone(folder)
self.folderid = folder.id self.folderid = folder.id
self.scanner = Scanner() self.__scan()
self.scanner.scan(folder)
def tearDown(self): def tearDown(self):
self.scanner.finish()
db.release_database() db.release_database()
@contextmanager @contextmanager
@ -45,30 +43,27 @@ class ScannerTestCase(unittest.TestCase):
tf.write(f.read()) tf.write(f.read())
yield tf yield tf
def __scan(self, force = False):
self.scanner = Scanner(force)
self.scanner.queue_folder('folder')
self.scanner.run()
@db_session @db_session
def test_scan(self): def test_scan(self):
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
self.assertRaises(TypeError, self.scanner.scan, None) self.assertRaises(TypeError, self.scanner.queue_folder, None)
self.assertRaises(TypeError, self.scanner.scan, 'string') self.assertRaises(TypeError, self.scanner.queue_folder, db.Folder[self.folderid])
@db_session
def test_progress(self):
def progress(processed):
self.assertIsInstance(processed, int)
self.scanner.scan(db.Folder[self.folderid], progress)
@db_session @db_session
def test_rescan(self): def test_rescan(self):
self.scanner.scan(db.Folder[self.folderid]) self.__scan()
commit() commit()
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
@db_session @db_session
def test_force_rescan(self): def test_force_rescan(self):
self.scanner = Scanner(True) self.__scan(True)
self.scanner.scan(db.Folder[self.folderid])
commit() commit()
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
@ -93,7 +88,7 @@ class ScannerTestCase(unittest.TestCase):
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
self.scanner.remove_file(track.path) self.scanner.remove_file(track.path)
self.scanner.finish() self.scanner.prune()
commit() commit()
self.assertEqual(db.Track.select().count(), 0) self.assertEqual(db.Track.select().count(), 0)
self.assertEqual(db.Album.select().count(), 0) self.assertEqual(db.Album.select().count(), 0)
@ -118,7 +113,7 @@ class ScannerTestCase(unittest.TestCase):
self.assertRaises(Exception, self.scanner.move_file, track.path, '/some/inexistent/path') self.assertRaises(Exception, self.scanner.move_file, track.path, '/some/inexistent/path')
with self.__temporary_track_copy() as tf: with self.__temporary_track_copy() as tf:
self.scanner.scan(db.Folder[self.folderid]) self.__scan()
commit() commit()
self.assertEqual(db.Track.select().count(), 2) self.assertEqual(db.Track.select().count(), 2)
self.scanner.move_file(tf.name, track.path) self.scanner.move_file(tf.name, track.path)
@ -135,10 +130,9 @@ class ScannerTestCase(unittest.TestCase):
@db_session @db_session
def test_rescan_corrupt_file(self): def test_rescan_corrupt_file(self):
track = db.Track.select().first() track = db.Track.select().first()
self.scanner = Scanner(True)
with self.__temporary_track_copy() as tf: with self.__temporary_track_copy() as tf:
self.scanner.scan(db.Folder[self.folderid]) self.__scan()
commit() commit()
self.assertEqual(db.Track.select().count(), 2) self.assertEqual(db.Track.select().count(), 2)
@ -146,7 +140,7 @@ class ScannerTestCase(unittest.TestCase):
tf.write(b'\x00' * 4096) tf.write(b'\x00' * 4096)
tf.truncate() tf.truncate()
self.scanner.scan(db.Folder[self.folderid]) self.__scan(True)
commit() commit()
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
@ -155,21 +149,20 @@ class ScannerTestCase(unittest.TestCase):
track = db.Track.select().first() track = db.Track.select().first()
with self.__temporary_track_copy() as tf: with self.__temporary_track_copy() as tf:
self.scanner.scan(db.Folder[self.folderid]) self.__scan()
commit() commit()
self.assertEqual(db.Track.select().count(), 2) self.assertEqual(db.Track.select().count(), 2)
self.scanner.scan(db.Folder[self.folderid]) self.__scan()
commit() commit()
self.assertEqual(db.Track.select().count(), 1) self.assertEqual(db.Track.select().count(), 1)
@db_session @db_session
def test_scan_tag_change(self): def test_scan_tag_change(self):
self.scanner = Scanner(True)
folder = db.Folder[self.folderid] folder = db.Folder[self.folderid]
with self.__temporary_track_copy() as tf: with self.__temporary_track_copy() as tf:
self.scanner.scan(folder) self.__scan()
commit() commit()
copy = db.Track.get(path = tf.name) copy = db.Track.get(path = tf.name)
self.assertEqual(copy.artist.name, 'Some artist') self.assertEqual(copy.artist.name, 'Some artist')
@ -180,8 +173,7 @@ class ScannerTestCase(unittest.TestCase):
tags['album'] = 'Crappy album' tags['album'] = 'Crappy album'
tags.save() tags.save()
self.scanner.scan(folder) self.__scan(True)
self.scanner.finish()
self.assertEqual(copy.artist.name, 'Renamed artist') self.assertEqual(copy.artist.name, 'Renamed artist')
self.assertEqual(copy.album.name, 'Crappy album') self.assertEqual(copy.album.name, 'Crappy album')
self.assertIsNotNone(db.Artist.get(name = 'Some artist')) self.assertIsNotNone(db.Artist.get(name = 'Some artist'))

View File

@ -37,18 +37,17 @@ class Issue101TestCase(unittest.TestCase):
subdir = tempfile.mkdtemp(dir = subdir) subdir = tempfile.mkdtemp(dir = subdir)
shutil.copyfile('tests/assets/folder/silence.mp3', os.path.join(subdir, 'silence.mp3')) shutil.copyfile('tests/assets/folder/silence.mp3', os.path.join(subdir, 'silence.mp3'))
scanner = Scanner()
with db_session: with db_session:
folder = Folder.select(lambda f: f.root).first() scanner = Scanner()
scanner.scan(folder) scanner.queue_folder('folder')
scanner.finish() scanner.run()
shutil.rmtree(firstsubdir) shutil.rmtree(firstsubdir)
with db_session: with db_session:
folder = Folder.select(lambda f: f.root).first() scanner = Scanner()
scanner.scan(folder) scanner.queue_folder('folder')
scanner.finish() scanner.run()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -25,8 +25,8 @@ class Issue129TestCase(TestBase):
with db_session: with db_session:
folder = FolderManager.add('folder', os.path.abspath('tests/assets/folder')) folder = FolderManager.add('folder', os.path.abspath('tests/assets/folder'))
scanner = Scanner() scanner = Scanner()
scanner.scan(folder) scanner.queue_folder('folder')
scanner.finish() 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

View File

@ -33,9 +33,8 @@ class Issue133TestCase(unittest.TestCase):
@db_session @db_session
def test_issue133(self): def test_issue133(self):
scanner = Scanner() scanner = Scanner()
folder = Folder.select(lambda f: f.root).first() scanner.queue_folder('folder')
scanner.scan(folder) scanner.run()
scanner.finish()
del scanner del scanner
track = Track.select().first() track = Track.select().first()

View File

@ -32,9 +32,8 @@ class Issue139TestCase(unittest.TestCase):
@db_session @db_session
def do_scan(self): def do_scan(self):
scanner = Scanner() scanner = Scanner()
folder = Folder.select(lambda f: f.root).first() scanner.queue_folder('folder')
scanner.scan(folder) scanner.run()
scanner.finish()
del scanner del scanner
def test_null_genre(self): def test_null_genre(self):