Use HTTPStatus instead of HTTP_ consts and magic values in comp.../[bc]* (#57989)

This commit is contained in:
Ville Skyttä 2021-10-22 20:43:40 +03:00 committed by GitHub
parent ab7a34fc71
commit 73d192b3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 169 additions and 182 deletions

View file

@ -1,17 +1,13 @@
"""Support for BloomSky weather station."""
from datetime import timedelta
from http import HTTPStatus
import logging
from aiohttp.hdrs import AUTHORIZATION
import requests
import voluptuous as vol
from homeassistant.const import (
CONF_API_KEY,
HTTP_METHOD_NOT_ALLOWED,
HTTP_OK,
HTTP_UNAUTHORIZED,
)
from homeassistant.const import CONF_API_KEY
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle
@ -72,12 +68,12 @@ class BloomSky:
headers={AUTHORIZATION: self._api_key},
timeout=10,
)
if response.status_code == HTTP_UNAUTHORIZED:
if response.status_code == HTTPStatus.UNAUTHORIZED:
raise RuntimeError("Invalid API_KEY")
if response.status_code == HTTP_METHOD_NOT_ALLOWED:
if response.status_code == HTTPStatus.METHOD_NOT_ALLOWED:
_LOGGER.error("You have no bloomsky devices configured")
return
if response.status_code != HTTP_OK:
if response.status_code != HTTPStatus.OK:
_LOGGER.error("Invalid HTTP response: %s", response.status_code)
return
# Create dictionary keyed off of the device unique id

View file

@ -2,6 +2,7 @@
import asyncio
from asyncio import CancelledError
from datetime import timedelta
from http import HTTPStatus
import logging
from urllib import parse
@ -38,7 +39,6 @@ from homeassistant.const import (
CONF_PORT,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
HTTP_OK,
STATE_IDLE,
STATE_OFF,
STATE_PAUSED,
@ -351,7 +351,7 @@ class BluesoundPlayer(MediaPlayerEntity):
with async_timeout.timeout(10):
response = await websession.get(url)
if response.status == HTTP_OK:
if response.status == HTTPStatus.OK:
result = await response.text()
if result:
data = xmltodict.parse(result)
@ -395,7 +395,7 @@ class BluesoundPlayer(MediaPlayerEntity):
url, headers={CONNECTION: KEEP_ALIVE}
)
if response.status == HTTP_OK:
if response.status == HTTPStatus.OK:
result = await response.text()
self._is_online = True
self._last_status_update = dt_util.utcnow()

View file

@ -1,5 +1,6 @@
"""The Bond integration."""
from asyncio import TimeoutError as AsyncIOTimeoutError
from http import HTTPStatus
import logging
from typing import Any
@ -7,12 +8,7 @@ from aiohttp import ClientError, ClientResponseError, ClientTimeout
from bond_api import Bond, BPUPSubscriptions, start_bpup
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_HOST,
EVENT_HOMEASSISTANT_STOP,
HTTP_UNAUTHORIZED,
)
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
@ -44,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try:
await hub.setup()
except ClientResponseError as ex:
if ex.status == HTTP_UNAUTHORIZED:
if ex.status == HTTPStatus.UNAUTHORIZED:
_LOGGER.error("Bond token no longer valid: %s", ex)
return False
raise ConfigEntryNotReady from ex

View file

@ -1,6 +1,7 @@
"""Config flow for Bond integration."""
from __future__ import annotations
from http import HTTPStatus
import logging
from typing import Any
@ -10,12 +11,7 @@ import voluptuous as vol
from homeassistant import config_entries, exceptions
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_HOST,
CONF_NAME,
HTTP_UNAUTHORIZED,
)
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import AbortFlow, FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -56,7 +52,7 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> tuple[st
except ClientConnectionError as error:
raise InputValidationError("cannot_connect") from error
except ClientResponseError as error:
if error.status == HTTP_UNAUTHORIZED:
if error.status == HTTPStatus.UNAUTHORIZED:
raise InputValidationError("invalid_auth") from error
raise InputValidationError("unknown") from error
except Exception as error:

View file

@ -1,6 +1,7 @@
"""Shared utilities for different supported platforms."""
import asyncio
from datetime import datetime, timedelta
from http import HTTPStatus
import logging
import aiohttp
@ -25,7 +26,7 @@ from buienradar.constants import (
)
from buienradar.urls import JSON_FEED_URL, json_precipitation_forecast_url
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, HTTP_OK
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.util import dt as dt_util
@ -92,7 +93,7 @@ class BrData:
result[STATUS_CODE] = resp.status
result[CONTENT] = await resp.text()
if resp.status == HTTP_OK:
if resp.status == HTTPStatus.OK:
result[SUCCESS] = True
else:
result[MESSAGE] = "Got http statuscode: %d" % (resp.status)

View file

@ -1,4 +1,5 @@
"""Clicksend platform for notify component."""
from http import HTTPStatus
import json
import logging
@ -13,7 +14,6 @@ from homeassistant.const import (
CONF_SENDER,
CONF_USERNAME,
CONTENT_TYPE_JSON,
HTTP_OK,
)
import homeassistant.helpers.config_validation as cv
@ -81,7 +81,7 @@ class ClicksendNotificationService(BaseNotificationService):
auth=(self.username, self.api_key),
timeout=TIMEOUT,
)
if resp.status_code == HTTP_OK:
if resp.status_code == HTTPStatus.OK:
return
obj = json.loads(resp.text)
@ -101,6 +101,4 @@ def _authenticate(config):
auth=(config[CONF_USERNAME], config[CONF_API_KEY]),
timeout=TIMEOUT,
)
if resp.status_code != HTTP_OK:
return False
return True
return resp.status_code == HTTPStatus.OK

View file

@ -1,4 +1,5 @@
"""clicksend_tts platform for notify component."""
from http import HTTPStatus
import json
import logging
@ -12,7 +13,6 @@ from homeassistant.const import (
CONF_RECIPIENT,
CONF_USERNAME,
CONTENT_TYPE_JSON,
HTTP_OK,
)
import homeassistant.helpers.config_validation as cv
@ -88,7 +88,7 @@ class ClicksendNotificationService(BaseNotificationService):
timeout=TIMEOUT,
)
if resp.status_code == HTTP_OK:
if resp.status_code == HTTPStatus.OK:
return
obj = json.loads(resp.text)
response_msg = obj["response_msg"]
@ -108,7 +108,4 @@ def _authenticate(config):
timeout=TIMEOUT,
)
if resp.status_code != HTTP_OK:
return False
return True
return resp.status_code == HTTPStatus.OK

View file

@ -2,6 +2,7 @@
import asyncio
from contextlib import suppress
from datetime import timedelta
from http import HTTPStatus
import logging
import aiohttp
@ -19,7 +20,6 @@ from homeassistant.const import (
CLOUD_NEVER_EXPOSED_ENTITIES,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
HTTP_BAD_REQUEST,
)
from homeassistant.core import HomeAssistant, callback, split_entity_id
from homeassistant.helpers import entity_registry as er, start
@ -161,7 +161,7 @@ class AlexaConfig(alexa_config.AbstractConfig):
resp = await cloud_api.async_alexa_access_token(self._cloud)
body = await resp.json()
if resp.status == HTTP_BAD_REQUEST:
if resp.status == HTTPStatus.BAD_REQUEST:
if body["reason"] in ("RefreshTokenNotFound", "UnknownRegion"):
if self.should_report_state:
await self._prefs.async_update(alexa_report_state=False)

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
from http import HTTPStatus
import logging
from pathlib import Path
from typing import Any
@ -14,7 +15,6 @@ from homeassistant.components.alexa import (
smart_home as alexa_sh,
)
from homeassistant.components.google_assistant import const as gc, smart_home as ga
from homeassistant.const import HTTP_OK
from homeassistant.core import Context, HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_call_later
@ -210,7 +210,7 @@ class CloudClient(Interface):
break
if found is None:
return {"status": HTTP_OK}
return {"status": HTTPStatus.OK}
request = MockRequest(
content=payload["body"].encode("utf-8"),

View file

@ -1,5 +1,6 @@
"""Google config for Cloud."""
import asyncio
from http import HTTPStatus
import logging
from hass_nabucasa import Cloud, cloud_api
@ -11,7 +12,6 @@ from homeassistant.const import (
CLOUD_NEVER_EXPOSED_ENTITIES,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
HTTP_OK,
)
from homeassistant.core import CoreState, split_entity_id
from homeassistant.helpers import entity_registry as er, start
@ -178,7 +178,7 @@ class CloudGoogleConfig(AbstractConfig):
async def _async_request_sync_devices(self, agent_user_id: str):
"""Trigger a sync with Google."""
if self._sync_entities_lock.locked():
return HTTP_OK
return HTTPStatus.OK
async with self._sync_entities_lock:
resp = await cloud_api.async_google_actions_request_sync(self._cloud)

View file

@ -1,6 +1,7 @@
"""The HTTP api to control the cloud integration."""
import asyncio
from functools import wraps
from http import HTTPStatus
import logging
import aiohttp
@ -20,12 +21,6 @@ from homeassistant.components.google_assistant import helpers as google_helpers
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.websocket_api import const as ws_const
from homeassistant.const import (
HTTP_BAD_GATEWAY,
HTTP_BAD_REQUEST,
HTTP_INTERNAL_SERVER_ERROR,
HTTP_UNAUTHORIZED,
)
from .const import (
DOMAIN,
@ -48,19 +43,19 @@ _LOGGER = logging.getLogger(__name__)
_CLOUD_ERRORS = {
InvalidTrustedNetworks: (
HTTP_INTERNAL_SERVER_ERROR,
HTTPStatus.INTERNAL_SERVER_ERROR,
"Remote UI not compatible with 127.0.0.1/::1 as a trusted network.",
),
InvalidTrustedProxies: (
HTTP_INTERNAL_SERVER_ERROR,
HTTPStatus.INTERNAL_SERVER_ERROR,
"Remote UI not compatible with 127.0.0.1/::1 as trusted proxies.",
),
asyncio.TimeoutError: (
HTTP_BAD_GATEWAY,
HTTPStatus.BAD_GATEWAY,
"Unable to reach the Home Assistant cloud.",
),
aiohttp.ClientError: (
HTTP_INTERNAL_SERVER_ERROR,
HTTPStatus.INTERNAL_SERVER_ERROR,
"Error making internal request",
),
}
@ -96,15 +91,15 @@ async def async_setup(hass):
_CLOUD_ERRORS.update(
{
auth.UserNotFound: (HTTP_BAD_REQUEST, "User does not exist."),
auth.UserNotConfirmed: (HTTP_BAD_REQUEST, "Email not confirmed."),
auth.UserNotFound: (HTTPStatus.BAD_REQUEST, "User does not exist."),
auth.UserNotConfirmed: (HTTPStatus.BAD_REQUEST, "Email not confirmed."),
auth.UserExists: (
HTTP_BAD_REQUEST,
HTTPStatus.BAD_REQUEST,
"An account with the given email already exists.",
),
auth.Unauthenticated: (HTTP_UNAUTHORIZED, "Authentication failed."),
auth.Unauthenticated: (HTTPStatus.UNAUTHORIZED, "Authentication failed."),
auth.PasswordChangeRequired: (
HTTP_BAD_REQUEST,
HTTPStatus.BAD_REQUEST,
"Password change required.",
),
}
@ -157,7 +152,7 @@ def _process_cloud_exception(exc, where):
if err_info is None:
_LOGGER.exception("Unexpected error processing request for %s", where)
err_info = (HTTP_BAD_GATEWAY, f"Unexpected error: {exc}")
err_info = (HTTPStatus.BAD_GATEWAY, f"Unexpected error: {exc}")
return err_info

View file

@ -56,7 +56,7 @@ async def test_fetching_url_and_caching(aioclient_mock, hass, hass_client):
resp = await client.get("/api/camera_proxy/camera.buienradar_51_5288505_400216")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert aioclient_mock.call_count == 1
body = await resp.text()
assert body == "hello world"
@ -86,7 +86,7 @@ async def test_expire_delta(aioclient_mock, hass, hass_client):
resp = await client.get("/api/camera_proxy/camera.buienradar_51_5288505_400216")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert aioclient_mock.call_count == 1
body = await resp.text()
assert body == "hello world"

View file

@ -1,5 +1,6 @@
"""The tests for the calendar component."""
from datetime import timedelta
from http import HTTPStatus
from homeassistant.bootstrap import async_setup_component
import homeassistant.util.dt as dt_util
@ -11,7 +12,7 @@ async def test_events_http_api(hass, hass_client):
await hass.async_block_till_done()
client = await hass_client()
response = await client.get("/api/calendars/calendar.calendar_2")
assert response.status == 400
assert response.status == HTTPStatus.BAD_REQUEST
start = dt_util.now()
end = start + timedelta(days=1)
response = await client.get(
@ -19,7 +20,7 @@ async def test_events_http_api(hass, hass_client):
start.isoformat(), end.isoformat()
)
)
assert response.status == 200
assert response.status == HTTPStatus.OK
events = await response.json()
assert events[0]["summary"] == "Future Event"
assert events[0]["title"] == "Future Event"
@ -31,7 +32,7 @@ async def test_calendars_http_api(hass, hass_client):
await hass.async_block_till_done()
client = await hass_client()
response = await client.get("/api/calendars")
assert response.status == 200
assert response.status == HTTPStatus.OK
data = await response.json()
assert data == [
{"entity_id": "calendar.calendar_1", "name": "Calendar 1"},

View file

@ -1,6 +1,7 @@
"""The tests for the camera component."""
import asyncio
import base64
from http import HTTPStatus
import io
from unittest.mock import Mock, PropertyMock, mock_open, patch
@ -15,12 +16,7 @@ from homeassistant.components.camera.const import (
from homeassistant.components.camera.prefs import CameraEntityPreferences
from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.config import async_process_ha_core_config
from homeassistant.const import (
ATTR_ENTITY_ID,
EVENT_HOMEASSISTANT_START,
HTTP_BAD_GATEWAY,
HTTP_OK,
)
from homeassistant.const import ATTR_ENTITY_ID, EVENT_HOMEASSISTANT_START
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import async_setup_component
@ -481,14 +477,14 @@ async def test_camera_proxy_stream(hass, mock_camera, hass_client):
client = await hass_client()
response = await client.get("/api/camera_proxy_stream/camera.demo_camera")
assert response.status == HTTP_OK
assert response.status == HTTPStatus.OK
with patch(
"homeassistant.components.demo.camera.DemoCamera.handle_async_mjpeg_stream",
return_value=None,
):
response = await client.get("/api/camera_proxy_stream/camera.demo_camera")
assert response.status == HTTP_BAD_GATEWAY
assert response.status == HTTPStatus.BAD_GATEWAY
async def test_websocket_web_rtc_offer(

View file

@ -1,4 +1,5 @@
"""Test the Cloud Google Config."""
from http import HTTPStatus
from unittest.mock import Mock, patch
import pytest
@ -6,7 +7,7 @@ import pytest
from homeassistant.components.cloud import GACTIONS_SCHEMA
from homeassistant.components.cloud.google_config import CloudGoogleConfig
from homeassistant.components.google_assistant import helpers as ga_helpers
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, HTTP_NOT_FOUND
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import CoreState, State
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.util.dt import utcnow
@ -71,9 +72,11 @@ async def test_sync_entities(mock_conf, hass, cloud_prefs):
with patch(
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
return_value=Mock(status=HTTP_NOT_FOUND),
return_value=Mock(status=HTTPStatus.NOT_FOUND),
) as mock_request_sync:
assert await mock_conf.async_sync_entities("mock-user-id") == HTTP_NOT_FOUND
assert (
await mock_conf.async_sync_entities("mock-user-id") == HTTPStatus.NOT_FOUND
)
assert len(mock_conf._store.agent_user_ids) == 0
assert len(mock_request_sync.mock_calls) == 1

View file

@ -16,7 +16,6 @@ from homeassistant.components.alexa import errors as alexa_errors
from homeassistant.components.alexa.entities import LightCapabilities
from homeassistant.components.cloud.const import DOMAIN, RequireRelink
from homeassistant.components.google_assistant.helpers import GoogleEntity
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.core import State
from . import mock_cloud, mock_cloud_prefs
@ -90,7 +89,7 @@ async def test_google_actions_sync(mock_cognito, mock_cloud_login, cloud_client)
return_value=Mock(status=200),
) as mock_request_sync:
req = await cloud_client.post("/api/cloud/google_actions/sync")
assert req.status == 200
assert req.status == HTTPStatus.OK
assert len(mock_request_sync.mock_calls) == 1
@ -98,10 +97,10 @@ async def test_google_actions_sync_fails(mock_cognito, mock_cloud_login, cloud_c
"""Test syncing Google Actions gone bad."""
with patch(
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
return_value=Mock(status=HTTP_INTERNAL_SERVER_ERROR),
return_value=Mock(status=HTTPStatus.INTERNAL_SERVER_ERROR),
) as mock_request_sync:
req = await cloud_client.post("/api/cloud/google_actions/sync")
assert req.status == HTTP_INTERNAL_SERVER_ERROR
assert req.status == HTTPStatus.INTERNAL_SERVER_ERROR
assert len(mock_request_sync.mock_calls) == 1
@ -113,7 +112,7 @@ async def test_login_view(hass, cloud_client):
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
result = await req.json()
assert result == {"success": True}
@ -124,7 +123,7 @@ async def test_login_view_random_exception(cloud_client):
req = await cloud_client.post(
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
resp = await req.json()
assert resp == {"code": "valueerror", "message": "Unexpected error: Boom"}
@ -133,7 +132,7 @@ async def test_login_view_invalid_json(cloud_client):
"""Try logging in with invalid JSON."""
with patch("hass_nabucasa.auth.CognitoAuth.async_login") as mock_login:
req = await cloud_client.post("/api/cloud/login", data="Not JSON")
assert req.status == 400
assert req.status == HTTPStatus.BAD_REQUEST
assert len(mock_login.mock_calls) == 0
@ -141,7 +140,7 @@ async def test_login_view_invalid_schema(cloud_client):
"""Try logging in with invalid schema."""
with patch("hass_nabucasa.auth.CognitoAuth.async_login") as mock_login:
req = await cloud_client.post("/api/cloud/login", json={"invalid": "schema"})
assert req.status == 400
assert req.status == HTTPStatus.BAD_REQUEST
assert len(mock_login.mock_calls) == 0
@ -154,7 +153,7 @@ async def test_login_view_request_timeout(cloud_client):
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_login_view_invalid_credentials(cloud_client):
@ -166,7 +165,7 @@ async def test_login_view_invalid_credentials(cloud_client):
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert req.status == 401
assert req.status == HTTPStatus.UNAUTHORIZED
async def test_login_view_unknown_error(cloud_client):
@ -176,7 +175,7 @@ async def test_login_view_unknown_error(cloud_client):
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_logout_view(hass, cloud_client):
@ -184,7 +183,7 @@ async def test_logout_view(hass, cloud_client):
cloud = hass.data["cloud"] = MagicMock()
cloud.logout = AsyncMock(return_value=None)
req = await cloud_client.post("/api/cloud/logout")
assert req.status == 200
assert req.status == HTTPStatus.OK
data = await req.json()
assert data == {"message": "ok"}
assert len(cloud.logout.mock_calls) == 1
@ -195,7 +194,7 @@ async def test_logout_view_request_timeout(hass, cloud_client):
cloud = hass.data["cloud"] = MagicMock()
cloud.logout.side_effect = asyncio.TimeoutError
req = await cloud_client.post("/api/cloud/logout")
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_logout_view_unknown_error(hass, cloud_client):
@ -203,7 +202,7 @@ async def test_logout_view_unknown_error(hass, cloud_client):
cloud = hass.data["cloud"] = MagicMock()
cloud.logout.side_effect = UnknownError
req = await cloud_client.post("/api/cloud/logout")
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_register_view(mock_cognito, cloud_client):
@ -211,7 +210,7 @@ async def test_register_view(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/register", json={"email": "hello@bla.com", "password": "falcon42"}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert len(mock_cognito.register.mock_calls) == 1
result_email, result_pass = mock_cognito.register.mock_calls[0][1]
assert result_email == "hello@bla.com"
@ -223,7 +222,7 @@ async def test_register_view_bad_data(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/register", json={"email": "hello@bla.com", "not_password": "falcon"}
)
assert req.status == 400
assert req.status == HTTPStatus.BAD_REQUEST
assert len(mock_cognito.logout.mock_calls) == 0
@ -233,7 +232,7 @@ async def test_register_view_request_timeout(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/register", json={"email": "hello@bla.com", "password": "falcon42"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_register_view_unknown_error(mock_cognito, cloud_client):
@ -242,7 +241,7 @@ async def test_register_view_unknown_error(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/register", json={"email": "hello@bla.com", "password": "falcon42"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_forgot_password_view(mock_cognito, cloud_client):
@ -250,7 +249,7 @@ async def test_forgot_password_view(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/forgot_password", json={"email": "hello@bla.com"}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert len(mock_cognito.initiate_forgot_password.mock_calls) == 1
@ -259,7 +258,7 @@ async def test_forgot_password_view_bad_data(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/forgot_password", json={"not_email": "hello@bla.com"}
)
assert req.status == 400
assert req.status == HTTPStatus.BAD_REQUEST
assert len(mock_cognito.initiate_forgot_password.mock_calls) == 0
@ -269,7 +268,7 @@ async def test_forgot_password_view_request_timeout(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/forgot_password", json={"email": "hello@bla.com"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_forgot_password_view_unknown_error(mock_cognito, cloud_client):
@ -278,7 +277,7 @@ async def test_forgot_password_view_unknown_error(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/forgot_password", json={"email": "hello@bla.com"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_forgot_password_view_aiohttp_error(mock_cognito, cloud_client):
@ -289,7 +288,7 @@ async def test_forgot_password_view_aiohttp_error(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/forgot_password", json={"email": "hello@bla.com"}
)
assert req.status == 500
assert req.status == HTTPStatus.INTERNAL_SERVER_ERROR
async def test_resend_confirm_view(mock_cognito, cloud_client):
@ -297,7 +296,7 @@ async def test_resend_confirm_view(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/resend_confirm", json={"email": "hello@bla.com"}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert len(mock_cognito.client.resend_confirmation_code.mock_calls) == 1
@ -306,7 +305,7 @@ async def test_resend_confirm_view_bad_data(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/resend_confirm", json={"not_email": "hello@bla.com"}
)
assert req.status == 400
assert req.status == HTTPStatus.BAD_REQUEST
assert len(mock_cognito.client.resend_confirmation_code.mock_calls) == 0
@ -316,7 +315,7 @@ async def test_resend_confirm_view_request_timeout(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/resend_confirm", json={"email": "hello@bla.com"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_resend_confirm_view_unknown_error(mock_cognito, cloud_client):
@ -325,7 +324,7 @@ async def test_resend_confirm_view_unknown_error(mock_cognito, cloud_client):
req = await cloud_client.post(
"/api/cloud/resend_confirm", json={"email": "hello@bla.com"}
)
assert req.status == 502
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_websocket_status(
@ -583,7 +582,7 @@ async def test_enabling_remote_trusted_networks_local4(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert response["error"]["code"] == HTTPStatus.INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as a trusted network."
@ -616,7 +615,7 @@ async def test_enabling_remote_trusted_networks_local6(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert response["error"]["code"] == HTTPStatus.INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as a trusted network."
@ -745,7 +744,7 @@ async def test_enabling_remote_trusted_proxies_local4(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert response["error"]["code"] == HTTPStatus.INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as trusted proxies."
@ -769,7 +768,7 @@ async def test_enabling_remote_trusted_proxies_local6(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert response["error"]["code"] == HTTPStatus.INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as trusted proxies."

View file

@ -1,4 +1,5 @@
"""Test Automation config panel."""
from http import HTTPStatus
import json
from unittest.mock import patch
@ -23,7 +24,7 @@ async def test_get_device_config(hass, hass_client):
with patch("homeassistant.components.config._read", mock_read):
resp = await client.get("/api/config/automation/config/moon")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"id": "moon"}
@ -56,7 +57,7 @@ async def test_update_device_config(hass, hass_client):
data=json.dumps({"trigger": [], "action": [], "condition": []}),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -99,7 +100,7 @@ async def test_bad_formatted_automations(hass, hass_client):
)
await hass.async_block_till_done()
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -157,7 +158,7 @@ async def test_delete_automation(hass, hass_client):
resp = await client.delete("/api/config/automation/config/sun")
await hass.async_block_till_done()
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}

View file

@ -1,6 +1,7 @@
"""Test config entries API."""
from collections import OrderedDict
from http import HTTPStatus
from unittest.mock import AsyncMock, patch
import pytest
@ -75,7 +76,7 @@ async def test_get_entries(hass, client):
).add_to_hass(hass)
resp = await client.get("/api/config/config_entries/entry")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
for entry in data:
entry.pop("entry_id")
@ -124,7 +125,7 @@ async def test_remove_entry(hass, client):
entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED)
entry.add_to_hass(hass)
resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data == {"require_restart": True}
assert len(hass.config_entries.async_entries()) == 0
@ -137,7 +138,7 @@ async def test_reload_entry(hass, client):
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data == {"require_restart": True}
assert len(hass.config_entries.async_entries()) == 1
@ -146,7 +147,7 @@ async def test_reload_entry(hass, client):
async def test_reload_invalid_entry(hass, client):
"""Test reloading an invalid entry via the API."""
resp = await client.post("/api/config/config_entries/entry/invalid/reload")
assert resp.status == 404
assert resp.status == HTTPStatus.NOT_FOUND
async def test_remove_entry_unauth(hass, client, hass_admin_user):
@ -155,7 +156,7 @@ async def test_remove_entry_unauth(hass, client, hass_admin_user):
entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED)
entry.add_to_hass(hass)
resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
assert resp.status == 401
assert resp.status == HTTPStatus.UNAUTHORIZED
assert len(hass.config_entries.async_entries()) == 1
@ -167,7 +168,7 @@ async def test_reload_entry_unauth(hass, client, hass_admin_user):
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 401
assert resp.status == HTTPStatus.UNAUTHORIZED
assert len(hass.config_entries.async_entries()) == 1
@ -178,7 +179,7 @@ async def test_reload_entry_in_failed_state(hass, client, hass_admin_user):
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 403
assert resp.status == HTTPStatus.FORBIDDEN
assert len(hass.config_entries.async_entries()) == 1
@ -186,7 +187,7 @@ async def test_available_flows(hass, client):
"""Test querying the available flows."""
with patch.object(config_flows, "FLOWS", ["hello", "world"]):
resp = await client.get("/api/config/config_entries/flow_handlers")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert set(data) == {"hello", "world"}
@ -222,7 +223,7 @@ async def test_initialize_flow(hass, client):
json={"handler": "test", "show_advanced_options": True},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
data.pop("flow_id")
@ -266,7 +267,7 @@ async def test_initialize_flow_unauth(hass, client, hass_admin_user):
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 401
assert resp.status == HTTPStatus.UNAUTHORIZED
async def test_abort(hass, client):
@ -282,7 +283,7 @@ async def test_abort(hass, client):
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
data.pop("flow_id")
assert data == {
@ -314,7 +315,7 @@ async def test_create_account(hass, client, enable_custom_integrations):
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
entries = hass.config_entries.async_entries("test")
assert len(entries) == 1
@ -369,7 +370,7 @@ async def test_two_step_flow(hass, client, enable_custom_integrations):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
@ -387,7 +388,7 @@ async def test_two_step_flow(hass, client, enable_custom_integrations):
f"/api/config/config_entries/flow/{flow_id}",
json={"user_title": "user-title"},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
entries = hass.config_entries.async_entries("test")
assert len(entries) == 1
@ -442,7 +443,7 @@ async def test_continue_flow_unauth(hass, client, hass_admin_user):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
@ -461,7 +462,7 @@ async def test_continue_flow_unauth(hass, client, hass_admin_user):
f"/api/config/config_entries/flow/{flow_id}",
json={"user_title": "user-title"},
)
assert resp.status == 401
assert resp.status == HTTPStatus.UNAUTHORIZED
async def test_get_progress_index(hass, hass_ws_client):
@ -532,14 +533,14 @@ async def test_get_progress_flow(hass, client):
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
resp2 = await client.get(
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
assert resp2.status == 200
assert resp2.status == HTTPStatus.OK
data2 = await resp2.json()
assert data == data2
@ -566,7 +567,7 @@ async def test_get_progress_flow_unauth(hass, client, hass_admin_user):
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
hass_admin_user.groups = []
@ -575,7 +576,7 @@ async def test_get_progress_flow_unauth(hass, client, hass_admin_user):
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
assert resp2.status == 401
assert resp2.status == HTTPStatus.UNAUTHORIZED
async def test_options_flow(hass, client):
@ -608,7 +609,7 @@ async def test_options_flow(hass, client):
url = "/api/config/config_entries/options/flow"
resp = await client.post(url, json={"handler": entry.entry_id})
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
data.pop("flow_id")
@ -657,7 +658,7 @@ async def test_two_step_options_flow(hass, client):
url = "/api/config/config_entries/options/flow"
resp = await client.post(url, json={"handler": entry.entry_id})
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
@ -675,7 +676,7 @@ async def test_two_step_options_flow(hass, client):
f"/api/config/config_entries/options/flow/{flow_id}",
json={"enabled": True},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
data.pop("flow_id")
assert data == {

View file

@ -1,4 +1,5 @@
"""Test core config."""
from http import HTTPStatus
from unittest.mock import patch
import pytest
@ -33,7 +34,7 @@ async def test_validate_config_ok(hass, hass_client):
):
resp = await client.post("/api/config/core/check_config")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result["result"] == "valid"
assert result["errors"] is None
@ -44,7 +45,7 @@ async def test_validate_config_ok(hass, hass_client):
):
resp = await client.post("/api/config/core/check_config")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result["result"] == "invalid"
assert result["errors"] == "beer"

View file

@ -1,4 +1,5 @@
"""Test Customize config panel."""
from http import HTTPStatus
import json
from unittest.mock import patch
@ -22,7 +23,7 @@ async def test_get_entity(hass, hass_client):
with patch("homeassistant.components.config._read", mock_read):
resp = await client.get("/api/config/customize/config/hello.beer")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"local": {"free": "beer"}, "global": {"cold": "beer"}}
@ -65,7 +66,7 @@ async def test_update_entity(hass, hass_client):
)
await hass.async_block_till_done()
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -94,7 +95,7 @@ async def test_update_entity_invalid_key(hass, hass_client):
"/api/config/customize/config/not_entity", data=json.dumps({"name": "YO"})
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_update_entity_invalid_json(hass, hass_client):
@ -106,4 +107,4 @@ async def test_update_entity_invalid_json(hass, hass_client):
resp = await client.post("/api/config/customize/config/hello.beer", data="not json")
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST

View file

@ -1,4 +1,5 @@
"""Test Group config panel."""
from http import HTTPStatus
import json
from unittest.mock import AsyncMock, patch
@ -22,7 +23,7 @@ async def test_get_device_config(hass, hass_client):
with patch("homeassistant.components.config._read", mock_read):
resp = await client.get("/api/config/group/config/hello.beer")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"free": "beer"}
@ -63,7 +64,7 @@ async def test_update_device_config(hass, hass_client):
)
await hass.async_block_till_done()
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -85,7 +86,7 @@ async def test_update_device_config_invalid_key(hass, hass_client):
"/api/config/group/config/not a slug", data=json.dumps({"name": "YO"})
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_update_device_config_invalid_data(hass, hass_client):
@ -99,7 +100,7 @@ async def test_update_device_config_invalid_data(hass, hass_client):
"/api/config/group/config/hello_beer", data=json.dumps({"invalid_option": 2})
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_update_device_config_invalid_json(hass, hass_client):
@ -111,4 +112,4 @@ async def test_update_device_config_invalid_json(hass, hass_client):
resp = await client.post("/api/config/group/config/hello_beer", data="not json")
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST

View file

@ -1,4 +1,5 @@
"""Test Automation config panel."""
from http import HTTPStatus
import json
from unittest.mock import patch
@ -40,7 +41,7 @@ async def test_create_scene(hass, hass_client):
),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -91,7 +92,7 @@ async def test_update_scene(hass, hass_client):
),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -148,7 +149,7 @@ async def test_bad_formatted_scene(hass, hass_client):
),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -202,7 +203,7 @@ async def test_delete_scene(hass, hass_client):
resp = await client.delete("/api/config/scene/config/light_on")
await hass.async_block_till_done()
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}

View file

@ -1,4 +1,5 @@
"""Tests for config/script."""
from http import HTTPStatus
from unittest.mock import patch
from homeassistant.bootstrap import async_setup_component
@ -29,7 +30,7 @@ async def test_delete_script(hass, hass_client):
):
resp = await client.delete("/api/config/script/config/two")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}

View file

@ -1,4 +1,5 @@
"""Test Z-Wave config panel."""
from http import HTTPStatus
import json
from unittest.mock import MagicMock, patch
@ -7,7 +8,6 @@ import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.components.zwave import DATA_NETWORK, const
from homeassistant.const import HTTP_NOT_FOUND
from tests.mock.zwave import MockEntityValues, MockNode, MockValue
@ -33,7 +33,7 @@ async def test_get_device_config(client):
with patch("homeassistant.components.config._read", mock_read):
resp = await client.get("/api/config/zwave/device_config/hello.beer")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"free": "beer"}
@ -64,7 +64,7 @@ async def test_update_device_config(client):
data=json.dumps({"polling_intensity": 2}),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"result": "ok"}
@ -80,7 +80,7 @@ async def test_update_device_config_invalid_key(client):
data=json.dumps({"polling_intensity": 2}),
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_update_device_config_invalid_data(client):
@ -90,7 +90,7 @@ async def test_update_device_config_invalid_data(client):
data=json.dumps({"invalid_option": 2}),
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_update_device_config_invalid_json(client):
@ -99,7 +99,7 @@ async def test_update_device_config_invalid_json(client):
"/api/config/zwave/device_config/hello.beer", data="not json"
)
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_get_values(hass, client):
@ -121,7 +121,7 @@ async def test_get_values(hass, client):
resp = await client.get("/api/zwave/values/1")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {
@ -147,7 +147,7 @@ async def test_get_groups(hass, client):
resp = await client.get("/api/zwave/groups/2")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {
@ -169,7 +169,7 @@ async def test_get_groups_nogroups(hass, client):
resp = await client.get("/api/zwave/groups/2")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {}
@ -182,7 +182,7 @@ async def test_get_groups_nonode(hass, client):
resp = await client.get("/api/zwave/groups/2")
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert result == {"message": "Node not found"}
@ -206,7 +206,7 @@ async def test_get_config(hass, client):
resp = await client.get("/api/zwave/config/2")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {
@ -232,7 +232,7 @@ async def test_get_config_noconfig_node(hass, client):
resp = await client.get("/api/zwave/config/2")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {}
@ -245,7 +245,7 @@ async def test_get_config_nonode(hass, client):
resp = await client.get("/api/zwave/config/2")
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert result == {"message": "Node not found"}
@ -258,7 +258,7 @@ async def test_get_usercodes_nonode(hass, client):
resp = await client.get("/api/zwave/usercodes/2")
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert result == {"message": "Node not found"}
@ -278,7 +278,7 @@ async def test_get_usercodes(hass, client):
resp = await client.get("/api/zwave/usercodes/18")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {"0": {"code": "1234", "label": "label", "length": 4}}
@ -294,7 +294,7 @@ async def test_get_usercode_nousercode_node(hass, client):
resp = await client.get("/api/zwave/usercodes/18")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {}
@ -314,7 +314,7 @@ async def test_get_usercodes_no_genreuser(hass, client):
resp = await client.get("/api/zwave/usercodes/18")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result == {}
@ -324,7 +324,7 @@ async def test_save_config_no_network(hass, client):
"""Test saving configuration without network data."""
resp = await client.post("/api/zwave/saveconfig")
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert result == {"message": "No Z-Wave network data found"}
@ -335,7 +335,7 @@ async def test_save_config(hass, client):
resp = await client.post("/api/zwave/saveconfig")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert network.write_config.called
assert result == {"message": "Z-Wave configuration saved to file"}
@ -367,7 +367,7 @@ async def test_get_protection_values(hass, client):
resp = await client.get("/api/zwave/protection/18")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert node.get_protections.called
assert node.get_protection_item.called
@ -401,7 +401,7 @@ async def test_get_protection_values_nonexisting_node(hass, client):
resp = await client.get("/api/zwave/protection/18")
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert not node.get_protections.called
assert not node.get_protection_item.called
@ -419,7 +419,7 @@ async def test_get_protection_values_without_protectionclass(hass, client):
resp = await client.get("/api/zwave/protection/18")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert not node.get_protections.called
assert not node.get_protection_item.called
@ -452,7 +452,7 @@ async def test_set_protection_value(hass, client):
data=json.dumps({"value_id": "123456", "selection": "Protection by Sequence"}),
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert node.set_protection.called
assert result == {"message": "Protection setting successfully set"}
@ -484,7 +484,7 @@ async def test_set_protection_value_failed(hass, client):
data=json.dumps({"value_id": "123456", "selection": "Protecton by Sequence"}),
)
assert resp.status == 202
assert resp.status == HTTPStatus.ACCEPTED
result = await resp.json()
assert node.set_protection.called
assert result == {"message": "Protection setting did not complete"}
@ -516,7 +516,7 @@ async def test_set_protection_value_nonexisting_node(hass, client):
data=json.dumps({"value_id": "123456", "selection": "Protecton by Sequence"}),
)
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert not node.set_protection.called
assert result == {"message": "Node not found"}
@ -536,7 +536,7 @@ async def test_set_protection_value_missing_class(hass, client):
data=json.dumps({"value_id": "123456", "selection": "Protecton by Sequence"}),
)
assert resp.status == HTTP_NOT_FOUND
assert resp.status == HTTPStatus.NOT_FOUND
result = await resp.json()
assert not node.set_protection.called
assert result == {"message": "No protection commandclass on this node"}

View file

@ -1,4 +1,6 @@
"""The tests for the Conversation component."""
from http import HTTPStatus
import pytest
from homeassistant.components import conversation
@ -116,7 +118,7 @@ async def test_http_processing_intent(hass, hass_client, hass_admin_user):
"/api/conversation/process", json={"text": "I would like the Grolsch beer"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data == {
@ -212,7 +214,7 @@ async def test_http_api(hass, hass_client):
resp = await client.post(
"/api/conversation/process", json={"text": "Turn the kitchen on"}
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert len(calls) == 1
call = calls[0]
@ -232,10 +234,10 @@ async def test_http_api_wrong_data(hass, hass_client):
client = await hass_client()
resp = await client.post("/api/conversation/process", json={"text": 123})
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
resp = await client.post("/api/conversation/process", json={})
assert resp.status == 400
assert resp.status == HTTPStatus.BAD_REQUEST
async def test_custom_agent(hass, hass_client, hass_admin_user):
@ -263,7 +265,7 @@ async def test_custom_agent(hass, hass_client, hass_admin_user):
"/api/conversation/process",
json={"text": "Test Text", "conversation_id": "test-conv-id"},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert await resp.json() == {
"card": {},
"speech": {"plain": {"extra_data": None, "speech": "Test response"}},