stream: Update playback tests to include backend
This commit is contained in:
parent
a0c0ab4cde
commit
9296ddd75b
@ -4,6 +4,8 @@ import mock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import requests.exceptions
|
||||||
|
|
||||||
import responses
|
import responses
|
||||||
|
|
||||||
from mopidy import exceptions
|
from mopidy import exceptions
|
||||||
@ -27,6 +29,11 @@ def config():
|
|||||||
'proxy': {},
|
'proxy': {},
|
||||||
'stream': {
|
'stream': {
|
||||||
'timeout': TIMEOUT,
|
'timeout': TIMEOUT,
|
||||||
|
'metadata_blacklist': [],
|
||||||
|
'protocols': ['file'],
|
||||||
|
},
|
||||||
|
'file': {
|
||||||
|
'enabled': False
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,24 +43,21 @@ def audio():
|
|||||||
return mock.Mock()
|
return mock.Mock()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.yield_fixture
|
||||||
def scanner():
|
def scanner():
|
||||||
scan_mock = mock.Mock(spec=scan.Scanner)
|
patcher = mock.patch.object(scan, 'Scanner')
|
||||||
scan_mock.scan.return_value = None
|
yield patcher.start()()
|
||||||
return scan_mock
|
patcher.stop()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def backend(scanner):
|
def backend(audio, config, scanner):
|
||||||
backend = mock.Mock()
|
return actor.StreamBackend(audio=audio, config=config)
|
||||||
backend.uri_schemes = ['file']
|
|
||||||
backend._scanner = scanner
|
|
||||||
return backend
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def provider(audio, backend, config):
|
def provider(backend):
|
||||||
return actor.StreamPlaybackProvider(audio, backend, config)
|
return backend.playback
|
||||||
|
|
||||||
|
|
||||||
class TestTranslateURI(object):
|
class TestTranslateURI(object):
|
||||||
@ -184,14 +188,24 @@ class TestTranslateURI(object):
|
|||||||
% STREAM_URI in caplog.text())
|
% STREAM_URI in caplog.text())
|
||||||
assert result == STREAM_URI
|
assert result == STREAM_URI
|
||||||
|
|
||||||
def test_failed_download_returns_none(self, provider, caplog):
|
@responses.activate
|
||||||
with mock.patch.object(actor, 'http') as http_mock:
|
def test_failed_download_returns_none(self, scanner, provider, caplog):
|
||||||
http_mock.download.return_value = None
|
scanner.scan.side_effect = [
|
||||||
|
mock.Mock(mime='text/foo', playable=False)
|
||||||
|
]
|
||||||
|
|
||||||
result = provider.translate_uri(PLAYLIST_URI)
|
responses.add(
|
||||||
|
responses.GET, PLAYLIST_URI,
|
||||||
|
body=requests.exceptions.HTTPError('Kaboom'))
|
||||||
|
|
||||||
|
result = provider.translate_uri(PLAYLIST_URI)
|
||||||
|
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
|
assert (
|
||||||
|
'Unwrapping stream from URI (%s) failed: '
|
||||||
|
'error downloading URI' % PLAYLIST_URI) in caplog.text()
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_playlist_references_itself(self, scanner, provider, caplog):
|
def test_playlist_references_itself(self, scanner, provider, caplog):
|
||||||
scanner.scan.side_effect = [
|
scanner.scan.side_effect = [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user