From 9a40d5b7edd1687d1258b520e78ee94ee148f717 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Thu, 9 Apr 2020 00:57:47 +0200 Subject: [PATCH] Use HTTP_NOT_FOUND constant (#33835) --- .../components/alexa/flash_briefings.py | 3 ++- homeassistant/components/auth/login_flow.py | 9 ++++--- homeassistant/components/config/__init__.py | 6 ++--- .../components/config/config_entries.py | 3 ++- .../components/haveibeenpwned/sensor.py | 10 ++++++-- .../components/media_player/__init__.py | 3 ++- .../components/thethingsnetwork/sensor.py | 4 +-- homeassistant/components/tts/__init__.py | 4 +-- homeassistant/helpers/data_entry_flow.py | 9 ++++--- .../components/alexa/test_flash_briefings.py | 3 ++- .../components/alexa/test_smart_home_http.py | 3 ++- tests/components/api/test_init.py | 2 +- tests/components/cloud/test_google_config.py | 7 +++--- tests/components/config/test_zwave.py | 15 +++++------ tests/components/ecobee/test_climate.py | 2 +- tests/components/emulated_hue/test_hue_api.py | 7 +++--- tests/components/frontend/test_init.py | 7 +++--- tests/components/generic/test_camera.py | 4 +-- tests/components/konnected/test_init.py | 25 ++++++++----------- tests/components/mailbox/test_init.py | 8 +++--- .../components/rss_feed_template/test_init.py | 3 ++- tests/components/shopping_list/test_init.py | 3 ++- .../smartthings/test_config_flow.py | 3 ++- tests/components/startca/test_sensor.py | 6 +++-- tests/components/stream/test_hls.py | 5 ++-- tests/components/stt/test_init.py | 5 ++-- tests/components/teksavvy/test_sensor.py | 4 +-- tests/components/tesla/test_config_flow.py | 8 +++--- tests/components/tts/test_init.py | 5 ++-- 29 files changed, 98 insertions(+), 78 deletions(-) diff --git a/homeassistant/components/alexa/flash_briefings.py b/homeassistant/components/alexa/flash_briefings.py index 45d31d6088a..1205fd58091 100644 --- a/homeassistant/components/alexa/flash_briefings.py +++ b/homeassistant/components/alexa/flash_briefings.py @@ -4,6 +4,7 @@ import logging import uuid from homeassistant.components import http +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.core import callback from homeassistant.helpers import template import homeassistant.util.dt as dt_util @@ -54,7 +55,7 @@ class AlexaFlashBriefingView(http.HomeAssistantView): if self.flash_briefings.get(briefing_id) is None: err = "No configured Alexa flash briefing was found for: %s" _LOGGER.error(err, briefing_id) - return b"", 404 + return b"", HTTP_NOT_FOUND briefing = [] diff --git a/homeassistant/components/auth/login_flow.py b/homeassistant/components/auth/login_flow.py index 6f8d2751018..229cbb0c9df 100644 --- a/homeassistant/components/auth/login_flow.py +++ b/homeassistant/components/auth/login_flow.py @@ -79,6 +79,7 @@ from homeassistant.components.http.ban import ( ) from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.http.view import HomeAssistantView +from homeassistant.const import HTTP_NOT_FOUND from . import indieauth @@ -185,7 +186,7 @@ class LoginFlowIndexView(HomeAssistantView): }, ) except data_entry_flow.UnknownHandler: - return self.json_message("Invalid handler specified", 404) + return self.json_message("Invalid handler specified", HTTP_NOT_FOUND) except data_entry_flow.UnknownStep: return self.json_message("Handler does not support init", 400) @@ -212,7 +213,7 @@ class LoginFlowResourceView(HomeAssistantView): async def get(self, request): """Do not allow getting status of a flow in progress.""" - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) @RequestDataValidator(vol.Schema({"client_id": str}, extra=vol.ALLOW_EXTRA)) @log_invalid_auth @@ -233,7 +234,7 @@ class LoginFlowResourceView(HomeAssistantView): result = await self._flow_mgr.async_configure(flow_id, data) except data_entry_flow.UnknownFlow: - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) except vol.Invalid: return self.json_message("User input malformed", 400) @@ -257,6 +258,6 @@ class LoginFlowResourceView(HomeAssistantView): try: self._flow_mgr.async_abort(flow_id) except data_entry_flow.UnknownFlow: - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) return self.json_message("Flow aborted") diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index 682e23dd14c..12a3adbd701 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -6,7 +6,7 @@ import os import voluptuous as vol from homeassistant.components.http import HomeAssistantView -from homeassistant.const import CONF_ID, EVENT_COMPONENT_LOADED +from homeassistant.const import CONF_ID, EVENT_COMPONENT_LOADED, HTTP_NOT_FOUND from homeassistant.core import callback from homeassistant.exceptions import HomeAssistantError from homeassistant.setup import ATTR_COMPONENT @@ -120,7 +120,7 @@ class BaseEditConfigView(HomeAssistantView): value = self._get_value(hass, current, config_key) if value is None: - return self.json_message("Resource not found", 404) + return self.json_message("Resource not found", HTTP_NOT_FOUND) return self.json(value) @@ -172,7 +172,7 @@ class BaseEditConfigView(HomeAssistantView): path = hass.config.path(self.path) if value is None: - return self.json_message("Resource not found", 404) + return self.json_message("Resource not found", HTTP_NOT_FOUND) self._delete_value(hass, current, config_key) await hass.async_add_executor_job(_write, path, current) diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index c69a3ed5739..f80d63d437a 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -7,6 +7,7 @@ from homeassistant import config_entries, data_entry_flow from homeassistant.auth.permissions.const import CAT_CONFIG_ENTRIES from homeassistant.components import websocket_api from homeassistant.components.http import HomeAssistantView +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.exceptions import Unauthorized import homeassistant.helpers.config_validation as cv from homeassistant.helpers.data_entry_flow import ( @@ -105,7 +106,7 @@ class ConfigManagerEntryResourceView(HomeAssistantView): try: result = await hass.config_entries.async_remove(entry_id) except config_entries.UnknownEntry: - return self.json_message("Invalid entry specified", 404) + return self.json_message("Invalid entry specified", HTTP_NOT_FOUND) return self.json(result) diff --git a/homeassistant/components/haveibeenpwned/sensor.py b/homeassistant/components/haveibeenpwned/sensor.py index 51b06917142..0f5a9b5ebfd 100644 --- a/homeassistant/components/haveibeenpwned/sensor.py +++ b/homeassistant/components/haveibeenpwned/sensor.py @@ -7,7 +7,13 @@ import requests import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_EMAIL, HTTP_OK +from homeassistant.const import ( + ATTR_ATTRIBUTION, + CONF_API_KEY, + CONF_EMAIL, + HTTP_NOT_FOUND, + HTTP_OK, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.helpers.event import track_point_in_time @@ -167,7 +173,7 @@ class HaveIBeenPwnedData: # the forced updates try this current email again self.set_next_email() - elif req.status_code == 404: + elif req.status_code == HTTP_NOT_FOUND: self.data[self._email] = [] # only goto next email if we had data so that diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 81f0fa010b0..a8c87effb10 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -19,6 +19,7 @@ from homeassistant.components import websocket_api from homeassistant.components.http import KEY_AUTHENTICATED, HomeAssistantView from homeassistant.const import ( HTTP_INTERNAL_SERVER_ERROR, + HTTP_NOT_FOUND, HTTP_OK, SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PAUSE, @@ -865,7 +866,7 @@ class MediaPlayerImageView(HomeAssistantView): """Start a get request.""" player = self.component.get_entity(entity_id) if player is None: - status = 404 if request[KEY_AUTHENTICATED] else 401 + status = HTTP_NOT_FOUND if request[KEY_AUTHENTICATED] else 401 return web.Response(status=status) authenticated = ( diff --git a/homeassistant/components/thethingsnetwork/sensor.py b/homeassistant/components/thethingsnetwork/sensor.py index 3ba58a688fe..35a16d30f32 100644 --- a/homeassistant/components/thethingsnetwork/sensor.py +++ b/homeassistant/components/thethingsnetwork/sensor.py @@ -8,7 +8,7 @@ import async_timeout import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONTENT_TYPE_JSON +from homeassistant.const import CONTENT_TYPE_JSON, HTTP_NOT_FOUND from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -139,7 +139,7 @@ class TtnDataStorage: _LOGGER.error("Not authorized for Application ID: %s", self._app_id) return None - if status == 404: + if status == HTTP_NOT_FOUND: _LOGGER.error("Application ID is not available: %s", self._app_id) return None diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 726490b2030..6eeab8d6b1e 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -22,7 +22,7 @@ from homeassistant.components.media_player.const import ( MEDIA_TYPE_MUSIC, SERVICE_PLAY_MEDIA, ) -from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM, HTTP_OK +from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM, HTTP_NOT_FOUND, HTTP_OK from homeassistant.core import callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_per_platform, discovery @@ -568,6 +568,6 @@ class TextToSpeechView(HomeAssistantView): content, data = await self.tts.async_read_tts(filename) except HomeAssistantError as err: _LOGGER.error("Error on load tts: %s", err) - return web.Response(status=404) + return web.Response(status=HTTP_NOT_FOUND) return web.Response(body=data, content_type=content) diff --git a/homeassistant/helpers/data_entry_flow.py b/homeassistant/helpers/data_entry_flow.py index 2b92887eac3..951b6d4c748 100644 --- a/homeassistant/helpers/data_entry_flow.py +++ b/homeassistant/helpers/data_entry_flow.py @@ -5,6 +5,7 @@ import voluptuous as vol from homeassistant import config_entries, data_entry_flow from homeassistant.components.http import HomeAssistantView from homeassistant.components.http.data_validator import RequestDataValidator +from homeassistant.const import HTTP_NOT_FOUND import homeassistant.helpers.config_validation as cv # mypy: allow-untyped-calls, allow-untyped-defs @@ -62,7 +63,7 @@ class FlowManagerIndexView(_BaseFlowManagerView): handler, context={"source": config_entries.SOURCE_USER} ) except data_entry_flow.UnknownHandler: - return self.json_message("Invalid handler specified", 404) + return self.json_message("Invalid handler specified", HTTP_NOT_FOUND) except data_entry_flow.UnknownStep: return self.json_message("Handler does not support user", 400) @@ -79,7 +80,7 @@ class FlowManagerResourceView(_BaseFlowManagerView): try: result = await self._flow_mgr.async_configure(flow_id) except data_entry_flow.UnknownFlow: - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) result = self._prepare_result_json(result) @@ -91,7 +92,7 @@ class FlowManagerResourceView(_BaseFlowManagerView): try: result = await self._flow_mgr.async_configure(flow_id, data) except data_entry_flow.UnknownFlow: - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) except vol.Invalid: return self.json_message("User input malformed", 400) @@ -104,6 +105,6 @@ class FlowManagerResourceView(_BaseFlowManagerView): try: self._flow_mgr.async_abort(flow_id) except data_entry_flow.UnknownFlow: - return self.json_message("Invalid flow specified", 404) + return self.json_message("Invalid flow specified", HTTP_NOT_FOUND) return self.json_message("Flow aborted") diff --git a/tests/components/alexa/test_flash_briefings.py b/tests/components/alexa/test_flash_briefings.py index d459ee2cc32..14dbe7336fb 100644 --- a/tests/components/alexa/test_flash_briefings.py +++ b/tests/components/alexa/test_flash_briefings.py @@ -6,6 +6,7 @@ import pytest from homeassistant.components import alexa from homeassistant.components.alexa import const +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.core import callback from homeassistant.setup import async_setup_component @@ -69,7 +70,7 @@ def _flash_briefing_req(client, briefing_id): async def test_flash_briefing_invalid_id(alexa_client): """Test an invalid Flash Briefing ID.""" req = await _flash_briefing_req(alexa_client, 10000) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND text = await req.text() assert text == "" diff --git a/tests/components/alexa/test_smart_home_http.py b/tests/components/alexa/test_smart_home_http.py index f242a421eac..46db47dc2c9 100644 --- a/tests/components/alexa/test_smart_home_http.py +++ b/tests/components/alexa/test_smart_home_http.py @@ -2,6 +2,7 @@ import json from homeassistant.components.alexa import DOMAIN, smart_home_http +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from . import get_new_request @@ -38,4 +39,4 @@ async def test_http_api_disabled(hass, hass_client): config = {"alexa": {}} response = await do_http_discovery(config, hass, hass_client) - assert response.status == 404 + assert response.status == HTTP_NOT_FOUND diff --git a/tests/components/api/test_init.py b/tests/components/api/test_init.py index 4417f3d4f91..e73b65661c9 100644 --- a/tests/components/api/test_init.py +++ b/tests/components/api/test_init.py @@ -52,7 +52,7 @@ async def test_api_get_state(hass, mock_api_client): async def test_api_get_non_existing_state(hass, mock_api_client): """Test if the debug interface allows us to get a state.""" resp = await mock_api_client.get("/api/states/does_not_exist") - assert resp.status == 404 + assert resp.status == const.HTTP_NOT_FOUND async def test_api_state_change(hass, mock_api_client): diff --git a/tests/components/cloud/test_google_config.py b/tests/components/cloud/test_google_config.py index 4f08c4c37d0..1070730ba96 100644 --- a/tests/components/cloud/test_google_config.py +++ b/tests/components/cloud/test_google_config.py @@ -4,6 +4,7 @@ from unittest.mock import Mock, patch 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 HTTP_NOT_FOUND from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED from homeassistant.util.dt import utcnow @@ -41,14 +42,14 @@ async def test_sync_entities(aioclient_mock, hass, cloud_prefs): GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, - Mock(auth=Mock(async_check_token=Mock(side_effect=mock_coro)),), + Mock(auth=Mock(async_check_token=Mock(side_effect=mock_coro))), ) with patch( "hass_nabucasa.cloud_api.async_google_actions_request_sync", - return_value=mock_coro(Mock(status=404)), + return_value=mock_coro(Mock(status=HTTP_NOT_FOUND)), ) as mock_request_sync: - assert await config.async_sync_entities("user") == 404 + assert await config.async_sync_entities("user") == HTTP_NOT_FOUND assert len(mock_request_sync.mock_calls) == 1 diff --git a/tests/components/config/test_zwave.py b/tests/components/config/test_zwave.py index 059cdb1f1e8..3624554843a 100644 --- a/tests/components/config/test_zwave.py +++ b/tests/components/config/test_zwave.py @@ -7,6 +7,7 @@ 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 @@ -181,7 +182,7 @@ async def test_get_groups_nonode(hass, client): resp = await client.get("/api/zwave/groups/2") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert result == {"message": "Node not found"} @@ -244,7 +245,7 @@ async def test_get_config_nonode(hass, client): resp = await client.get("/api/zwave/config/2") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert result == {"message": "Node not found"} @@ -257,7 +258,7 @@ async def test_get_usercodes_nonode(hass, client): resp = await client.get("/api/zwave/usercodes/2") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert result == {"message": "Node not found"} @@ -323,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 == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert result == {"message": "No Z-Wave network data found"} @@ -400,7 +401,7 @@ async def test_get_protection_values_nonexisting_node(hass, client): resp = await client.get("/api/zwave/protection/18") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert not node.get_protections.called assert not node.get_protection_item.called @@ -515,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 == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert not node.set_protection.called assert result == {"message": "Node not found"} @@ -535,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 == 404 + assert resp.status == HTTP_NOT_FOUND result = await resp.json() assert not node.set_protection.called assert result == {"message": "No protection commandclass on this node"} diff --git a/tests/components/ecobee/test_climate.py b/tests/components/ecobee/test_climate.py index 0c0ca785026..63476a9b717 100644 --- a/tests/components/ecobee/test_climate.py +++ b/tests/components/ecobee/test_climate.py @@ -64,7 +64,7 @@ class TestEcobee(unittest.TestCase): def test_current_temperature(self): """Test current temperature.""" assert 30 == self.thermostat.current_temperature - self.ecobee["runtime"]["actualTemperature"] = 404 + self.ecobee["runtime"]["actualTemperature"] = const.HTTP_NOT_FOUND assert 40.4 == self.thermostat.current_temperature def test_target_temperature_low(self): diff --git a/tests/components/emulated_hue/test_hue_api.py b/tests/components/emulated_hue/test_hue_api.py index e9925132b00..a6b4113e314 100644 --- a/tests/components/emulated_hue/test_hue_api.py +++ b/tests/components/emulated_hue/test_hue_api.py @@ -34,6 +34,7 @@ from homeassistant.components.emulated_hue.hue_api import ( ) from homeassistant.const import ( ATTR_ENTITY_ID, + HTTP_NOT_FOUND, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF, @@ -450,7 +451,7 @@ async def test_put_light_state(hass_hue, hue_client): kitchen_result = await perform_put_light_state( hass_hue, hue_client, "light.kitchen_light", True ) - assert kitchen_result.status == 404 + assert kitchen_result.status == HTTP_NOT_FOUND async def test_put_light_state_script(hass_hue, hue_client): @@ -684,11 +685,11 @@ async def test_entity_not_found(hue_client): """Test for entity which are not found.""" result = await hue_client.get("/api/username/lights/not.existant_entity") - assert result.status == 404 + assert result.status == HTTP_NOT_FOUND result = await hue_client.put("/api/username/lights/not.existant_entity/state") - assert result.status == 404 + assert result.status == HTTP_NOT_FOUND async def test_allowed_methods(hue_client): diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index 36243972fb6..2d07fb33314 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -13,6 +13,7 @@ from homeassistant.components.frontend import ( EVENT_PANELS_UPDATED, ) from homeassistant.components.websocket_api.const import TYPE_RESULT +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from tests.common import async_capture_events, mock_coro @@ -97,7 +98,7 @@ async def test_dont_cache_service_worker(mock_http_client): async def test_404(mock_http_client): """Test for HTTP 404 error.""" resp = await mock_http_client.get("/not-existing") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND async def test_we_cannot_POST_to_root(mock_http_client): @@ -219,7 +220,7 @@ async def test_get_panels(hass, hass_ws_client, mock_http_client): events = async_capture_events(hass, EVENT_PANELS_UPDATED) resp = await mock_http_client.get("/map") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND hass.components.frontend.async_register_built_in_panel( "map", "Map", "mdi:tooltip-account", require_admin=True @@ -247,7 +248,7 @@ async def test_get_panels(hass, hass_ws_client, mock_http_client): hass.components.frontend.async_remove_panel("map") resp = await mock_http_client.get("/map") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND assert len(events) == 2 diff --git a/tests/components/generic/test_camera.py b/tests/components/generic/test_camera.py index 9b0466dda93..e519e0f9416 100644 --- a/tests/components/generic/test_camera.py +++ b/tests/components/generic/test_camera.py @@ -2,7 +2,7 @@ import asyncio from unittest import mock -from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR +from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR, HTTP_NOT_FOUND from homeassistant.setup import async_setup_component @@ -94,7 +94,7 @@ async def test_limit_refetch(aioclient_mock, hass, hass_client): aioclient_mock.get("http://example.com/5a", text="hello world") aioclient_mock.get("http://example.com/10a", text="hello world") aioclient_mock.get("http://example.com/15a", text="hello planet") - aioclient_mock.get("http://example.com/20a", status=404) + aioclient_mock.get("http://example.com/20a", status=HTTP_NOT_FOUND) await async_setup_component( hass, diff --git a/tests/components/konnected/test_init.py b/tests/components/konnected/test_init.py index 2a9c3f8cd4f..28071291266 100644 --- a/tests/components/konnected/test_init.py +++ b/tests/components/konnected/test_init.py @@ -4,6 +4,7 @@ import pytest from homeassistant.components import konnected from homeassistant.components.konnected import config_flow +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry @@ -254,7 +255,7 @@ async def test_setup_defined_hosts_known_auth(hass): config_flow.CONF_ID: "aabbccddeeff", config_flow.CONF_HOST: "0.0.0.0", config_flow.CONF_PORT: 1234, - }, + } ], } }, @@ -303,11 +304,7 @@ async def test_setup_multiple(hass): { konnected.CONF_ID: "aabbccddeeff", "binary_sensors": [ - { - "zone": 4, - "type": "motion", - "name": "Hallway Motion", - }, + {"zone": 4, "type": "motion", "name": "Hallway Motion"}, { "zone": 5, "type": "window", @@ -334,7 +331,7 @@ async def test_setup_multiple(hass): "momentary": 65, "pause": 55, "repeat": 4, - }, + } ], }, ], @@ -469,23 +466,23 @@ async def test_api(hass, aiohttp_client, mock_panel): # Test the get endpoint for switch status polling resp = await client.get("/api/konnected") - assert resp.status == 404 # no device provided + assert resp.status == HTTP_NOT_FOUND # no device provided resp = await client.get("/api/konnected/223344556677") - assert resp.status == 404 # unknown device provided + assert resp.status == HTTP_NOT_FOUND # unknown device provided resp = await client.get("/api/konnected/device/112233445566") - assert resp.status == 404 # no zone provided + assert resp.status == HTTP_NOT_FOUND # no zone provided result = await resp.json() assert result == {"message": "Switch on zone or pin unknown not configured"} resp = await client.get("/api/konnected/device/112233445566?zone=8") - assert resp.status == 404 # invalid zone + assert resp.status == HTTP_NOT_FOUND # invalid zone result = await resp.json() assert result == {"message": "Switch on zone or pin 8 not configured"} resp = await client.get("/api/konnected/device/112233445566?pin=12") - assert resp.status == 404 # invalid pin + assert resp.status == HTTP_NOT_FOUND # invalid pin result = await resp.json() assert result == {"message": "Switch on zone or pin 12 not configured"} @@ -501,7 +498,7 @@ async def test_api(hass, aiohttp_client, mock_panel): # Test the post endpoint for sensor updates resp = await client.post("/api/konnected/device", json={"zone": "1", "state": 1}) - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND resp = await client.post( "/api/konnected/device/112233445566", json={"zone": "1", "state": 1} @@ -622,7 +619,7 @@ async def test_state_updates(hass, aiohttp_client, mock_panel): entry.add_to_hass(hass) # Add empty data field to ensure we process it correctly (possible if entry is ignored) - entry = MockConfigEntry(domain="konnected", title="Konnected Alarm Panel", data={},) + entry = MockConfigEntry(domain="konnected", title="Konnected Alarm Panel", data={}) entry.add_to_hass(hass) assert ( diff --git a/tests/components/mailbox/test_init.py b/tests/components/mailbox/test_init.py index f35c763bf74..a2b2583bdb5 100644 --- a/tests/components/mailbox/test_init.py +++ b/tests/components/mailbox/test_init.py @@ -5,7 +5,7 @@ import pytest from homeassistant.bootstrap import async_setup_component import homeassistant.components.mailbox as mailbox -from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR +from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR, HTTP_NOT_FOUND @pytest.fixture @@ -73,7 +73,7 @@ async def test_get_messages_from_invalid_mailbox(mock_http_client): url = "/api/mailbox/messages/mailbox.invalid_mailbox" req = await mock_http_client.get(url) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND async def test_get_media_from_invalid_mailbox(mock_http_client): @@ -82,7 +82,7 @@ async def test_get_media_from_invalid_mailbox(mock_http_client): url = "/api/mailbox/media/mailbox.invalid_mailbox/%s" % (msgsha) req = await mock_http_client.get(url) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND async def test_get_media_from_invalid_msgid(mock_http_client): @@ -100,4 +100,4 @@ async def test_delete_from_invalid_mailbox(mock_http_client): url = "/api/mailbox/delete/mailbox.invalid_mailbox/%s" % (msgsha) req = await mock_http_client.delete(url) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND diff --git a/tests/components/rss_feed_template/test_init.py b/tests/components/rss_feed_template/test_init.py index fe06c6d8c1a..e0637b709e0 100644 --- a/tests/components/rss_feed_template/test_init.py +++ b/tests/components/rss_feed_template/test_init.py @@ -2,6 +2,7 @@ from defusedxml import ElementTree import pytest +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component @@ -29,7 +30,7 @@ def mock_http_client(loop, hass, hass_client): async def test_get_nonexistant_feed(mock_http_client): """Test if we can retrieve the correct rss feed.""" resp = await mock_http_client.get("/api/rss_template/otherfeed") - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND async def test_get_rss_feed(mock_http_client, hass): diff --git a/tests/components/shopping_list/test_init.py b/tests/components/shopping_list/test_init.py index 82b0d9b455d..b8930114665 100644 --- a/tests/components/shopping_list/test_init.py +++ b/tests/components/shopping_list/test_init.py @@ -1,6 +1,7 @@ """Test shopping list component.""" from homeassistant.components.websocket_api.const import TYPE_RESULT +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.helpers import intent @@ -171,7 +172,7 @@ async def test_api_update_fails(hass, hass_client, sl_setup): client = await hass_client() resp = await client.post("/api/shopping_list/non_existing", json={"name": "soda"}) - assert resp.status == 404 + assert resp.status == HTTP_NOT_FOUND beer_id = hass.data["shopping_list"].items[0]["id"] resp = await client.post(f"/api/shopping_list/item/{beer_id}", json={"name": 123}) diff --git a/tests/components/smartthings/test_config_flow.py b/tests/components/smartthings/test_config_flow.py index f299727b948..0d533910b54 100644 --- a/tests/components/smartthings/test_config_flow.py +++ b/tests/components/smartthings/test_config_flow.py @@ -15,6 +15,7 @@ from homeassistant.components.smartthings.const import ( CONF_REFRESH_TOKEN, DOMAIN, ) +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, mock_coro @@ -160,7 +161,7 @@ async def test_unknown_api_error(hass, smartthings_mock): request_info = Mock(real_url="http://example.com") smartthings_mock.apps.side_effect = ClientResponseError( - request_info=request_info, history=None, status=404 + request_info=request_info, history=None, status=HTTP_NOT_FOUND ) result = await flow.async_step_user({"access_token": str(uuid4())}) diff --git a/tests/components/startca/test_sensor.py b/tests/components/startca/test_sensor.py index 23cc892900b..f3c6af51df5 100644 --- a/tests/components/startca/test_sensor.py +++ b/tests/components/startca/test_sensor.py @@ -1,7 +1,7 @@ """Tests for the Start.ca sensor platform.""" from homeassistant.bootstrap import async_setup_component from homeassistant.components.startca.sensor import StartcaData -from homeassistant.const import DATA_GIGABYTES, UNIT_PERCENTAGE +from homeassistant.const import DATA_GIGABYTES, HTTP_NOT_FOUND, UNIT_PERCENTAGE from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -197,7 +197,9 @@ async def test_unlimited_setup(hass, aioclient_mock): async def test_bad_return_code(hass, aioclient_mock): """Test handling a return code that isn't HTTP OK.""" - aioclient_mock.get("https://www.start.ca/support/usage/api?key=NOTAKEY", status=404) + aioclient_mock.get( + "https://www.start.ca/support/usage/api?key=NOTAKEY", status=HTTP_NOT_FOUND + ) scd = StartcaData(hass.loop, async_get_clientsession(hass), "NOTAKEY", 400) diff --git a/tests/components/stream/test_hls.py b/tests/components/stream/test_hls.py index 888f56efb29..3de50d3309c 100644 --- a/tests/components/stream/test_hls.py +++ b/tests/components/stream/test_hls.py @@ -5,6 +5,7 @@ from urllib.parse import urlparse import pytest from homeassistant.components.stream import request_stream +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -49,7 +50,7 @@ async def test_hls_stream(hass, hass_client): # Ensure playlist not accessible after stream ends fail_response = await http_client.get(parsed_url.path) - assert fail_response.status == 404 + assert fail_response.status == HTTP_NOT_FOUND @pytest.mark.skip("Flaky in CI") @@ -86,7 +87,7 @@ async def test_stream_timeout(hass, hass_client): # Ensure playlist not accessible fail_response = await http_client.get(parsed_url.path) - assert fail_response.status == 404 + assert fail_response.status == HTTP_NOT_FOUND @pytest.mark.skip("Flaky in CI") diff --git a/tests/components/stt/test_init.py b/tests/components/stt/test_init.py index 1e69fa2494a..9658ab92140 100644 --- a/tests/components/stt/test_init.py +++ b/tests/components/stt/test_init.py @@ -1,6 +1,7 @@ """Test STT component setup.""" from homeassistant.components import stt +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component @@ -16,7 +17,7 @@ async def test_demo_settings_not_exists(hass, hass_client): response = await client.get("/api/stt/beer") - assert response.status == 404 + assert response.status == HTTP_NOT_FOUND async def test_demo_speech_not_exists(hass, hass_client): @@ -26,4 +27,4 @@ async def test_demo_speech_not_exists(hass, hass_client): response = await client.post("/api/stt/beer", data=b"test") - assert response.status == 404 + assert response.status == HTTP_NOT_FOUND diff --git a/tests/components/teksavvy/test_sensor.py b/tests/components/teksavvy/test_sensor.py index e3e7eae36a8..049a1ddc60c 100644 --- a/tests/components/teksavvy/test_sensor.py +++ b/tests/components/teksavvy/test_sensor.py @@ -1,7 +1,7 @@ """Tests for the TekSavvy sensor platform.""" from homeassistant.bootstrap import async_setup_component from homeassistant.components.teksavvy.sensor import TekSavvyData -from homeassistant.const import DATA_GIGABYTES, UNIT_PERCENTAGE +from homeassistant.const import DATA_GIGABYTES, HTTP_NOT_FOUND, UNIT_PERCENTAGE from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -173,7 +173,7 @@ async def test_bad_return_code(hass, aioclient_mock): "https://api.teksavvy.com/" "web/Usage/UsageSummaryRecords?" "$filter=IsCurrent%20eq%20true", - status=404, + status=HTTP_NOT_FOUND, ) tsd = TekSavvyData(hass.loop, async_get_clientsession(hass), "notakey", 400) diff --git a/tests/components/tesla/test_config_flow.py b/tests/components/tesla/test_config_flow.py index 00e7ba78cc1..8698fddbeab 100644 --- a/tests/components/tesla/test_config_flow.py +++ b/tests/components/tesla/test_config_flow.py @@ -17,6 +17,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_TOKEN, CONF_USERNAME, + HTTP_NOT_FOUND, ) from tests.common import MockConfigEntry, mock_coro @@ -81,7 +82,7 @@ async def test_form_cannot_connect(hass): with patch( "homeassistant.components.tesla.config_flow.TeslaAPI.connect", - side_effect=TeslaException(code=404), + side_effect=TeslaException(code=HTTP_NOT_FOUND), ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -147,10 +148,7 @@ async def test_option_flow(hass): user_input={CONF_SCAN_INTERVAL: 350, CONF_WAKE_ON_START: True}, ) assert result["type"] == "create_entry" - assert result["data"] == { - CONF_SCAN_INTERVAL: 350, - CONF_WAKE_ON_START: True, - } + assert result["data"] == {CONF_SCAN_INTERVAL: 350, CONF_WAKE_ON_START: True} async def test_option_flow_defaults(hass): diff --git a/tests/components/tts/test_init.py b/tests/components/tts/test_init.py index c6b847c313e..8b516e4bf9f 100644 --- a/tests/components/tts/test_init.py +++ b/tests/components/tts/test_init.py @@ -16,6 +16,7 @@ from homeassistant.components.media_player.const import ( ) import homeassistant.components.tts as tts from homeassistant.components.tts import _get_cache_files +from homeassistant.const import HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from tests.common import assert_setup_component, async_mock_service @@ -500,7 +501,7 @@ async def test_setup_component_and_web_view_wrong_file(hass, hass_client): url = "/api/tts_proxy/42f18378fd4393d18c8dd11d03fa9563c1e54491_en_-_demo.mp3" req = await client.get(url) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND async def test_setup_component_and_web_view_wrong_filename(hass, hass_client): @@ -515,7 +516,7 @@ async def test_setup_component_and_web_view_wrong_filename(hass, hass_client): url = "/api/tts_proxy/265944dsk32c1b2a621be5930510bb2cd_en_-_demo.mp3" req = await client.get(url) - assert req.status == 404 + assert req.status == HTTP_NOT_FOUND async def test_setup_component_test_without_cache(hass, empty_cache_dir):