Migrate collection of component tests from coroutine to async/await (#30504)
This commit is contained in:
1 parent
f400b77837
commit
e642d95d0f
7 files changed
+45
-69
No files matched your search
@@ -1,5 +1,4 @@
|
||||
"""The tests the for Meraki device tracker."""
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
import pytest
|
||||
@@ -34,39 +33,38 @@ def meraki_client(loop, hass, hass_client):
|
||||
yield loop.run_until_complete(hass_client())
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client):
|
||||
async def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client):
|
||||
"""Test validator with invalid or missing data."""
|
||||
req = yield from meraki_client.get(URL)
|
||||
text = yield from req.text()
|
||||
req = await meraki_client.get(URL)
|
||||
text = await req.text()
|
||||
assert req.status == 200
|
||||
assert text == "validator"
|
||||
|
||||
req = yield from meraki_client.post(URL, data=b"invalid")
|
||||
text = yield from req.json()
|
||||
req = await meraki_client.post(URL, data=b"invalid")
|
||||
text = await req.json()
|
||||
assert req.status == 400
|
||||
assert text["message"] == "Invalid JSON"
|
||||
|
||||
req = yield from meraki_client.post(URL, data=b"{}")
|
||||
text = yield from req.json()
|
||||
req = await meraki_client.post(URL, data=b"{}")
|
||||
text = await req.json()
|
||||
assert req.status == 422
|
||||
assert text["message"] == "No secret"
|
||||
|
||||
data = {"version": "1.0", "secret": "secret"}
|
||||
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
||||
text = yield from req.json()
|
||||
req = await meraki_client.post(URL, data=json.dumps(data))
|
||||
text = await req.json()
|
||||
assert req.status == 422
|
||||
assert text["message"] == "Invalid version"
|
||||
|
||||
data = {"version": "2.0", "secret": "invalid"}
|
||||
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
||||
text = yield from req.json()
|
||||
req = await meraki_client.post(URL, data=json.dumps(data))
|
||||
text = await req.json()
|
||||
assert req.status == 422
|
||||
assert text["message"] == "Invalid secret"
|
||||
|
||||
data = {"version": "2.0", "secret": "secret", "type": "InvalidType"}
|
||||
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
||||
text = yield from req.json()
|
||||
req = await meraki_client.post(URL, data=json.dumps(data))
|
||||
text = await req.json()
|
||||
assert req.status == 422
|
||||
assert text["message"] == "Invalid device type"
|
||||
|
||||
@@ -76,12 +74,11 @@ def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client):
|
||||
"type": "BluetoothDevicesSeen",
|
||||
"data": {"observations": []},
|
||||
}
|
||||
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
||||
req = await meraki_client.post(URL, data=json.dumps(data))
|
||||
assert req.status == 200
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_data_will_be_saved(mock_device_tracker_conf, hass, meraki_client):
|
||||
async def test_data_will_be_saved(mock_device_tracker_conf, hass, meraki_client):
|
||||
"""Test with valid data."""
|
||||
data = {
|
||||
"version": "2.0",
|
||||
@@ -122,9 +119,9 @@ def test_data_will_be_saved(mock_device_tracker_conf, hass, meraki_client):
|
||||
]
|
||||
},
|
||||
}
|
||||
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
||||
req = await meraki_client.post(URL, data=json.dumps(data))
|
||||
assert req.status == 200
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format("device_tracker", "00_26_ab_b8_a9_a4")
|
||||
).state
|
||||
|
||||
Reference in new issue
Block a user