From 6a7caad8dcd89a8488ec6243559aa98990e87398 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Wed, 23 Sep 2020 20:21:55 +0200 Subject: [PATCH] Use content type json constant (#40312) --- .../components/microsoft_face/__init__.py | 4 +- .../components/mobile_app/helpers.py | 6 +-- tests/components/adguard/test_config_flow.py | 9 +++-- tests/components/agent_dvr/__init__.py | 6 +-- .../components/agent_dvr/test_config_flow.py | 6 +-- tests/components/alexa/test_intent.py | 3 +- .../components/alexa/test_smart_home_http.py | 4 +- tests/components/atag/__init__.py | 8 ++-- tests/components/bsblan/__init__.py | 4 +- tests/components/bsblan/test_config_flow.py | 4 +- tests/components/cloud/test_client.py | 7 ++-- tests/components/deconz/test_config_flow.py | 38 +++++++++---------- tests/components/directv/__init__.py | 29 ++++++++------ tests/components/elgato/__init__.py | 10 ++--- tests/components/elgato/test_config_flow.py | 8 ++-- tests/components/emulated_hue/test_hue_api.py | 31 +++++++-------- tests/components/emulated_hue/test_upnp.py | 6 +-- tests/components/flo/conftest.py | 26 ++++++------- tests/components/flo/test_config_flow.py | 3 +- tests/components/rest/test_binary_sensor.py | 6 +-- tests/components/rest/test_sensor.py | 29 ++++++++------ tests/components/rest/test_switch.py | 4 +- tests/components/rest_command/test_init.py | 18 ++++----- tests/components/sonarr/__init__.py | 15 ++++---- .../twentemilieu/test_config_flow.py | 8 ++-- tests/components/unifi/test_config_flow.py | 13 ++++--- tests/components/wled/__init__.py | 10 ++--- tests/components/wled/test_config_flow.py | 8 ++-- 28 files changed, 170 insertions(+), 153 deletions(-) diff --git a/homeassistant/components/microsoft_face/__init__.py b/homeassistant/components/microsoft_face/__init__.py index 208cecf6d3b..69a738724c3 100644 --- a/homeassistant/components/microsoft_face/__init__.py +++ b/homeassistant/components/microsoft_face/__init__.py @@ -8,7 +8,7 @@ from aiohttp.hdrs import CONTENT_TYPE import async_timeout import voluptuous as vol -from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_TIMEOUT +from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_TIMEOUT, CONTENT_TYPE_JSON from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -290,7 +290,7 @@ class MicrosoftFace: headers[CONTENT_TYPE] = "application/octet-stream" payload = data else: - headers[CONTENT_TYPE] = "application/json" + headers[CONTENT_TYPE] = CONTENT_TYPE_JSON if data is not None: payload = json.dumps(data).encode() else: diff --git a/homeassistant/components/mobile_app/helpers.py b/homeassistant/components/mobile_app/helpers.py index b2cb3d22e4b..7c5cbd135ed 100644 --- a/homeassistant/components/mobile_app/helpers.py +++ b/homeassistant/components/mobile_app/helpers.py @@ -7,7 +7,7 @@ from aiohttp.web import Response, json_response from nacl.encoding import Base64Encoder from nacl.secret import SecretBox -from homeassistant.const import HTTP_BAD_REQUEST, HTTP_OK +from homeassistant.const import CONTENT_TYPE_JSON, HTTP_BAD_REQUEST, HTTP_OK from homeassistant.core import Context from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.typing import HomeAssistantType @@ -94,7 +94,7 @@ def registration_context(registration: Dict) -> Context: def empty_okay_response(headers: Dict = None, status: int = HTTP_OK) -> Response: """Return a Response with empty JSON object and a 200.""" return Response( - text="{}", status=status, content_type="application/json", headers=headers + text="{}", status=status, content_type=CONTENT_TYPE_JSON, headers=headers ) @@ -161,7 +161,7 @@ def webhook_response( data = json.dumps({"encrypted": True, "encrypted_data": enc_data}) return Response( - text=data, status=status, content_type="application/json", headers=headers + text=data, status=status, content_type=CONTENT_TYPE_JSON, headers=headers ) diff --git a/tests/components/adguard/test_config_flow.py b/tests/components/adguard/test_config_flow.py index dae9e0da79d..e773768ebe6 100644 --- a/tests/components/adguard/test_config_flow.py +++ b/tests/components/adguard/test_config_flow.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_SSL, CONF_USERNAME, CONF_VERIFY_SSL, + CONTENT_TYPE_JSON, ) from tests.async_mock import patch @@ -62,7 +63,7 @@ async def test_full_flow_implementation(hass, aioclient_mock): f"://{FIXTURE_USER_INPUT[CONF_HOST]}" f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status", json={"version": "v0.99.0"}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.AdGuardHomeFlowHandler() @@ -134,12 +135,12 @@ async def test_hassio_update_instance_running(hass, aioclient_mock): aioclient_mock.get( "http://mock-adguard-updated:3000/control/status", json={"version": "v0.99.0"}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://mock-adguard:3000/control/status", json={"version": "v0.99.0"}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( @@ -195,7 +196,7 @@ async def test_hassio_confirm(hass, aioclient_mock): aioclient_mock.get( "http://mock-adguard:3000/control/status", json={"version": "v0.99.0"}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/agent_dvr/__init__.py b/tests/components/agent_dvr/__init__.py index 2cda0b8aa73..ec35b521a17 100644 --- a/tests/components/agent_dvr/__init__.py +++ b/tests/components/agent_dvr/__init__.py @@ -1,7 +1,7 @@ """Tests for the agent_dvr component.""" from homeassistant.components.agent_dvr.const import DOMAIN, SERVER_URL -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry, load_fixture @@ -18,12 +18,12 @@ async def init_integration( aioclient_mock.get( "http://example.local:8090/command.cgi?cmd=getStatus", text=load_fixture("agent_dvr/status.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://example.local:8090/command.cgi?cmd=getObjects", text=load_fixture("agent_dvr/objects.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/agent_dvr/test_config_flow.py b/tests/components/agent_dvr/test_config_flow.py index 403dd9f4bee..064034a4a69 100644 --- a/tests/components/agent_dvr/test_config_flow.py +++ b/tests/components/agent_dvr/test_config_flow.py @@ -3,7 +3,7 @@ from homeassistant import data_entry_flow from homeassistant.components.agent_dvr import config_flow from homeassistant.components.agent_dvr.const import SERVER_URL from homeassistant.config_entries import SOURCE_USER -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from . import init_integration @@ -61,13 +61,13 @@ async def test_full_user_flow_implementation( aioclient_mock.get( "http://example.local:8090/command.cgi?cmd=getStatus", text=load_fixture("agent_dvr/status.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://example.local:8090/command.cgi?cmd=getObjects", text=load_fixture("agent_dvr/objects.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/alexa/test_intent.py b/tests/components/alexa/test_intent.py index 8937a7938ac..c838bf5b3a3 100644 --- a/tests/components/alexa/test_intent.py +++ b/tests/components/alexa/test_intent.py @@ -6,6 +6,7 @@ import pytest from homeassistant.components import alexa from homeassistant.components.alexa import intent +from homeassistant.const import CONTENT_TYPE_JSON from homeassistant.core import callback from homeassistant.setup import async_setup_component @@ -111,7 +112,7 @@ def _intent_req(client, data=None): return client.post( intent.INTENTS_API_ENDPOINT, data=json.dumps(data or {}), - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) diff --git a/tests/components/alexa/test_smart_home_http.py b/tests/components/alexa/test_smart_home_http.py index 46db47dc2c9..c46a61aef41 100644 --- a/tests/components/alexa/test_smart_home_http.py +++ b/tests/components/alexa/test_smart_home_http.py @@ -2,7 +2,7 @@ import json from homeassistant.components.alexa import DOMAIN, smart_home_http -from homeassistant.const import HTTP_NOT_FOUND +from homeassistant.const import CONTENT_TYPE_JSON, HTTP_NOT_FOUND from homeassistant.setup import async_setup_component from . import get_new_request @@ -17,7 +17,7 @@ async def do_http_discovery(config, hass, hass_client): response = await http_client.post( smart_home_http.SMART_HOME_HTTP_ENDPOINT, data=json.dumps(request), - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) return response diff --git a/tests/components/atag/__init__.py b/tests/components/atag/__init__.py index 3f2b6468491..11162f3d8a7 100644 --- a/tests/components/atag/__init__.py +++ b/tests/components/atag/__init__.py @@ -1,7 +1,7 @@ """Tests for the Atag integration.""" from homeassistant.components.atag import DOMAIN -from homeassistant.const import CONF_EMAIL, CONF_HOST, CONF_PORT +from homeassistant.const import CONF_EMAIL, CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -62,17 +62,17 @@ async def init_integration( aioclient_mock.get( "http://127.0.0.1:10000/retrieve", json=RECEIVE_REPLY, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.post( "http://127.0.0.1:10000/update", json=UPDATE_REPLY, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.post( "http://127.0.0.1:10000/pair", json=PAIR_REPLY, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT) diff --git a/tests/components/bsblan/__init__.py b/tests/components/bsblan/__init__.py index 45b0f16c0a1..511b566ce41 100644 --- a/tests/components/bsblan/__init__.py +++ b/tests/components/bsblan/__init__.py @@ -5,7 +5,7 @@ from homeassistant.components.bsblan.const import ( CONF_PASSKEY, DOMAIN, ) -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry, load_fixture @@ -23,7 +23,7 @@ async def init_integration( "http://example.local:80/1234/JQ?Parameter=6224,6225,6226", params={"Parameter": "6224,6225,6226"}, text=load_fixture("bsblan/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( diff --git a/tests/components/bsblan/test_config_flow.py b/tests/components/bsblan/test_config_flow.py index c24fbc34f6a..4c24e10a237 100644 --- a/tests/components/bsblan/test_config_flow.py +++ b/tests/components/bsblan/test_config_flow.py @@ -5,7 +5,7 @@ from homeassistant import data_entry_flow from homeassistant.components.bsblan import config_flow from homeassistant.components.bsblan.const import CONF_DEVICE_IDENT, CONF_PASSKEY from homeassistant.config_entries import SOURCE_USER -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from . import init_integration @@ -67,7 +67,7 @@ async def test_full_user_flow_implementation( aioclient_mock.post( "http://example.local:80/1234/JQ?Parameter=6224,6225,6226", text=load_fixture("bsblan/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/cloud/test_client.py b/tests/components/cloud/test_client.py index d0d9c4b25b7..aaabca71885 100644 --- a/tests/components/cloud/test_client.py +++ b/tests/components/cloud/test_client.py @@ -5,6 +5,7 @@ import pytest from homeassistant.components.cloud import DOMAIN from homeassistant.components.cloud.client import CloudClient from homeassistant.components.cloud.const import PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE +from homeassistant.const import CONTENT_TYPE_JSON from homeassistant.core import State from homeassistant.setup import async_setup_component @@ -175,7 +176,7 @@ async def test_webhook_msg(hass, caplog): { "cloudhook_id": "mock-cloud-id", "body": '{"hello": "world"}', - "headers": {"content-type": "application/json"}, + "headers": {"content-type": CONTENT_TYPE_JSON}, "method": "POST", "query": None, } @@ -184,7 +185,7 @@ async def test_webhook_msg(hass, caplog): assert response == { "status": 200, "body": '{"from": "handler"}', - "headers": {"Content-Type": "application/json"}, + "headers": {"Content-Type": CONTENT_TYPE_JSON}, } assert len(received) == 1 @@ -197,7 +198,7 @@ async def test_webhook_msg(hass, caplog): { "cloudhook_id": "mock-nonexisting-id", "body": '{"nonexisting": "payload"}', - "headers": {"content-type": "application/json"}, + "headers": {"content-type": CONTENT_TYPE_JSON}, "method": "POST", "query": None, } diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 43536a44bbe..092d59bec76 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -17,7 +17,7 @@ from homeassistant.components.deconz.const import ( CONF_MASTER_GATEWAY, DOMAIN, ) -from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT +from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from .test_gateway import API_KEY, BRIDGEID, setup_deconz_integration @@ -32,7 +32,7 @@ async def test_flow_discovered_bridges(hass, aioclient_mock): {"id": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80}, {"id": "1234E567890A", "internalipaddress": "5.6.7.8", "internalport": 80}, ], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -52,7 +52,7 @@ async def test_flow_discovered_bridges(hass, aioclient_mock): aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -73,7 +73,7 @@ async def test_flow_manual_configuration_decision(hass, aioclient_mock): aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[{"id": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -98,13 +98,13 @@ async def test_flow_manual_configuration_decision(hass, aioclient_mock): aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://1.2.3.4:80/api/{API_KEY}/config", json={"bridgeid": BRIDGEID}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -125,7 +125,7 @@ async def test_flow_manual_configuration(hass, aioclient_mock): aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -146,13 +146,13 @@ async def test_flow_manual_configuration(hass, aioclient_mock): aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://1.2.3.4:80/api/{API_KEY}/config", json={"bridgeid": BRIDGEID}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -201,7 +201,7 @@ async def test_manual_configuration_update_configuration(hass, aioclient_mock): aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -222,13 +222,13 @@ async def test_manual_configuration_update_configuration(hass, aioclient_mock): aioclient_mock.post( "http://2.3.4.5:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://2.3.4.5:80/api/{API_KEY}/config", json={"bridgeid": BRIDGEID}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -247,7 +247,7 @@ async def test_manual_configuration_dont_update_configuration(hass, aioclient_mo aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -268,13 +268,13 @@ async def test_manual_configuration_dont_update_configuration(hass, aioclient_mo aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://1.2.3.4:80/api/{API_KEY}/config", json={"bridgeid": BRIDGEID}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -290,7 +290,7 @@ async def test_manual_configuration_timeout_get_bridge(hass, aioclient_mock): aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -311,7 +311,7 @@ async def test_manual_configuration_timeout_get_bridge(hass, aioclient_mock): aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -331,7 +331,7 @@ async def test_link_get_api_key_ResponseError(hass, aioclient_mock): aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[{"id": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -374,7 +374,7 @@ async def test_flow_ssdp_discovery(hass, aioclient_mock): aioclient_mock.post( "http://1.2.3.4:80/api", json=[{"success": {"username": API_KEY}}], - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( diff --git a/tests/components/directv/__init__.py b/tests/components/directv/__init__.py index 6b71b1e8cfe..9f09c377bd4 100644 --- a/tests/components/directv/__init__.py +++ b/tests/components/directv/__init__.py @@ -1,7 +1,12 @@ """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, HTTP_FORBIDDEN, HTTP_INTERNAL_SERVER_ERROR +from homeassistant.const import ( + CONF_HOST, + CONTENT_TYPE_JSON, + HTTP_FORBIDDEN, + HTTP_INTERNAL_SERVER_ERROR, +) from homeassistant.helpers.typing import HomeAssistantType from tests.common import MockConfigEntry, load_fixture @@ -22,20 +27,20 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None: aioclient_mock.get( f"http://{HOST}:8080/info/getVersion", text=load_fixture("directv/info-get-version.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/info/getLocations", text=load_fixture("directv/info-get-locations.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/info/mode", params={"clientAddr": "B01234567890"}, text=load_fixture("directv/info-mode-standby.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -43,39 +48,39 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None: params={"clientAddr": "9XXXXXXXXXX9"}, status=HTTP_INTERNAL_SERVER_ERROR, text=load_fixture("directv/info-mode-error.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/info/mode", text=load_fixture("directv/info-mode.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/remote/processKey", text=load_fixture("directv/remote-process-key.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/tv/tune", text=load_fixture("directv/tv-tune.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/tv/getTuned", params={"clientAddr": "2CA17D1CD30X"}, text=load_fixture("directv/tv-get-tuned.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/tv/getTuned", params={"clientAddr": "A01234567890"}, text=load_fixture("directv/tv-get-tuned-music.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -83,13 +88,13 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None: params={"clientAddr": "C01234567890"}, status=HTTP_FORBIDDEN, text=load_fixture("directv/tv-get-tuned-restricted.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"http://{HOST}:8080/tv/getTuned", text=load_fixture("directv/tv-get-tuned-movie.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) diff --git a/tests/components/elgato/__init__.py b/tests/components/elgato/__init__.py index 5f0f2f5fb14..3b1942aee14 100644 --- a/tests/components/elgato/__init__.py +++ b/tests/components/elgato/__init__.py @@ -1,7 +1,7 @@ """Tests for the Elgato Key Light integration.""" from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER, DOMAIN -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry, load_fixture @@ -18,25 +18,25 @@ async def init_integration( aioclient_mock.get( "http://1.2.3.4:9123/elgato/accessory-info", text=load_fixture("elgato/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.put( "http://1.2.3.4:9123/elgato/lights", text=load_fixture("elgato/state.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://1.2.3.4:9123/elgato/lights", text=load_fixture("elgato/state.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://5.6.7.8:9123/elgato/accessory-info", text=load_fixture("elgato/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( diff --git a/tests/components/elgato/test_config_flow.py b/tests/components/elgato/test_config_flow.py index bd65811133a..e0d34aecad2 100644 --- a/tests/components/elgato/test_config_flow.py +++ b/tests/components/elgato/test_config_flow.py @@ -5,7 +5,7 @@ from homeassistant import data_entry_flow from homeassistant.components.elgato import config_flow from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF -from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_PORT, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from . import init_integration @@ -44,7 +44,7 @@ async def test_show_zerconf_form( aioclient_mock.get( "http://1.2.3.4:9123/elgato/accessory-info", text=load_fixture("elgato/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.ElgatoFlowHandler() @@ -176,7 +176,7 @@ async def test_full_user_flow_implementation( aioclient_mock.get( "http://1.2.3.4:9123/elgato/accessory-info", text=load_fixture("elgato/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -208,7 +208,7 @@ async def test_full_zeroconf_flow_implementation( aioclient_mock.get( "http://1.2.3.4:9123/elgato/accessory-info", text=load_fixture("elgato/info.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.ElgatoFlowHandler() diff --git a/tests/components/emulated_hue/test_hue_api.py b/tests/components/emulated_hue/test_hue_api.py index 0f61178107d..576a464c86a 100644 --- a/tests/components/emulated_hue/test_hue_api.py +++ b/tests/components/emulated_hue/test_hue_api.py @@ -38,6 +38,7 @@ from homeassistant.components.emulated_hue.hue_api import ( ) from homeassistant.const import ( ATTR_ENTITY_ID, + CONTENT_TYPE_JSON, HTTP_NOT_FOUND, HTTP_OK, HTTP_UNAUTHORIZED, @@ -245,7 +246,7 @@ async def test_discover_lights(hue_client): result = await hue_client.get("/api/username/lights") assert result.status == HTTP_OK - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] result_json = await result.json() @@ -342,7 +343,7 @@ async def test_light_without_brightness_can_be_turned_off(hass_hue, hue_client): no_brightness_result_json = await no_brightness_result.json() assert no_brightness_result.status == HTTP_OK - assert "application/json" in no_brightness_result.headers["content-type"] + assert CONTENT_TYPE_JSON in no_brightness_result.headers["content-type"] assert len(no_brightness_result_json) == 1 # Verify that SERVICE_TURN_OFF has been called @@ -384,7 +385,7 @@ async def test_light_without_brightness_can_be_turned_on(hass_hue, hue_client): no_brightness_result_json = await no_brightness_result.json() assert no_brightness_result.status == HTTP_OK - assert "application/json" in no_brightness_result.headers["content-type"] + assert CONTENT_TYPE_JSON in no_brightness_result.headers["content-type"] assert len(no_brightness_result_json) == 1 # Verify that SERVICE_TURN_ON has been called @@ -421,7 +422,7 @@ async def test_discover_full_state(hue_client): result = await hue_client.get(f"/api/{HUE_API_USERNAME}") assert result.status == HTTP_OK - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] result_json = await result.json() @@ -471,7 +472,7 @@ async def test_discover_config(hue_client): result = await hue_client.get(f"/api/{HUE_API_USERNAME}/config") assert result.status == 200 - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] config_json = await result.json() @@ -508,7 +509,7 @@ async def test_discover_config(hue_client): result = await hue_client.get("/api/config") assert result.status == 200 - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] config_json = await result.json() assert "error" not in config_json @@ -517,7 +518,7 @@ async def test_discover_config(hue_client): result = await hue_client.get("/api/wronguser/config") assert result.status == 200 - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] config_json = await result.json() assert "error" not in config_json @@ -550,7 +551,7 @@ async def test_get_light_state(hass_hue, hue_client): result = await hue_client.get("/api/username/lights") assert result.status == HTTP_OK - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] result_json = await result.json() @@ -667,7 +668,7 @@ async def test_put_light_state(hass, hass_hue, hue_client): ceiling_result_json = await ceiling_result.json() assert ceiling_result.status == HTTP_OK - assert "application/json" in ceiling_result.headers["content-type"] + assert CONTENT_TYPE_JSON in ceiling_result.headers["content-type"] assert len(ceiling_result_json) == 1 @@ -857,7 +858,7 @@ async def test_close_cover(hass_hue, hue_client): ) assert cover_result.status == HTTP_OK - assert "application/json" in cover_result.headers["content-type"] + assert CONTENT_TYPE_JSON in cover_result.headers["content-type"] for _ in range(7): future = dt_util.utcnow() + timedelta(seconds=1) @@ -905,7 +906,7 @@ async def test_set_position_cover(hass_hue, hue_client): ) assert cover_result.status == HTTP_OK - assert "application/json" in cover_result.headers["content-type"] + assert CONTENT_TYPE_JSON in cover_result.headers["content-type"] cover_result_json = await cover_result.json() @@ -1104,7 +1105,7 @@ async def test_get_empty_groups_state(hue_client): # pylint: disable=invalid-name async def perform_put_test_on_ceiling_lights( - hass_hue, hue_client, content_type="application/json" + hass_hue, hue_client, content_type=CONTENT_TYPE_JSON ): """Test the setting of a light.""" # Turn the office light off first @@ -1124,7 +1125,7 @@ async def perform_put_test_on_ceiling_lights( ) assert office_result.status == HTTP_OK - assert "application/json" in office_result.headers["content-type"] + assert CONTENT_TYPE_JSON in office_result.headers["content-type"] office_result_json = await office_result.json() @@ -1143,7 +1144,7 @@ async def perform_get_light_state_by_number(client, entity_number, expected_stat assert result.status == expected_status if expected_status == HTTP_OK: - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] return await result.json() @@ -1164,7 +1165,7 @@ async def perform_put_light_state( entity_id, is_on, brightness=None, - content_type="application/json", + content_type=CONTENT_TYPE_JSON, hue=None, saturation=None, color_temp=None, diff --git a/tests/components/emulated_hue/test_upnp.py b/tests/components/emulated_hue/test_upnp.py index 8a5556b1222..e68688399e0 100644 --- a/tests/components/emulated_hue/test_upnp.py +++ b/tests/components/emulated_hue/test_upnp.py @@ -9,7 +9,7 @@ import requests from homeassistant import const, setup from homeassistant.components import emulated_hue from homeassistant.components.emulated_hue import upnp -from homeassistant.const import HTTP_OK +from homeassistant.const import CONTENT_TYPE_JSON, HTTP_OK from tests.common import get_test_home_assistant, get_test_instance_port @@ -167,7 +167,7 @@ MX:3 ) assert result.status_code == HTTP_OK - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] resp_json = result.json() success_json = resp_json[0] @@ -186,7 +186,7 @@ MX:3 ) assert result.status_code == HTTP_OK - assert "application/json" in result.headers["content-type"] + assert CONTENT_TYPE_JSON in result.headers["content-type"] resp_json = result.json() assert len(resp_json) == 1 diff --git a/tests/components/flo/conftest.py b/tests/components/flo/conftest.py index 3a835cb0547..907feb85569 100644 --- a/tests/components/flo/conftest.py +++ b/tests/components/flo/conftest.py @@ -5,7 +5,7 @@ import time import pytest from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN -from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONTENT_TYPE_JSON from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID @@ -40,7 +40,7 @@ def aioclient_mock_fixture(aioclient_mock): "timeNow": now, } ), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, status=200, ) # Mocks the device for flo. @@ -48,28 +48,28 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/devices/98765", text=load_fixture("flo/device_info_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) # Mocks the water consumption for flo. aioclient_mock.get( "https://api-gw.meetflo.com/api/v2/water/consumption", text=load_fixture("flo/water_consumption_info_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) # Mocks the location info for flo. aioclient_mock.get( "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp", text=load_fixture("flo/location_info_expand_devices_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) # Mocks the user info for flo. aioclient_mock.get( "https://api-gw.meetflo.com/api/v2/users/12345abcde", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, params={"expand": "locations"}, ) # Mocks the user info for flo. @@ -77,14 +77,14 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/users/12345abcde", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) # Mocks the valve open call for flo. aioclient_mock.post( "https://api-gw.meetflo.com/api/v2/devices/98765", text=load_fixture("flo/device_info_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, json={"valve": {"target": "open"}}, ) # Mocks the valve close call for flo. @@ -92,7 +92,7 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/devices/98765", text=load_fixture("flo/device_info_response_closed.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, json={"valve": {"target": "closed"}}, ) # Mocks the health test call for flo. @@ -100,14 +100,14 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/devices/98765/healthTest/run", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) # Mocks the health test call for flo. aioclient_mock.post( "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, json={"systemMode": {"target": "home"}}, ) # Mocks the health test call for flo. @@ -115,7 +115,7 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, json={"systemMode": {"target": "away"}}, ) # Mocks the health test call for flo. @@ -123,7 +123,7 @@ def aioclient_mock_fixture(aioclient_mock): "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode", text=load_fixture("flo/user_info_expand_locations_response.json"), status=200, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, json={ "systemMode": { "target": "sleep", diff --git a/tests/components/flo/test_config_flow.py b/tests/components/flo/test_config_flow.py index 265f2ae2d38..edc9705b7cd 100644 --- a/tests/components/flo/test_config_flow.py +++ b/tests/components/flo/test_config_flow.py @@ -4,6 +4,7 @@ import time from homeassistant import config_entries, setup from homeassistant.components.flo.const import DOMAIN +from homeassistant.const import CONTENT_TYPE_JSON from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID @@ -53,7 +54,7 @@ async def test_form_cannot_connect(hass, aioclient_mock): "timeNow": now, } ), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, status=400, ) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/rest/test_binary_sensor.py b/tests/components/rest/test_binary_sensor.py index e56342d861f..b18d8f300cf 100644 --- a/tests/components/rest/test_binary_sensor.py +++ b/tests/components/rest/test_binary_sensor.py @@ -9,7 +9,7 @@ import requests_mock import homeassistant.components.binary_sensor as binary_sensor import homeassistant.components.rest.binary_sensor as rest -from homeassistant.const import STATE_OFF, STATE_ON +from homeassistant.const import CONTENT_TYPE_JSON, STATE_OFF, STATE_ON from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers import template from homeassistant.setup import setup_component @@ -143,7 +143,7 @@ class TestRestBinarySensorSetup(unittest.TestCase): "authentication": "basic", "username": "my username", "password": "my password", - "headers": {"Accept": "application/json"}, + "headers": {"Accept": CONTENT_TYPE_JSON}, } }, ) @@ -170,7 +170,7 @@ class TestRestBinarySensorSetup(unittest.TestCase): "authentication": "basic", "username": "my username", "password": "my password", - "headers": {"Accept": "application/json"}, + "headers": {"Accept": CONTENT_TYPE_JSON}, } }, ) diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index 7fbb211fb4f..5ffa12c6167 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -12,7 +12,12 @@ import requests_mock from homeassistant import config as hass_config import homeassistant.components.rest.sensor as rest import homeassistant.components.sensor as sensor -from homeassistant.const import CONTENT_TYPE_TEXT_PLAIN, DATA_MEGABYTES, SERVICE_RELOAD +from homeassistant.const import ( + CONTENT_TYPE_JSON, + CONTENT_TYPE_TEXT_PLAIN, + DATA_MEGABYTES, + SERVICE_RELOAD, +) from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.config_validation import template from homeassistant.setup import async_setup_component, setup_component @@ -135,7 +140,7 @@ class TestRestSensorSetup(unittest.TestCase): "authentication": "basic", "username": "my username", "password": "my password", - "headers": {"Accept": "application/json"}, + "headers": {"Accept": CONTENT_TYPE_JSON}, } }, ) @@ -164,7 +169,7 @@ class TestRestSensorSetup(unittest.TestCase): "authentication": "basic", "username": "my username", "password": "my password", - "headers": {"Accept": "application/json"}, + "headers": {"Accept": CONTENT_TYPE_JSON}, } }, ) @@ -212,7 +217,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '{ "key": "' + self.initial_state + '" }', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.name = "foo" @@ -276,7 +281,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '{ "key": "updated_state" }', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor.update() @@ -288,7 +293,7 @@ class TestRestSensor(unittest.TestCase): self.rest.update = Mock( "rest.RestData.update", side_effect=self.update_side_effect( - "plain_state", CaseInsensitiveDict({"Content-Type": "application/json"}) + "plain_state", CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}) ), ) self.sensor = rest.RestSensor( @@ -313,7 +318,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '{ "key": "some_json_value" }', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor = rest.RestSensor( @@ -337,7 +342,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '[{ "key": "another_value" }]', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor = rest.RestSensor( @@ -361,7 +366,7 @@ class TestRestSensor(unittest.TestCase): self.rest.update = Mock( "rest.RestData.update", side_effect=self.update_side_effect( - None, CaseInsensitiveDict({"Content-Type": "application/json"}) + None, CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}) ), ) self.sensor = rest.RestSensor( @@ -387,7 +392,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '["list", "of", "things"]', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor = rest.RestSensor( @@ -439,7 +444,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '{ "key": "json_state_updated_value" }', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor = rest.RestSensor( @@ -471,7 +476,7 @@ class TestRestSensor(unittest.TestCase): "rest.RestData.update", side_effect=self.update_side_effect( '{ "toplevel": {"master_value": "master", "second_level": {"some_json_key": "some_json_value", "some_json_key2": "some_json_value2" } } }', - CaseInsensitiveDict({"Content-Type": "application/json"}), + CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}), ), ) self.sensor = rest.RestSensor( diff --git a/tests/components/rest/test_switch.py b/tests/components/rest/test_switch.py index 065645fffd1..47eec8e700f 100644 --- a/tests/components/rest/test_switch.py +++ b/tests/components/rest/test_switch.py @@ -123,7 +123,7 @@ class TestRestSwitchSetup: CONF_NAME: "foo", CONF_RESOURCE: "http://localhost", rest.CONF_STATE_RESOURCE: "http://localhost/state", - CONF_HEADERS: {"Content-type": "application/json"}, + CONF_HEADERS: {"Content-type": CONTENT_TYPE_JSON}, rest.CONF_BODY_ON: "custom on text", rest.CONF_BODY_OFF: "custom off text", } @@ -143,7 +143,7 @@ class TestRestSwitch: self.method = "post" self.resource = "http://localhost/" self.state_resource = self.resource - self.headers = {"Content-type": "application/json"} + self.headers = {"Content-type": CONTENT_TYPE_JSON} self.auth = None self.body_on = Template("on", self.hass) self.body_off = Template("off", self.hass) diff --git a/tests/components/rest_command/test_init.py b/tests/components/rest_command/test_init.py index 780e513ea38..80ede61be84 100644 --- a/tests/components/rest_command/test_init.py +++ b/tests/components/rest_command/test_init.py @@ -4,7 +4,7 @@ import asyncio import aiohttp import homeassistant.components.rest_command as rc -from homeassistant.const import CONTENT_TYPE_TEXT_PLAIN +from homeassistant.const import CONTENT_TYPE_JSON, CONTENT_TYPE_TEXT_PLAIN from homeassistant.setup import setup_component from tests.common import assert_setup_component, get_test_home_assistant @@ -222,24 +222,24 @@ class TestRestCommandComponent: "content_type_test": {"content_type": CONTENT_TYPE_TEXT_PLAIN}, "headers_test": { "headers": { - "Accept": "application/json", + "Accept": CONTENT_TYPE_JSON, "User-Agent": "Mozilla/5.0", } }, "headers_and_content_type_test": { - "headers": {"Accept": "application/json"}, + "headers": {"Accept": CONTENT_TYPE_JSON}, "content_type": CONTENT_TYPE_TEXT_PLAIN, }, "headers_and_content_type_override_test": { "headers": { - "Accept": "application/json", + "Accept": CONTENT_TYPE_JSON, aiohttp.hdrs.CONTENT_TYPE: "application/pdf", }, "content_type": CONTENT_TYPE_TEXT_PLAIN, }, "headers_template_test": { "headers": { - "Accept": "application/json", + "Accept": CONTENT_TYPE_JSON, "User-Agent": "Mozilla/{{ 3 + 2 }}.0", } }, @@ -291,7 +291,7 @@ class TestRestCommandComponent: # headers_test assert len(aioclient_mock.mock_calls[2][3]) == 2 - assert aioclient_mock.mock_calls[2][3].get("Accept") == "application/json" + assert aioclient_mock.mock_calls[2][3].get("Accept") == CONTENT_TYPE_JSON assert aioclient_mock.mock_calls[2][3].get("User-Agent") == "Mozilla/5.0" # headers_and_content_type_test @@ -300,7 +300,7 @@ class TestRestCommandComponent: aioclient_mock.mock_calls[3][3].get(aiohttp.hdrs.CONTENT_TYPE) == CONTENT_TYPE_TEXT_PLAIN ) - assert aioclient_mock.mock_calls[3][3].get("Accept") == "application/json" + assert aioclient_mock.mock_calls[3][3].get("Accept") == CONTENT_TYPE_JSON # headers_and_content_type_override_test assert len(aioclient_mock.mock_calls[4][3]) == 2 @@ -308,11 +308,11 @@ class TestRestCommandComponent: aioclient_mock.mock_calls[4][3].get(aiohttp.hdrs.CONTENT_TYPE) == CONTENT_TYPE_TEXT_PLAIN ) - assert aioclient_mock.mock_calls[4][3].get("Accept") == "application/json" + assert aioclient_mock.mock_calls[4][3].get("Accept") == CONTENT_TYPE_JSON # headers_template_test assert len(aioclient_mock.mock_calls[5][3]) == 2 - assert aioclient_mock.mock_calls[5][3].get("Accept") == "application/json" + assert aioclient_mock.mock_calls[5][3].get("Accept") == CONTENT_TYPE_JSON assert aioclient_mock.mock_calls[5][3].get("User-Agent") == "Mozilla/5.0" # headers_and_content_type_override_template_test diff --git a/tests/components/sonarr/__init__.py b/tests/components/sonarr/__init__.py index b076f39d0d2..0ce08e0c868 100644 --- a/tests/components/sonarr/__init__.py +++ b/tests/components/sonarr/__init__.py @@ -15,6 +15,7 @@ from homeassistant.const import ( CONF_PORT, CONF_SSL, CONF_VERIFY_SSL, + CONTENT_TYPE_JSON, ) from homeassistant.helpers.typing import HomeAssistantType @@ -85,43 +86,43 @@ def mock_connection( aioclient_mock.get( f"{sonarr_url}/system/status", text=load_fixture("sonarr/system-status.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/diskspace", text=load_fixture("sonarr/diskspace.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/calendar", text=load_fixture("sonarr/calendar.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/command", text=load_fixture("sonarr/command.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/queue", text=load_fixture("sonarr/queue.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/series", text=load_fixture("sonarr/series.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( f"{sonarr_url}/wanted/missing", text=load_fixture("sonarr/wanted-missing.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) diff --git a/tests/components/twentemilieu/test_config_flow.py b/tests/components/twentemilieu/test_config_flow.py index 7dd19e755f3..d176c6b1ee4 100644 --- a/tests/components/twentemilieu/test_config_flow.py +++ b/tests/components/twentemilieu/test_config_flow.py @@ -9,7 +9,7 @@ from homeassistant.components.twentemilieu.const import ( CONF_POST_CODE, DOMAIN, ) -from homeassistant.const import CONF_ID +from homeassistant.const import CONF_ID, CONTENT_TYPE_JSON from tests.common import MockConfigEntry @@ -51,7 +51,7 @@ async def test_invalid_address(hass, aioclient_mock): aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": []}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.TwenteMilieuFlowHandler() @@ -72,7 +72,7 @@ async def test_address_already_set_up(hass, aioclient_mock): aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": [{"UniqueId": "12345"}]}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.TwenteMilieuFlowHandler() @@ -88,7 +88,7 @@ async def test_full_flow_implementation(hass, aioclient_mock): aioclient_mock.post( "https://twentemilieuapi.ximmio.com/api/FetchAdress", json={"dataList": [{"UniqueId": "12345"}]}, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.TwenteMilieuFlowHandler() diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index aec6ebed664..8b935d7744b 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -23,6 +23,7 @@ from homeassistant.const import ( CONF_PORT, CONF_USERNAME, CONF_VERIFY_SSL, + CONTENT_TYPE_JSON, ) from .test_controller import setup_unifi_integration @@ -94,7 +95,7 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery): aioclient_mock.post( "https://1.2.3.4:1234/api/login", json={"data": "login successful", "meta": {"rc": "ok"}}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -103,7 +104,7 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery): "data": [{"desc": "Site name", "name": "site_id", "role": "admin"}], "meta": {"rc": "ok"}, }, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -145,7 +146,7 @@ async def test_flow_works_multiple_sites(hass, aioclient_mock): aioclient_mock.post( "https://1.2.3.4:1234/api/login", json={"data": "login successful", "meta": {"rc": "ok"}}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -157,7 +158,7 @@ async def test_flow_works_multiple_sites(hass, aioclient_mock): ], "meta": {"rc": "ok"}, }, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( @@ -196,7 +197,7 @@ async def test_flow_fails_site_already_configured(hass, aioclient_mock): aioclient_mock.post( "https://1.2.3.4:1234/api/login", json={"data": "login successful", "meta": {"rc": "ok"}}, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( @@ -205,7 +206,7 @@ async def test_flow_fails_site_already_configured(hass, aioclient_mock): "data": [{"desc": "Site name", "name": "site_id", "role": "admin"}], "meta": {"rc": "ok"}, }, - headers={"content-type": "application/json"}, + headers={"content-type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_configure( diff --git a/tests/components/wled/__init__.py b/tests/components/wled/__init__.py index 487ccd9ab9e..a39d1ef6453 100644 --- a/tests/components/wled/__init__.py +++ b/tests/components/wled/__init__.py @@ -3,7 +3,7 @@ import json from homeassistant.components.wled.const import DOMAIN -from homeassistant.const import CONF_HOST, CONF_MAC +from homeassistant.const import CONF_HOST, CONF_MAC, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry, load_fixture @@ -24,25 +24,25 @@ async def init_integration( aioclient_mock.get( "http://192.168.1.123:80/json/", json=data, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.post( "http://192.168.1.123:80/json/state", json=data["state"], - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://192.168.1.123:80/json/info", json=data["info"], - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) aioclient_mock.get( "http://192.168.1.123:80/json/state", json=data["state"], - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) entry = MockConfigEntry( diff --git a/tests/components/wled/test_config_flow.py b/tests/components/wled/test_config_flow.py index a0c5c11e7ce..7793dc2a378 100644 --- a/tests/components/wled/test_config_flow.py +++ b/tests/components/wled/test_config_flow.py @@ -5,7 +5,7 @@ from wled import WLEDConnectionError from homeassistant import data_entry_flow from homeassistant.components.wled import config_flow from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF -from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONTENT_TYPE_JSON from homeassistant.core import HomeAssistant from . import init_integration @@ -45,7 +45,7 @@ async def test_show_zerconf_form( aioclient_mock.get( "http://192.168.1.123:80/json/", text=load_fixture("wled/rgb.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.WLEDFlowHandler() @@ -190,7 +190,7 @@ async def test_full_user_flow_implementation( aioclient_mock.get( "http://192.168.1.123:80/json/", text=load_fixture("wled/rgb.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) result = await hass.config_entries.flow.async_init( @@ -218,7 +218,7 @@ async def test_full_zeroconf_flow_implementation( aioclient_mock.get( "http://192.168.1.123:80/json/", text=load_fixture("wled/rgb.json"), - headers={"Content-Type": "application/json"}, + headers={"Content-Type": CONTENT_TYPE_JSON}, ) flow = config_flow.WLEDFlowHandler()