diff --git a/tests/api/__init__.py b/tests/api/__init__.py index 909a20d..057e9c1 100644 --- a/tests/api/__init__.py +++ b/tests/api/__init__.py @@ -21,6 +21,7 @@ from .test_browse import BrowseTestCase from .test_album_songs import AlbumSongsTestCase from .test_annotation import AnnotationTestCase from .test_media import MediaTestCase +from .test_transcoding import TranscodingTestCase def suite(): suite = unittest.TestSuite() @@ -36,6 +37,7 @@ def suite(): suite.addTest(unittest.makeSuite(AlbumSongsTestCase)) suite.addTest(unittest.makeSuite(AnnotationTestCase)) suite.addTest(unittest.makeSuite(MediaTestCase)) + suite.addTest(unittest.makeSuite(TranscodingTestCase)) return suite diff --git a/tests/api/test_media.py b/tests/api/test_media.py index e45ef96..c2070fa 100644 --- a/tests/api/test_media.py +++ b/tests/api/test_media.py @@ -65,8 +65,6 @@ class MediaTestCase(ApiTestBase): self.assertEqual(len(rv.data), 23) self.assertEqual(self.track.play_count, 1) - # TODO test transcoding - def test_download(self): self._make_request('download', error = 10) self._make_request('download', { 'id': 'string' }, error = 0) diff --git a/tests/api/test_transcoding.py b/tests/api/test_transcoding.py new file mode 100644 index 0000000..c745cd2 --- /dev/null +++ b/tests/api/test_transcoding.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# This file is part of Supysonic. +# Supysonic is a Python implementation of the Subsonic server API. +# +# Copyright (C) 2017 Alban 'spl0k' FĂ©ron +# +# Distributed under terms of the GNU AGPLv3 license. + +import unittest + +from supysonic.db import Folder, Track +from supysonic.managers.folder import FolderManager +from supysonic.scanner import Scanner + +from .apitestbase import ApiTestBase + +class TranscodingTestCase(ApiTestBase): + def setUp(self): + self.skipTest('Logging/atexit error') + + super(TranscodingTestCase, self).setUp() + + FolderManager.add(self.store, 'Folder', 'tests/assets/folder') + scanner = Scanner(self.store) + scanner.scan(self.store.find(Folder).one()) + scanner.finish() + + self.trackid = self.store.find(Track).one().id + + def _stream(self, **kwargs): + kwargs.update({ 'u': 'alice', 'p': 'Alic3', 'c': 'tests', 'v': '1.8.0', 'id': self.trackid }) + + rv = self.client.get('/rest/stream.view', query_string = kwargs) + self.assertEqual(rv.status_code, 200) + self.assertFalse(rv.mimetype.startswith('text/')) + + return rv + + def test_no_transcoding_available(self): + self._make_request('stream', { 'id': self.trackid, 'format': 'wat' }, error = 0) + + def test_direct_transcode(self): + rv = self._stream(maxBitRate = 96) + self.assertIn('tests/assets/folder/silence.mp3', rv.data) + self.assertTrue(rv.data.endswith('96')) + + def test_decode_encode(self): + rv = self._stream(format = 'cat') + self.assertEqual(rv.data, 'Pushing out some mp3 data...') + + rv = self._stream(format = 'md5') + self.assertTrue(rv.data.startswith('dbb16c0847e5d8c3b1867604828cb50b')) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/testbase.py b/tests/testbase.py index 13bd98b..bd4c2aa 100644 --- a/tests/testbase.py +++ b/tests/testbase.py @@ -30,6 +30,12 @@ class TestConfig(DefaultConfig): 'mp3': 'audio/mpeg', 'weirdextension': 'application/octet-stream' } + TRANSCODING = { + 'transcoder_mp3_mp3': 'echo -n %srcpath %outrate', + 'decoder_mp3': 'echo -n Pushing out some mp3 data...', + 'encoder_cat': 'cat -', + 'encoder_md5': 'md5sum' + } def __init__(self, with_webui, with_api): super(TestConfig, self).__init__()