2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the Cast Media player platform."""
|
2016-10-30 21:18:53 +00:00
|
|
|
# pylint: disable=protected-access
|
2016-02-02 05:07:33 +00:00
|
|
|
import unittest
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant.components.media_player import cast
|
|
|
|
|
|
|
|
|
2016-10-13 15:51:43 +00:00
|
|
|
class FakeChromeCast(object):
|
2016-10-20 17:10:12 +00:00
|
|
|
"""A fake Chrome Cast."""
|
|
|
|
|
2016-10-13 15:51:43 +00:00
|
|
|
def __init__(self, host, port):
|
2016-10-20 17:10:12 +00:00
|
|
|
"""Initialize the fake Chrome Cast."""
|
2016-10-13 15:51:43 +00:00
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
|
|
|
|
|
2016-02-02 05:07:33 +00:00
|
|
|
class TestCastMediaPlayer(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the media_player module."""
|
2016-02-02 05:07:33 +00:00
|
|
|
|
|
|
|
@patch('homeassistant.components.media_player.cast.CastDevice')
|
2016-10-13 15:51:43 +00:00
|
|
|
@patch('pychromecast.get_chromecasts')
|
|
|
|
def test_filter_duplicates(self, mock_get_chromecasts, mock_device):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test filtering of duplicates."""
|
2016-10-13 15:51:43 +00:00
|
|
|
mock_get_chromecasts.return_value = [
|
|
|
|
FakeChromeCast('some_host', cast.DEFAULT_PORT)
|
|
|
|
]
|
|
|
|
|
|
|
|
# Test chromecasts as if they were hardcoded in configuration.yaml
|
2016-02-02 05:07:33 +00:00
|
|
|
cast.setup_platform(None, {
|
|
|
|
'host': 'some_host'
|
|
|
|
}, lambda _: _)
|
|
|
|
|
|
|
|
assert mock_device.called
|
|
|
|
|
|
|
|
mock_device.reset_mock()
|
|
|
|
assert not mock_device.called
|
|
|
|
|
2016-10-13 15:51:43 +00:00
|
|
|
# Test chromecasts as if they were automatically discovered
|
2017-04-12 03:10:02 +00:00
|
|
|
cast.setup_platform(None, {}, lambda _: _, {
|
|
|
|
'host': 'some_host',
|
|
|
|
'port': cast.DEFAULT_PORT,
|
|
|
|
})
|
2016-02-02 05:07:33 +00:00
|
|
|
assert not mock_device.called
|