mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
Migrate owntracks tests from coroutine to async/await (#30369)
This commit is contained in:
parent
1a2a976be2
commit
47aa0043bf
@ -1,6 +1,4 @@
|
|||||||
"""Test the owntracks_http platform."""
|
"""Test the owntracks_http platform."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import owntracks
|
from homeassistant.components import owntracks
|
||||||
@ -55,10 +53,9 @@ def mock_client(hass, aiohttp_client):
|
|||||||
return hass.loop.run_until_complete(aiohttp_client(hass.http.app))
|
return hass.loop.run_until_complete(aiohttp_client(hass.http.app))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_handle_valid_message(mock_client):
|
||||||
def test_handle_valid_message(mock_client):
|
|
||||||
"""Test that we forward messages correctly to OwnTracks."""
|
"""Test that we forward messages correctly to OwnTracks."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test",
|
"/api/webhook/owntracks_test",
|
||||||
json=LOCATION_MESSAGE,
|
json=LOCATION_MESSAGE,
|
||||||
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
||||||
@ -66,14 +63,13 @@ def test_handle_valid_message(mock_client):
|
|||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
json = yield from resp.json()
|
json = await resp.json()
|
||||||
assert json == []
|
assert json == []
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_handle_valid_minimal_message(mock_client):
|
||||||
def test_handle_valid_minimal_message(mock_client):
|
|
||||||
"""Test that we forward messages correctly to OwnTracks."""
|
"""Test that we forward messages correctly to OwnTracks."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test",
|
"/api/webhook/owntracks_test",
|
||||||
json=MINIMAL_LOCATION_MESSAGE,
|
json=MINIMAL_LOCATION_MESSAGE,
|
||||||
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
||||||
@ -81,14 +77,13 @@ def test_handle_valid_minimal_message(mock_client):
|
|||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
json = yield from resp.json()
|
json = await resp.json()
|
||||||
assert json == []
|
assert json == []
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_handle_value_error(mock_client):
|
||||||
def test_handle_value_error(mock_client):
|
|
||||||
"""Test we don't disclose that this is a valid webhook."""
|
"""Test we don't disclose that this is a valid webhook."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test",
|
"/api/webhook/owntracks_test",
|
||||||
json="",
|
json="",
|
||||||
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
headers={"X-Limit-u": "Paulus", "X-Limit-d": "Pixel"},
|
||||||
@ -96,14 +91,13 @@ def test_handle_value_error(mock_client):
|
|||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
json = yield from resp.text()
|
json = await resp.text()
|
||||||
assert json == ""
|
assert json == ""
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_returns_error_missing_username(mock_client, caplog):
|
||||||
def test_returns_error_missing_username(mock_client, caplog):
|
|
||||||
"""Test that an error is returned when username is missing."""
|
"""Test that an error is returned when username is missing."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test",
|
"/api/webhook/owntracks_test",
|
||||||
json=LOCATION_MESSAGE,
|
json=LOCATION_MESSAGE,
|
||||||
headers={"X-Limit-d": "Pixel"},
|
headers={"X-Limit-d": "Pixel"},
|
||||||
@ -111,29 +105,27 @@ def test_returns_error_missing_username(mock_client, caplog):
|
|||||||
|
|
||||||
# Needs to be 200 or OwnTracks keeps retrying bad packet.
|
# Needs to be 200 or OwnTracks keeps retrying bad packet.
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
json = yield from resp.json()
|
json = await resp.json()
|
||||||
assert json == []
|
assert json == []
|
||||||
assert "No topic or user found" in caplog.text
|
assert "No topic or user found" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_returns_error_incorrect_json(mock_client, caplog):
|
||||||
def test_returns_error_incorrect_json(mock_client, caplog):
|
|
||||||
"""Test that an error is returned when username is missing."""
|
"""Test that an error is returned when username is missing."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test", data="not json", headers={"X-Limit-d": "Pixel"}
|
"/api/webhook/owntracks_test", data="not json", headers={"X-Limit-d": "Pixel"}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Needs to be 200 or OwnTracks keeps retrying bad packet.
|
# Needs to be 200 or OwnTracks keeps retrying bad packet.
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
json = yield from resp.json()
|
json = await resp.json()
|
||||||
assert json == []
|
assert json == []
|
||||||
assert "invalid JSON" in caplog.text
|
assert "invalid JSON" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_returns_error_missing_device(mock_client):
|
||||||
def test_returns_error_missing_device(mock_client):
|
|
||||||
"""Test that an error is returned when device name is missing."""
|
"""Test that an error is returned when device name is missing."""
|
||||||
resp = yield from mock_client.post(
|
resp = await mock_client.post(
|
||||||
"/api/webhook/owntracks_test",
|
"/api/webhook/owntracks_test",
|
||||||
json=LOCATION_MESSAGE,
|
json=LOCATION_MESSAGE,
|
||||||
headers={"X-Limit-u": "Paulus"},
|
headers={"X-Limit-u": "Paulus"},
|
||||||
@ -141,7 +133,7 @@ def test_returns_error_missing_device(mock_client):
|
|||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
json = yield from resp.json()
|
json = await resp.json()
|
||||||
assert json == []
|
assert json == []
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user