Use HTTP_INTERNAL_SERVER_ERROR constant (#33832)

This commit is contained in:
springstan authored and GitHub committed 2020-04-08 23:20:03 +02:00
1 parent 15ab63a4c2
commit fb8f8133a0
27 files changed
+122 -69

No files matched your search

+4 -2
View File
@@ -5,7 +5,7 @@ from abodepy.exceptions import AbodeAuthenticationException
from homeassistant import data_entry_flow
from homeassistant.components.abode import config_flow
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, HTTP_INTERNAL_SERVER_ERROR
from tests.common import MockConfigEntry
@@ -74,7 +74,9 @@ async def test_connection_error(hass):
with patch(
"homeassistant.components.abode.config_flow.Abode",
side_effect=AbodeAuthenticationException((500, "connection error")),
side_effect=AbodeAuthenticationException(
(HTTP_INTERNAL_SERVER_ERROR, "connection error")
),
):
result = await flow.async_step_user(user_input=conf)
assert result["errors"] == {"base": "connection_error"}
+2 -1
View File
@@ -3,6 +3,7 @@ import asyncio
from aiohttp.client_exceptions import ClientResponseError
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
@@ -202,7 +203,7 @@ async def test_retries_after_error(aioclient_mock, hass, hass_client):
client = await hass_client()
aioclient_mock.get(radar_map_url(), text=None, status=500)
aioclient_mock.get(radar_map_url(), text=None, status=HTTP_INTERNAL_SERVER_ERROR)
# A 404 should not return data and throw:
try:
+8 -7
View File
@@ -15,6 +15,7 @@ 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
@@ -99,10 +100,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_coro(Mock(status=500)),
return_value=mock_coro(Mock(status=HTTP_INTERNAL_SERVER_ERROR)),
) as mock_request_sync:
req = await cloud_client.post("/api/cloud/google_actions/sync")
assert req.status == 500
assert req.status == HTTP_INTERNAL_SERVER_ERROR
assert len(mock_request_sync.mock_calls) == 1
@@ -436,7 +437,7 @@ async def test_websocket_subscription_fail(
hass, hass_ws_client, aioclient_mock, mock_auth, mock_cloud_login
):
"""Test querying the status."""
aioclient_mock.get(SUBSCRIPTION_INFO_URL, status=500)
aioclient_mock.get(SUBSCRIPTION_INFO_URL, status=HTTP_INTERNAL_SERVER_ERROR)
client = await hass_ws_client(hass)
await client.send_json({"id": 5, "type": "cloud/subscription"})
response = await client.receive_json()
@@ -611,7 +612,7 @@ async def test_enabling_remote_trusted_networks_local4(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == 500
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as a trusted network."
@@ -643,7 +644,7 @@ async def test_enabling_remote_trusted_networks_local6(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == 500
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as a trusted network."
@@ -744,7 +745,7 @@ async def test_enabling_remote_trusted_proxies_local4(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == 500
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as trusted proxies."
@@ -768,7 +769,7 @@ async def test_enabling_remote_trusted_proxies_local6(
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == 500
assert response["error"]["code"] == HTTP_INTERNAL_SERVER_ERROR
assert (
response["error"]["message"]
== "Remote UI not compatible with 127.0.0.1/::1 as trusted proxies."
+3 -3
View File
@@ -1,7 +1,7 @@
"""Tests for the DirecTV component."""
from homeassistant.components.directv.const import CONF_RECEIVER_ID, DOMAIN
from homeassistant.components.ssdp import ATTR_SSDP_LOCATION
from homeassistant.const import CONF_HOST
from homeassistant.const import CONF_HOST, HTTP_INTERNAL_SERVER_ERROR
from homeassistant.helpers.typing import HomeAssistantType
from tests.common import MockConfigEntry, load_fixture
@@ -34,7 +34,7 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None:
aioclient_mock.get(
f"http://{HOST}:8080/info/mode",
params={"clientAddr": "9XXXXXXXXXX9"},
status=500,
status=HTTP_INTERNAL_SERVER_ERROR,
text=load_fixture("directv/info-mode-error.json"),
headers={"Content-Type": "application/json"},
)
@@ -80,7 +80,7 @@ async def setup_integration(
"""Set up the DirecTV integration in Home Assistant."""
if setup_error:
aioclient_mock.get(
f"http://{HOST}:8080/info/getVersion", status=500,
f"http://{HOST}:8080/info/getVersion", status=HTTP_INTERNAL_SERVER_ERROR
)
else:
mock_connection(aioclient_mock)
+2 -1
View File
@@ -12,6 +12,7 @@ from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_BILLION,
CONCENTRATION_PARTS_PER_MILLION,
HTTP_INTERNAL_SERVER_ERROR,
TEMP_CELSIUS,
UNIT_PERCENTAGE,
)
@@ -83,7 +84,7 @@ async def test_setup_temporary_error(hass, aioclient_mock):
"""Expected failures caused by temporary errors in API response."""
fake_async_add_entities = MagicMock()
errors = [429, 500]
errors = [429, HTTP_INTERNAL_SERVER_ERROR]
for error in errors:
aioclient_mock.get(re.compile("api.foobot.io/v2/owner/.*"), status=error)
with pytest.raises(PlatformNotReady):
+2 -1
View File
@@ -2,6 +2,7 @@
import asyncio
from unittest import mock
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.setup import async_setup_component
@@ -117,7 +118,7 @@ async def test_limit_refetch(aioclient_mock, hass, hass_client):
with mock.patch("async_timeout.timeout", side_effect=asyncio.TimeoutError()):
resp = await client.get("/api/camera_proxy/camera.config_test")
assert aioclient_mock.call_count == 0
assert resp.status == 500
assert resp.status == HTTP_INTERNAL_SERVER_ERROR
hass.states.async_set("sensor.temp", "10")
+2 -1
View File
@@ -1,6 +1,7 @@
"""The tests for the hassio component."""
from unittest.mock import Mock, patch
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.exceptions import HomeAssistantError
from tests.common import mock_coro
@@ -186,5 +187,5 @@ async def test_password_no_user(hass, hassio_client_supervisor):
)
# Check we got right response
assert resp.status == 500
assert resp.status == HTTP_INTERNAL_SERVER_ERROR
assert not mock_save.called
+4 -3
View File
@@ -5,6 +5,7 @@ from unittest.mock import MagicMock, mock_open, patch
from aiohttp.hdrs import AUTHORIZATION
import homeassistant.components.html5.notify as html5
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import async_setup_component
@@ -335,7 +336,7 @@ async def test_registering_new_device_fails_view(hass, hass_client):
):
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
assert resp.status == 500
assert resp.status == HTTP_INTERNAL_SERVER_ERROR
assert registrations == {}
@@ -380,7 +381,7 @@ async def test_registering_existing_device_fails_view(hass, hass_client):
mock_save.side_effect = HomeAssistantError
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
assert resp.status == 500
assert resp.status == HTTP_INTERNAL_SERVER_ERROR
assert registrations == {"unnamed device": SUBSCRIPTION_1}
@@ -451,7 +452,7 @@ async def test_unregistering_device_view_handles_save_error(hass, hass_client):
data=json.dumps({"subscription": SUBSCRIPTION_1["subscription"]}),
)
assert resp.status == 500, resp.response
assert resp.status == HTTP_INTERNAL_SERVER_ERROR, resp.response
assert registrations == {
"some device": SUBSCRIPTION_1,
"other device": SUBSCRIPTION_2,
+2 -1
View File
@@ -5,6 +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
@pytest.fixture
@@ -90,7 +91,7 @@ async def test_get_media_from_invalid_msgid(mock_http_client):
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
req = await mock_http_client.get(url)
assert req.status == 500
assert req.status == HTTP_INTERNAL_SERVER_ERROR
async def test_delete_from_invalid_mailbox(mock_http_client):
+2 -1
View File
@@ -11,6 +11,7 @@ from homeassistant.components.media_player.const import (
SERVICE_PLAY_MEDIA,
)
import homeassistant.components.tts as tts
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.setup import setup_component
from tests.common import assert_setup_component, get_test_home_assistant, mock_service
@@ -122,7 +123,7 @@ class TestTTSMaryTTSPlatform:
conn = Mock()
response = Mock()
conn.getresponse.return_value = response
response.status = 500
response.status = HTTP_INTERNAL_SERVER_ERROR
response.reason = "test"
response.readline.return_value = "content"
+10 -8
View File
@@ -8,6 +8,7 @@ import pytest
from homeassistant import config_entries
from homeassistant.components.melcloud.const import DOMAIN
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from tests.common import MockConfigEntry
@@ -50,7 +51,7 @@ async def test_form(hass, mock_login, mock_get_devices):
with patch(
"homeassistant.components.melcloud.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.melcloud.async_setup_entry", return_value=True,
"homeassistant.components.melcloud.async_setup_entry", return_value=True
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -89,7 +90,11 @@ async def test_form_errors(hass, mock_login, mock_get_devices, error, reason):
@pytest.mark.parametrize(
"error,message",
[(401, "invalid_auth"), (403, "invalid_auth"), (500, "cannot_connect")],
[
(401, "invalid_auth"),
(403, "invalid_auth"),
(HTTP_INTERNAL_SERVER_ERROR, "cannot_connect"),
],
)
async def test_form_response_errors(
hass, mock_login, mock_get_devices, mock_request_info, error, message
@@ -112,7 +117,7 @@ async def test_import_with_token(hass, mock_login, mock_get_devices):
with patch(
"homeassistant.components.melcloud.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.melcloud.async_setup_entry", return_value=True,
"homeassistant.components.melcloud.async_setup_entry", return_value=True
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -135,10 +140,7 @@ async def test_token_refresh(hass, mock_login, mock_get_devices):
"""Re-configuration with existing username should refresh token."""
mock_entry = MockConfigEntry(
domain=DOMAIN,
data={
"username": "test-email@test-domain.com",
"token": "test-original-token",
},
data={"username": "test-email@test-domain.com", "token": "test-original-token"},
unique_id="test-email@test-domain.com",
)
mock_entry.add_to_hass(hass)
@@ -146,7 +148,7 @@ async def test_token_refresh(hass, mock_login, mock_get_devices):
with patch(
"homeassistant.components.melcloud.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.melcloud.async_setup_entry", return_value=True,
"homeassistant.components.melcloud.async_setup_entry", return_value=True
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
+4 -4
View File
@@ -4,7 +4,7 @@ import requests
from homeassistant import config_entries, setup
from homeassistant.components.nuheat.const import CONF_SERIAL_NUMBER, DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, HTTP_INTERNAL_SERVER_ERROR
from .mocks import _get_mock_thermostat_run
@@ -29,7 +29,7 @@ async def test_form_user(hass):
), patch(
"homeassistant.components.nuheat.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.nuheat.async_setup_entry", return_value=True,
"homeassistant.components.nuheat.async_setup_entry", return_value=True
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -67,7 +67,7 @@ async def test_form_import(hass):
), patch(
"homeassistant.components.nuheat.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.nuheat.async_setup_entry", return_value=True,
"homeassistant.components.nuheat.async_setup_entry", return_value=True
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -139,7 +139,7 @@ async def test_form_invalid_thermostat(hass):
)
response_mock = MagicMock()
type(response_mock).status_code = 500
type(response_mock).status_code = HTTP_INTERNAL_SERVER_ERROR
with patch(
"homeassistant.components.nuheat.config_flow.nuheat.NuHeat.authenticate",
+4 -3
View File
@@ -4,6 +4,7 @@ import asyncio
import aiohttp
import homeassistant.components.rest.switch as rest
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.helpers.template import Template
from homeassistant.setup import setup_component
@@ -140,7 +141,7 @@ class TestRestSwitch:
def test_turn_on_status_not_ok(self, aioclient_mock):
"""Test turn_on when error status returned."""
aioclient_mock.post(self.resource, status=500)
aioclient_mock.post(self.resource, status=HTTP_INTERNAL_SERVER_ERROR)
asyncio.run_coroutine_threadsafe(
self.switch.async_turn_on(), self.hass.loop
).result()
@@ -150,7 +151,7 @@ class TestRestSwitch:
def test_turn_on_timeout(self, aioclient_mock):
"""Test turn_on when timeout occurs."""
aioclient_mock.post(self.resource, status=500)
aioclient_mock.post(self.resource, status=HTTP_INTERNAL_SERVER_ERROR)
asyncio.run_coroutine_threadsafe(
self.switch.async_turn_on(), self.hass.loop
).result()
@@ -169,7 +170,7 @@ class TestRestSwitch:
def test_turn_off_status_not_ok(self, aioclient_mock):
"""Test turn_off when error status returned."""
aioclient_mock.post(self.resource, status=500)
aioclient_mock.post(self.resource, status=HTTP_INTERNAL_SERVER_ERROR)
asyncio.run_coroutine_threadsafe(
self.switch.async_turn_off(), self.hass.loop
).result()
+5 -4
View File
@@ -17,6 +17,7 @@ from homeassistant.components.smartthings.const import (
SIGNAL_SMARTTHINGS_UPDATE,
SUPPORTED_PLATFORMS,
)
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.setup import async_setup_component
@@ -80,7 +81,7 @@ async def test_recoverable_api_errors_raise_not_ready(
config_entry.add_to_hass(hass)
request_info = Mock(real_url="http://example.com")
smartthings_mock.app.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
request_info=request_info, history=None, status=HTTP_INTERNAL_SERVER_ERROR
)
with pytest.raises(ConfigEntryNotReady):
@@ -96,7 +97,7 @@ async def test_scenes_api_errors_raise_not_ready(
smartthings_mock.app.return_value = app
smartthings_mock.installed_app.return_value = installed_app
smartthings_mock.scenes.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
request_info=request_info, history=None, status=HTTP_INTERNAL_SERVER_ERROR
)
with pytest.raises(ConfigEntryNotReady):
await smartthings.async_setup_entry(hass, config_entry)
@@ -325,7 +326,7 @@ async def test_remove_entry_installedapp_api_error(
request_info = Mock(real_url="http://example.com")
# Arrange
smartthings_mock.delete_installed_app.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
request_info=request_info, history=None, status=HTTP_INTERNAL_SERVER_ERROR
)
# Act
with pytest.raises(ClientResponseError):
@@ -354,7 +355,7 @@ async def test_remove_entry_app_api_error(hass, config_entry, smartthings_mock):
# Arrange
request_info = Mock(real_url="http://example.com")
smartthings_mock.delete_app.side_effect = ClientResponseError(
request_info=request_info, history=None, status=500
request_info=request_info, history=None, status=HTTP_INTERNAL_SERVER_ERROR
)
# Act
with pytest.raises(ClientResponseError):
+7 -2
View File
@@ -8,7 +8,12 @@ import requests_mock
from homeassistant.components.yessssms.const import CONF_PROVIDER
import homeassistant.components.yessssms.notify as yessssms
from homeassistant.const import CONF_PASSWORD, CONF_RECIPIENT, CONF_USERNAME
from homeassistant.const import (
CONF_PASSWORD,
CONF_RECIPIENT,
CONF_USERNAME,
HTTP_INTERNAL_SERVER_ERROR,
)
from homeassistant.setup import async_setup_component
@@ -318,7 +323,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
"POST",
# pylint: disable=protected-access
self.yessssms.yesss._websms_url,
status_code=500,
status_code=HTTP_INTERNAL_SERVER_ERROR,
)
message = "Testing YesssSMS platform :)"