Remove launching a server in a test (#21445)

This commit is contained in:
Paulus Schoutsen 2019-02-26 13:06:27 -08:00 committed by GitHub
parent e119deafe5
commit 344e839bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,22 +6,13 @@ import asyncio
import pytest import pytest
import voluptuous as vol import voluptuous as vol
from homeassistant.setup import setup_component from homeassistant.setup import setup_component, async_setup_component
from homeassistant.const import HTTP_HEADER_HA_AUTH
import homeassistant.components.media_player as mp import homeassistant.components.media_player as mp
import homeassistant.components.http as http
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION
import requests from tests.common import get_test_home_assistant
from tests.common import get_test_home_assistant, get_test_instance_port
from tests.components.media_player import common from tests.components.media_player import common
SERVER_PORT = get_test_instance_port()
HTTP_BASE_URL = 'http://127.0.0.1:{}'.format(SERVER_PORT)
API_PASSWORD = "test1234"
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
entity_id = 'media_player.walkman' entity_id = 'media_player.walkman'
@ -231,61 +222,41 @@ class TestDemoMediaPlayer(unittest.TestCase):
assert mock_seek.called assert mock_seek.called
class TestMediaPlayerWeb(unittest.TestCase): async def test_media_image_proxy(hass, hass_client):
"""Test the media player web views sensor.""" """Test the media server image proxy server ."""
assert await async_setup_component(
hass, mp.DOMAIN,
{'media_player': {'platform': 'demo'}})
def setUp(self): fake_picture_data = 'test.test'
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
assert setup_component(self.hass, http.DOMAIN, { class MockResponse():
http.DOMAIN: { def __init__(self):
http.CONF_SERVER_PORT: SERVER_PORT, self.status = 200
http.CONF_API_PASSWORD: API_PASSWORD, self.headers = {'Content-Type': 'sometype'}
},
})
assert setup_component( @asyncio.coroutine
self.hass, mp.DOMAIN, def read(self):
{'media_player': {'platform': 'demo'}}) return fake_picture_data.encode('ascii')
self.hass.start() @asyncio.coroutine
def release(self):
pass
def tearDown(self): class MockWebsession():
"""Stop everything that was started."""
self.hass.stop()
def test_media_image_proxy(self): @asyncio.coroutine
"""Test the media server image proxy server .""" def get(self, url):
fake_picture_data = 'test.test' return MockResponse()
class MockResponse(): def detach(self):
def __init__(self): pass
self.status = 200
self.headers = {'Content-Type': 'sometype'}
@asyncio.coroutine hass.data[DATA_CLIENTSESSION] = MockWebsession()
def read(self):
return fake_picture_data.encode('ascii')
@asyncio.coroutine assert hass.states.is_state(entity_id, 'playing')
def release(self): state = hass.states.get(entity_id)
pass client = await hass_client()
req = await client.get(state.attributes.get('entity_picture'))
class MockWebsession(): assert req.status == 200
assert await req.text() == fake_picture_data
@asyncio.coroutine
def get(self, url):
return MockResponse()
def detach(self):
pass
self.hass.data[DATA_CLIENTSESSION] = MockWebsession()
assert self.hass.states.is_state(entity_id, 'playing')
state = self.hass.states.get(entity_id)
req = requests.get(HTTP_BASE_URL +
state.attributes.get('entity_picture'))
assert req.status_code == 200
assert req.text == fake_picture_data