Use HTTP_NOT_FOUND constant (#33835)

This commit is contained in:
springstan 2020-04-09 00:57:47 +02:00 committed by GitHub
parent ac9429988b
commit 9a40d5b7ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 98 additions and 78 deletions

View file

@ -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 = []

View file

@ -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")

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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 = (

View file

@ -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

View file

@ -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)

View file

@ -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")

View file

@ -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 == ""

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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"}

View file

@ -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):

View file

@ -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):

View file

@ -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

View file

@ -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,

View file

@ -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 (

View file

@ -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

View file

@ -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):

View file

@ -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})

View file

@ -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())})

View file

@ -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)

View file

@ -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")

View file

@ -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

View file

@ -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)

View file

@ -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):

View file

@ -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):