Use http.HTTPStatus in components/[tuv]* (#58325)
This commit is contained in:
parent
45a98aee10
commit
cc0c79ac9a
14 changed files with 69 additions and 57 deletions
|
@ -1,4 +1,5 @@
|
|||
"""The tests the for Traccar device tracker platform."""
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -8,12 +9,7 @@ from homeassistant.components import traccar, zone
|
|||
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
|
||||
from homeassistant.components.traccar import DOMAIN, TRACKER_UPDATE
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
HTTP_OK,
|
||||
HTTP_UNPROCESSABLE_ENTITY,
|
||||
STATE_HOME,
|
||||
STATE_NOT_HOME,
|
||||
)
|
||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.dispatcher import DATA_DISPATCHER
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -84,21 +80,21 @@ async def test_missing_data(hass, client, webhook_id):
|
|||
# No data
|
||||
req = await client.post(url)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_UNPROCESSABLE_ENTITY
|
||||
assert req.status == HTTPStatus.UNPROCESSABLE_ENTITY
|
||||
|
||||
# No latitude
|
||||
copy = data.copy()
|
||||
del copy["lat"]
|
||||
req = await client.post(url, params=copy)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_UNPROCESSABLE_ENTITY
|
||||
assert req.status == HTTPStatus.UNPROCESSABLE_ENTITY
|
||||
|
||||
# No device
|
||||
copy = data.copy()
|
||||
del copy["id"]
|
||||
req = await client.post(url, params=copy)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_UNPROCESSABLE_ENTITY
|
||||
assert req.status == HTTPStatus.UNPROCESSABLE_ENTITY
|
||||
|
||||
|
||||
async def test_enter_and_exit(hass, client, webhook_id):
|
||||
|
@ -109,7 +105,7 @@ async def test_enter_and_exit(hass, client, webhook_id):
|
|||
# Enter the Home
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
|
||||
).state
|
||||
|
@ -118,7 +114,7 @@ async def test_enter_and_exit(hass, client, webhook_id):
|
|||
# Enter Home again
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
|
||||
).state
|
||||
|
@ -130,7 +126,7 @@ async def test_enter_and_exit(hass, client, webhook_id):
|
|||
# Enter Somewhere else
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
|
||||
).state
|
||||
|
@ -160,7 +156,7 @@ async def test_enter_with_attrs(hass, client, webhook_id):
|
|||
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
|
||||
assert state.state == STATE_NOT_HOME
|
||||
assert state.attributes["gps_accuracy"] == 10.5
|
||||
|
@ -182,7 +178,7 @@ async def test_enter_with_attrs(hass, client, webhook_id):
|
|||
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
|
||||
assert state.state == STATE_HOME
|
||||
assert state.attributes["gps_accuracy"] == 123
|
||||
|
@ -201,7 +197,7 @@ async def test_two_devices(hass, client, webhook_id):
|
|||
# Exit Home
|
||||
req = await client.post(url, params=data_device_1)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["id"]))
|
||||
assert state.state == "not_home"
|
||||
|
@ -213,7 +209,7 @@ async def test_two_devices(hass, client, webhook_id):
|
|||
data_device_2["id"] = "device_2"
|
||||
req = await client.post(url, params=data_device_2)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_2["id"]))
|
||||
assert state.state == "home"
|
||||
|
@ -232,7 +228,7 @@ async def test_load_unload_entry(hass, client, webhook_id):
|
|||
# Enter the Home
|
||||
req = await client.post(url, params=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
assert req.status == HTTPStatus.OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
|
||||
).state
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue