1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

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

@@ -1,11 +1,13 @@
"""The tests for the Home Assistant API component."""
# pylint: disable=protected-access,too-many-public-methods
import asyncio
from contextlib import closing
import json
import time
import unittest
from unittest.mock import Mock, patch
from aiohttp import web
import requests
from homeassistant import bootstrap, const
@@ -243,20 +245,18 @@ class TestAPI(unittest.TestCase):
def test_api_get_error_log(self):
"""Test the return of the error log."""
test_string = 'Test String°'.encode('UTF-8')
test_string = 'Test String°'
# Can't use read_data with wsgiserver in Python 3.4.2. Due to a
# bug in read_data, it can't handle byte types ('Type str doesn't
# support the buffer API'), but wsgiserver requires byte types
# ('WSGI Applications must yield bytes'). So just mock our own
# read method.
m_open = Mock(return_value=Mock(
read=Mock(side_effect=[test_string]))
)
with patch('homeassistant.components.http.open', m_open, create=True):
@asyncio.coroutine
def mock_send():
"""Mock file send."""
return web.Response(text=test_string)
with patch('homeassistant.components.http.HomeAssistantView.file',
Mock(return_value=mock_send())):
req = requests.get(_url(const.URL_API_ERROR_LOG),
headers=HA_HEADERS)
self.assertEqual(test_string, req.text.encode('UTF-8'))
self.assertEqual(test_string, req.text)
self.assertIsNone(req.headers.get('expires'))
def test_api_get_event_listeners(self):