async HTTP component (#3914)

* Migrate WSGI to asyncio

* Rename wsgi -> http

* Python 3.4 compat

* Move linting to Python 3.4

* lint

* Lint

* Fix Python 3.4 mock_open + binary data

* Surpress logging aiohttp.access

* Spelling

* Sending files is a coroutine

* More callback annotations and naming fixes

* Fix ios
This commit is contained in:
Paulus Schoutsen 2016-10-23 23:48:01 -07:00 committed by GitHub
parent 9aa88819a5
commit 519d9f2fd0
45 changed files with 1422 additions and 1009 deletions

View file

@ -18,42 +18,19 @@ HTTP_BASE_URL = 'http://127.0.0.1:{}'.format(SERVER_PORT)
API_PASSWORD = "test1234"
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
hass = None
entity_id = 'media_player.walkman'
def setUpModule(): # pylint: disable=invalid-name
"""Initalize a Home Assistant server."""
global hass
hass = get_test_home_assistant()
setup_component(hass, http.DOMAIN, {
http.DOMAIN: {
http.CONF_SERVER_PORT: SERVER_PORT,
http.CONF_API_PASSWORD: API_PASSWORD,
},
})
hass.start()
time.sleep(0.05)
def tearDownModule(): # pylint: disable=invalid-name
"""Stop the Home Assistant server."""
hass.stop()
class TestDemoMediaPlayer(unittest.TestCase):
"""Test the media_player module."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = hass
try:
self.hass.config.components.remove(mp.DOMAIN)
except ValueError:
pass
self.hass = get_test_home_assistant()
def tearDown(self):
"""Shut down test instance."""
self.hass.stop()
def test_source_select(self):
"""Test the input source service."""
@ -226,21 +203,6 @@ class TestDemoMediaPlayer(unittest.TestCase):
assert 0 == (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
@requests_mock.Mocker(real_http=True)
def test_media_image_proxy(self, m):
"""Test the media server image proxy server ."""
fake_picture_data = 'test.test'
m.get('https://graph.facebook.com/v2.5/107771475912710/'
'picture?type=large', text=fake_picture_data)
assert setup_component(
self.hass, mp.DOMAIN,
{'media_player': {'platform': 'demo'}})
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.text == fake_picture_data
@patch('homeassistant.components.media_player.demo.DemoYoutubePlayer.'
'media_seek')
def test_play_media(self, mock_seek):
@ -275,3 +237,42 @@ class TestDemoMediaPlayer(unittest.TestCase):
mp.media_seek(self.hass, 100, ent_id)
self.hass.block_till_done()
assert mock_seek.called
class TestMediaPlayerWeb(unittest.TestCase):
"""Test the media player web views sensor."""
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
setup_component(self.hass, http.DOMAIN, {
http.DOMAIN: {
http.CONF_SERVER_PORT: SERVER_PORT,
http.CONF_API_PASSWORD: API_PASSWORD,
},
})
self.hass.start()
time.sleep(0.05)
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
@requests_mock.Mocker(real_http=True)
def test_media_image_proxy(self, m):
"""Test the media server image proxy server ."""
fake_picture_data = 'test.test'
m.get('https://graph.facebook.com/v2.5/107771475912710/'
'picture?type=large', text=fake_picture_data)
self.hass.block_till_done()
assert setup_component(
self.hass, mp.DOMAIN,
{'media_player': {'platform': 'demo'}})
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