* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
134 lines
4.3 KiB
Python
134 lines
4.3 KiB
Python
"""The tests the for Meraki device tracker."""
|
|
import asyncio
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.meraki.device_tracker import (
|
|
CONF_VALIDATOR, CONF_SECRET)
|
|
from homeassistant.setup import async_setup_component
|
|
import homeassistant.components.device_tracker as device_tracker
|
|
from homeassistant.const import CONF_PLATFORM
|
|
from homeassistant.components.meraki.device_tracker import URL
|
|
|
|
|
|
@pytest.fixture
|
|
def meraki_client(loop, hass, hass_client):
|
|
"""Meraki mock client."""
|
|
assert loop.run_until_complete(
|
|
async_setup_component(
|
|
hass,
|
|
device_tracker.DOMAIN,
|
|
{
|
|
device_tracker.DOMAIN: {
|
|
CONF_PLATFORM: "meraki",
|
|
CONF_VALIDATOR: "validator",
|
|
CONF_SECRET: "secret",
|
|
}
|
|
},
|
|
)
|
|
)
|
|
|
|
yield loop.run_until_complete(hass_client())
|
|
|
|
|
|
@asyncio.coroutine
|
|
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()
|
|
assert req.status == 200
|
|
assert text == "validator"
|
|
|
|
req = yield from meraki_client.post(URL, data=b"invalid")
|
|
text = yield from 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()
|
|
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()
|
|
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()
|
|
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()
|
|
assert req.status == 422
|
|
assert text["message"] == "Invalid device type"
|
|
|
|
data = {
|
|
"version": "2.0",
|
|
"secret": "secret",
|
|
"type": "BluetoothDevicesSeen",
|
|
"data": {"observations": []},
|
|
}
|
|
req = yield from 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):
|
|
"""Test with valid data."""
|
|
data = {
|
|
"version": "2.0",
|
|
"secret": "secret",
|
|
"type": "DevicesSeen",
|
|
"data": {
|
|
"observations": [
|
|
{
|
|
"location": {
|
|
"lat": "51.5355157",
|
|
"lng": "21.0699035",
|
|
"unc": "46.3610585",
|
|
},
|
|
"seenTime": "2016-09-12T16:23:13Z",
|
|
"ssid": "ssid",
|
|
"os": "HA",
|
|
"ipv6": "2607:f0d0:1002:51::4/64",
|
|
"clientMac": "00:26:ab:b8:a9:a4",
|
|
"seenEpoch": "147369739",
|
|
"rssi": "20",
|
|
"manufacturer": "Seiko Epson",
|
|
},
|
|
{
|
|
"location": {
|
|
"lat": "51.5355357",
|
|
"lng": "21.0699635",
|
|
"unc": "46.3610585",
|
|
},
|
|
"seenTime": "2016-09-12T16:21:13Z",
|
|
"ssid": "ssid",
|
|
"os": "HA",
|
|
"ipv4": "192.168.0.1",
|
|
"clientMac": "00:26:ab:b8:a9:a5",
|
|
"seenEpoch": "147369750",
|
|
"rssi": "20",
|
|
"manufacturer": "Seiko Epson",
|
|
},
|
|
]
|
|
},
|
|
}
|
|
req = yield from meraki_client.post(URL, data=json.dumps(data))
|
|
assert req.status == 200
|
|
yield from hass.async_block_till_done()
|
|
state_name = hass.states.get(
|
|
"{}.{}".format("device_tracker", "00_26_ab_b8_a9_a4")
|
|
).state
|
|
assert "home" == state_name
|
|
|
|
state_name = hass.states.get(
|
|
"{}.{}".format("device_tracker", "00_26_ab_b8_a9_a5")
|
|
).state
|
|
assert "home" == state_name
|