Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -16,12 +16,19 @@ from tests.common import get_test_home_assistant
|
|||
@pytest.fixture
|
||||
def camera_client(hass, hass_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',
|
||||
}}))
|
||||
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(hass_client())
|
||||
|
||||
|
@ -39,73 +46,64 @@ class TestHelpersAiohttpClient(unittest.TestCase):
|
|||
|
||||
def test_get_clientsession_with_ssl(self):
|
||||
"""Test init clientsession with ssl."""
|
||||
run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
|
||||
self.hass).result()
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, client.async_get_clientsession, self.hass
|
||||
).result()
|
||||
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CLIENTSESSION], aiohttp.ClientSession)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
self.hass.data[client.DATA_CLIENTSESSION], aiohttp.ClientSession
|
||||
)
|
||||
assert isinstance(self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
|
||||
def test_get_clientsession_without_ssl(self):
|
||||
"""Test init clientsession without ssl."""
|
||||
run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
|
||||
self.hass, False).result()
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, client.async_get_clientsession, self.hass, False
|
||||
).result()
|
||||
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY],
|
||||
aiohttp.ClientSession)
|
||||
self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY], aiohttp.ClientSession
|
||||
)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY],
|
||||
aiohttp.TCPConnector)
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY], aiohttp.TCPConnector
|
||||
)
|
||||
|
||||
def test_create_clientsession_with_ssl_and_cookies(self):
|
||||
"""Test create clientsession with ssl."""
|
||||
|
||||
def _async_helper():
|
||||
return client.async_create_clientsession(
|
||||
self.hass,
|
||||
cookies={'bla': True}
|
||||
)
|
||||
return client.async_create_clientsession(self.hass, cookies={"bla": True})
|
||||
|
||||
session = run_callback_threadsafe(
|
||||
self.hass.loop,
|
||||
_async_helper,
|
||||
).result()
|
||||
session = run_callback_threadsafe(self.hass.loop, _async_helper).result()
|
||||
|
||||
assert isinstance(
|
||||
session, aiohttp.ClientSession)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
assert isinstance(session, aiohttp.ClientSession)
|
||||
assert isinstance(self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
|
||||
def test_create_clientsession_without_ssl_and_cookies(self):
|
||||
"""Test create clientsession without ssl."""
|
||||
|
||||
def _async_helper():
|
||||
return client.async_create_clientsession(
|
||||
self.hass,
|
||||
False,
|
||||
cookies={'bla': True}
|
||||
self.hass, False, cookies={"bla": True}
|
||||
)
|
||||
|
||||
session = run_callback_threadsafe(
|
||||
self.hass.loop,
|
||||
_async_helper,
|
||||
).result()
|
||||
session = run_callback_threadsafe(self.hass.loop, _async_helper).result()
|
||||
|
||||
assert isinstance(session, aiohttp.ClientSession)
|
||||
assert isinstance(
|
||||
session, aiohttp.ClientSession)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY],
|
||||
aiohttp.TCPConnector)
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY], aiohttp.TCPConnector
|
||||
)
|
||||
|
||||
def test_get_clientsession_cleanup(self):
|
||||
"""Test init clientsession with ssl."""
|
||||
run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
|
||||
self.hass).result()
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, client.async_get_clientsession, self.hass
|
||||
).result()
|
||||
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CLIENTSESSION], aiohttp.ClientSession)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
self.hass.data[client.DATA_CLIENTSESSION], aiohttp.ClientSession
|
||||
)
|
||||
assert isinstance(self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)
|
||||
|
||||
self.hass.bus.fire(EVENT_HOMEASSISTANT_CLOSE)
|
||||
self.hass.block_till_done()
|
||||
|
@ -115,15 +113,16 @@ class TestHelpersAiohttpClient(unittest.TestCase):
|
|||
|
||||
def test_get_clientsession_cleanup_without_ssl(self):
|
||||
"""Test init clientsession with ssl."""
|
||||
run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
|
||||
self.hass, False).result()
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, client.async_get_clientsession, self.hass, False
|
||||
).result()
|
||||
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY],
|
||||
aiohttp.ClientSession)
|
||||
self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY], aiohttp.ClientSession
|
||||
)
|
||||
assert isinstance(
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY],
|
||||
aiohttp.TCPConnector)
|
||||
self.hass.data[client.DATA_CONNECTOR_NOTVERIFY], aiohttp.TCPConnector
|
||||
)
|
||||
|
||||
self.hass.bus.fire(EVENT_HOMEASSISTANT_CLOSE)
|
||||
self.hass.block_till_done()
|
||||
|
@ -135,35 +134,29 @@ class TestHelpersAiohttpClient(unittest.TestCase):
|
|||
@asyncio.coroutine
|
||||
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'Frame1Frame2Frame3')
|
||||
aioclient_mock.get("http://example.com/mjpeg_stream", content=b"Frame1Frame2Frame3")
|
||||
|
||||
resp = yield from camera_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 == 'Frame1Frame2Frame3'
|
||||
assert body == "Frame1Frame2Frame3"
|
||||
|
||||
|
||||
@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())
|
||||
aioclient_mock.get("http://example.com/mjpeg_stream", exc=asyncio.TimeoutError())
|
||||
|
||||
resp = yield from camera_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 == 504
|
||||
|
||||
|
||||
@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())
|
||||
aioclient_mock.get("http://example.com/mjpeg_stream", exc=aiohttp.ClientError())
|
||||
|
||||
resp = yield from camera_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 == 502
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue