mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Move HomeAssistantView to separate file. Convert http to async syntax. [skip ci] (#12982)
* Move HomeAssistantView to separate file. Convert http to async syntax. * pylint * websocket api * update emulated_hue for async/await * Lint
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
"""Test real IP middleware."""
|
||||
import asyncio
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.hdrs import X_FORWARDED_FOR
|
||||
|
||||
@@ -8,41 +6,38 @@ from homeassistant.components.http.real_ip import setup_real_ip
|
||||
from homeassistant.components.http.const import KEY_REAL_IP
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_handler(request):
|
||||
async def mock_handler(request):
|
||||
"""Handler that returns the real IP as text."""
|
||||
return web.Response(text=str(request[KEY_REAL_IP]))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_ignore_x_forwarded_for(test_client):
|
||||
async def test_ignore_x_forwarded_for(test_client):
|
||||
"""Test that we get the IP from the transport."""
|
||||
app = web.Application()
|
||||
app.router.add_get('/', mock_handler)
|
||||
setup_real_ip(app, False)
|
||||
|
||||
mock_api_client = yield from test_client(app)
|
||||
mock_api_client = await test_client(app)
|
||||
|
||||
resp = yield from mock_api_client.get('/', headers={
|
||||
resp = await mock_api_client.get('/', headers={
|
||||
X_FORWARDED_FOR: '255.255.255.255'
|
||||
})
|
||||
assert resp.status == 200
|
||||
text = yield from resp.text()
|
||||
text = await resp.text()
|
||||
assert text != '255.255.255.255'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_use_x_forwarded_for(test_client):
|
||||
async def test_use_x_forwarded_for(test_client):
|
||||
"""Test that we get the IP from the transport."""
|
||||
app = web.Application()
|
||||
app.router.add_get('/', mock_handler)
|
||||
setup_real_ip(app, True)
|
||||
|
||||
mock_api_client = yield from test_client(app)
|
||||
mock_api_client = await test_client(app)
|
||||
|
||||
resp = yield from mock_api_client.get('/', headers={
|
||||
resp = await mock_api_client.get('/', headers={
|
||||
X_FORWARDED_FOR: '255.255.255.255'
|
||||
})
|
||||
assert resp.status == 200
|
||||
text = yield from resp.text()
|
||||
text = await resp.text()
|
||||
assert text == '255.255.255.255'
|
||||
|
||||
Reference in New Issue
Block a user