1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-14 14:12:17 +00:00
supysonic/tests/api/test_transcoding.py

64 lines
1.8 KiB
Python
Raw Normal View History

2017-12-07 22:33:32 +00:00
#!/usr/bin/env python
2018-03-04 20:49:56 +00:00
# coding: utf-8
2017-12-07 22:33:32 +00:00
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
2018-03-04 20:49:56 +00:00
# Copyright (C) 2017-2018 Alban 'spl0k' Féron
2017-12-07 22:33:32 +00:00
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
from pony.orm import db_session
from supysonic.db import Folder, Track
2017-12-07 22:33:32 +00:00
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner
from .apitestbase import ApiTestBase
2019-06-29 15:25:44 +00:00
2017-12-07 22:33:32 +00:00
class TranscodingTestCase(ApiTestBase):
def setUp(self):
super(TranscodingTestCase, self).setUp()
self._patch_client()
2017-12-07 22:33:32 +00:00
2017-12-23 21:59:04 +00:00
with db_session:
2019-06-29 15:25:44 +00:00
folder = FolderManager.add("Folder", "tests/assets/folder")
scanner = Scanner()
2019-06-29 15:25:44 +00:00
scanner.queue_folder("Folder")
2019-05-11 15:13:58 +00:00
scanner.run()
2017-12-07 22:33:32 +00:00
2017-12-23 21:59:04 +00:00
self.trackid = Track.get().id
2017-12-07 22:33:32 +00:00
def _stream(self, **kwargs):
2019-06-29 15:25:44 +00:00
kwargs.update(
{"u": "alice", "p": "Alic3", "c": "tests", "v": "1.9.0", "id": self.trackid}
)
2017-12-07 22:33:32 +00:00
2019-06-29 15:25:44 +00:00
rv = self.client.get("/rest/stream.view", query_string=kwargs)
2017-12-07 22:33:32 +00:00
self.assertEqual(rv.status_code, 200)
2019-06-29 15:25:44 +00:00
self.assertFalse(rv.mimetype.startswith("text/"))
2017-12-07 22:33:32 +00:00
return rv
def test_no_transcoding_available(self):
2019-06-29 15:25:44 +00:00
self._make_request("stream", {"id": self.trackid, "format": "wat"}, error=0)
2017-12-07 22:33:32 +00:00
def test_direct_transcode(self):
2019-06-29 15:25:44 +00:00
rv = self._stream(maxBitRate=96, estimateContentLength="true")
self.assertIn("tests/assets/folder/silence.mp3", rv.data)
self.assertTrue(rv.data.endswith("96"))
2017-12-07 22:33:32 +00:00
def test_decode_encode(self):
2019-06-29 15:25:44 +00:00
rv = self._stream(format="cat")
self.assertEqual(rv.data, "Pushing out some mp3 data...")
2017-12-07 22:33:32 +00:00
2019-06-29 15:25:44 +00:00
rv = self._stream(format="md5")
self.assertTrue(rv.data.startswith("dbb16c0847e5d8c3b1867604828cb50b"))
2017-12-07 22:33:32 +00:00
2019-06-29 15:25:44 +00:00
if __name__ == "__main__":
unittest.main()