Upgrade to aiohttp 3 (#12921)

* Upgrade aiohttp to 3.0.6

* Fix tests

* Fix aiohttp client stream test

* Lint

* Remove drain
This commit is contained in:
Paulus Schoutsen 2018-03-05 13:28:41 -08:00 committed by GitHub
parent e5c4bba906
commit 6a5c7ef43f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 65 deletions

View file

@ -3,6 +3,7 @@ import asyncio
import unittest
import aiohttp
import pytest
from homeassistant.core import EVENT_HOMEASSISTANT_CLOSE
from homeassistant.setup import async_setup_component
@ -12,6 +13,19 @@ from homeassistant.util.async import run_callback_threadsafe
from tests.common import get_test_home_assistant
@pytest.fixture
def camera_client(hass, test_client):
"""Fixture to fetch camera streams."""
assert hass.loop.run_until_complete(async_setup_component(hass, 'camera', {
'camera': {
'name': 'config_test',
'platform': 'mjpeg',
'mjpeg_url': 'http://example.com/mjpeg_stream',
}}))
yield hass.loop.run_until_complete(test_client(hass.http.app))
class TestHelpersAiohttpClient(unittest.TestCase):
"""Test homeassistant.helpers.aiohttp_client module."""
@ -119,41 +133,38 @@ class TestHelpersAiohttpClient(unittest.TestCase):
@asyncio.coroutine
def test_async_aiohttp_proxy_stream(aioclient_mock, hass, test_client):
def test_async_aiohttp_proxy_stream(aioclient_mock, camera_client):
"""Test that it fetches the given url."""
aioclient_mock.get('http://example.com/mjpeg_stream', content=[
b'Frame1', b'Frame2', b'Frame3'
])
result = yield from async_setup_component(hass, 'camera', {
'camera': {
'name': 'config_test',
'platform': 'mjpeg',
'mjpeg_url': 'http://example.com/mjpeg_stream',
}})
assert result, 'Failed to setup camera'
client = yield from test_client(hass.http.app)
resp = yield from client.get('/api/camera_proxy_stream/camera.config_test')
resp = yield from camera_client.get(
'/api/camera_proxy_stream/camera.config_test')
assert resp.status == 200
assert aioclient_mock.call_count == 1
body = yield from resp.text()
assert body == 'Frame3Frame2Frame1'
aioclient_mock.clear_requests()
aioclient_mock.get(
'http://example.com/mjpeg_stream', exc=asyncio.TimeoutError(),
content=[b'Frame1', b'Frame2', b'Frame3'])
resp = yield from client.get('/api/camera_proxy_stream/camera.config_test')
@asyncio.coroutine
def test_async_aiohttp_proxy_stream_timeout(aioclient_mock, camera_client):
"""Test that it fetches the given url."""
aioclient_mock.get(
'http://example.com/mjpeg_stream', exc=asyncio.TimeoutError())
resp = yield from camera_client.get(
'/api/camera_proxy_stream/camera.config_test')
assert resp.status == 504
aioclient_mock.clear_requests()
aioclient_mock.get(
'http://example.com/mjpeg_stream', exc=aiohttp.ClientError(),
content=[b'Frame1', b'Frame2', b'Frame3'])
resp = yield from client.get('/api/camera_proxy_stream/camera.config_test')
@asyncio.coroutine
def test_async_aiohttp_proxy_stream_client_err(aioclient_mock, camera_client):
"""Test that it fetches the given url."""
aioclient_mock.get(
'http://example.com/mjpeg_stream', exc=aiohttp.ClientError())
resp = yield from camera_client.get(
'/api/camera_proxy_stream/camera.config_test')
assert resp.status == 502