Use content type json constant (#40312)

This commit is contained in:
springstan 2020-09-23 20:21:55 +02:00 committed by GitHub
parent 9c1eb78a0f
commit 6a7caad8dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 170 additions and 153 deletions

View file

@ -8,7 +8,7 @@ from aiohttp.hdrs import CONTENT_TYPE
import async_timeout import async_timeout
import voluptuous as vol 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.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -290,7 +290,7 @@ class MicrosoftFace:
headers[CONTENT_TYPE] = "application/octet-stream" headers[CONTENT_TYPE] = "application/octet-stream"
payload = data payload = data
else: else:
headers[CONTENT_TYPE] = "application/json" headers[CONTENT_TYPE] = CONTENT_TYPE_JSON
if data is not None: if data is not None:
payload = json.dumps(data).encode() payload = json.dumps(data).encode()
else: else:

View file

@ -7,7 +7,7 @@ from aiohttp.web import Response, json_response
from nacl.encoding import Base64Encoder from nacl.encoding import Base64Encoder
from nacl.secret import SecretBox 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.core import Context
from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.json import JSONEncoder
from homeassistant.helpers.typing import HomeAssistantType 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: def empty_okay_response(headers: Dict = None, status: int = HTTP_OK) -> Response:
"""Return a Response with empty JSON object and a 200.""" """Return a Response with empty JSON object and a 200."""
return Response( 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}) data = json.dumps({"encrypted": True, "encrypted_data": enc_data})
return Response( return Response(
text=data, status=status, content_type="application/json", headers=headers text=data, status=status, content_type=CONTENT_TYPE_JSON, headers=headers
) )

View file

@ -12,6 +12,7 @@ from homeassistant.const import (
CONF_SSL, CONF_SSL,
CONF_USERNAME, CONF_USERNAME,
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
CONTENT_TYPE_JSON,
) )
from tests.async_mock import patch 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_HOST]}"
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status", f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
json={"version": "v0.99.0"}, json={"version": "v0.99.0"},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.AdGuardHomeFlowHandler() flow = config_flow.AdGuardHomeFlowHandler()
@ -134,12 +135,12 @@ async def test_hassio_update_instance_running(hass, aioclient_mock):
aioclient_mock.get( aioclient_mock.get(
"http://mock-adguard-updated:3000/control/status", "http://mock-adguard-updated:3000/control/status",
json={"version": "v0.99.0"}, json={"version": "v0.99.0"},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://mock-adguard:3000/control/status", "http://mock-adguard:3000/control/status",
json={"version": "v0.99.0"}, json={"version": "v0.99.0"},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry( entry = MockConfigEntry(
@ -195,7 +196,7 @@ async def test_hassio_confirm(hass, aioclient_mock):
aioclient_mock.get( aioclient_mock.get(
"http://mock-adguard:3000/control/status", "http://mock-adguard:3000/control/status",
json={"version": "v0.99.0"}, json={"version": "v0.99.0"},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(

View file

@ -1,7 +1,7 @@
"""Tests for the agent_dvr component.""" """Tests for the agent_dvr component."""
from homeassistant.components.agent_dvr.const import DOMAIN, SERVER_URL 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 homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@ -18,12 +18,12 @@ async def init_integration(
aioclient_mock.get( aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getStatus", "http://example.local:8090/command.cgi?cmd=getStatus",
text=load_fixture("agent_dvr/status.json"), text=load_fixture("agent_dvr/status.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getObjects", "http://example.local:8090/command.cgi?cmd=getObjects",
text=load_fixture("agent_dvr/objects.json"), text=load_fixture("agent_dvr/objects.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -3,7 +3,7 @@ from homeassistant import data_entry_flow
from homeassistant.components.agent_dvr import config_flow from homeassistant.components.agent_dvr import config_flow
from homeassistant.components.agent_dvr.const import SERVER_URL from homeassistant.components.agent_dvr.const import SERVER_URL
from homeassistant.config_entries import SOURCE_USER 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 homeassistant.core import HomeAssistant
from . import init_integration from . import init_integration
@ -61,13 +61,13 @@ async def test_full_user_flow_implementation(
aioclient_mock.get( aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getStatus", "http://example.local:8090/command.cgi?cmd=getStatus",
text=load_fixture("agent_dvr/status.json"), text=load_fixture("agent_dvr/status.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getObjects", "http://example.local:8090/command.cgi?cmd=getObjects",
text=load_fixture("agent_dvr/objects.json"), 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( result = await hass.config_entries.flow.async_init(

View file

@ -6,6 +6,7 @@ import pytest
from homeassistant.components import alexa from homeassistant.components import alexa
from homeassistant.components.alexa import intent from homeassistant.components.alexa import intent
from homeassistant.const import CONTENT_TYPE_JSON
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -111,7 +112,7 @@ def _intent_req(client, data=None):
return client.post( return client.post(
intent.INTENTS_API_ENDPOINT, intent.INTENTS_API_ENDPOINT,
data=json.dumps(data or {}), data=json.dumps(data or {}),
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )

View file

@ -2,7 +2,7 @@
import json import json
from homeassistant.components.alexa import DOMAIN, smart_home_http 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 homeassistant.setup import async_setup_component
from . import get_new_request from . import get_new_request
@ -17,7 +17,7 @@ async def do_http_discovery(config, hass, hass_client):
response = await http_client.post( response = await http_client.post(
smart_home_http.SMART_HOME_HTTP_ENDPOINT, smart_home_http.SMART_HOME_HTTP_ENDPOINT,
data=json.dumps(request), data=json.dumps(request),
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
return response return response

View file

@ -1,7 +1,7 @@
"""Tests for the Atag integration.""" """Tests for the Atag integration."""
from homeassistant.components.atag import DOMAIN 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 homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -62,17 +62,17 @@ async def init_integration(
aioclient_mock.get( aioclient_mock.get(
"http://127.0.0.1:10000/retrieve", "http://127.0.0.1:10000/retrieve",
json=RECEIVE_REPLY, json=RECEIVE_REPLY,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.post( aioclient_mock.post(
"http://127.0.0.1:10000/update", "http://127.0.0.1:10000/update",
json=UPDATE_REPLY, json=UPDATE_REPLY,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.post( aioclient_mock.post(
"http://127.0.0.1:10000/pair", "http://127.0.0.1:10000/pair",
json=PAIR_REPLY, json=PAIR_REPLY,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT) entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT)

View file

@ -5,7 +5,7 @@ from homeassistant.components.bsblan.const import (
CONF_PASSKEY, CONF_PASSKEY,
DOMAIN, 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 homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture 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", "http://example.local:80/1234/JQ?Parameter=6224,6225,6226",
params={"Parameter": "6224,6225,6226"}, params={"Parameter": "6224,6225,6226"},
text=load_fixture("bsblan/info.json"), text=load_fixture("bsblan/info.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry( entry = MockConfigEntry(

View file

@ -5,7 +5,7 @@ from homeassistant import data_entry_flow
from homeassistant.components.bsblan import config_flow from homeassistant.components.bsblan import config_flow
from homeassistant.components.bsblan.const import CONF_DEVICE_IDENT, CONF_PASSKEY from homeassistant.components.bsblan.const import CONF_DEVICE_IDENT, CONF_PASSKEY
from homeassistant.config_entries import SOURCE_USER 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 homeassistant.core import HomeAssistant
from . import init_integration from . import init_integration
@ -67,7 +67,7 @@ async def test_full_user_flow_implementation(
aioclient_mock.post( aioclient_mock.post(
"http://example.local:80/1234/JQ?Parameter=6224,6225,6226", "http://example.local:80/1234/JQ?Parameter=6224,6225,6226",
text=load_fixture("bsblan/info.json"), 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( result = await hass.config_entries.flow.async_init(

View file

@ -5,6 +5,7 @@ import pytest
from homeassistant.components.cloud import DOMAIN from homeassistant.components.cloud import DOMAIN
from homeassistant.components.cloud.client import CloudClient from homeassistant.components.cloud.client import CloudClient
from homeassistant.components.cloud.const import PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE 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.core import State
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -175,7 +176,7 @@ async def test_webhook_msg(hass, caplog):
{ {
"cloudhook_id": "mock-cloud-id", "cloudhook_id": "mock-cloud-id",
"body": '{"hello": "world"}', "body": '{"hello": "world"}',
"headers": {"content-type": "application/json"}, "headers": {"content-type": CONTENT_TYPE_JSON},
"method": "POST", "method": "POST",
"query": None, "query": None,
} }
@ -184,7 +185,7 @@ async def test_webhook_msg(hass, caplog):
assert response == { assert response == {
"status": 200, "status": 200,
"body": '{"from": "handler"}', "body": '{"from": "handler"}',
"headers": {"Content-Type": "application/json"}, "headers": {"Content-Type": CONTENT_TYPE_JSON},
} }
assert len(received) == 1 assert len(received) == 1
@ -197,7 +198,7 @@ async def test_webhook_msg(hass, caplog):
{ {
"cloudhook_id": "mock-nonexisting-id", "cloudhook_id": "mock-nonexisting-id",
"body": '{"nonexisting": "payload"}', "body": '{"nonexisting": "payload"}',
"headers": {"content-type": "application/json"}, "headers": {"content-type": CONTENT_TYPE_JSON},
"method": "POST", "method": "POST",
"query": None, "query": None,
} }

View file

@ -17,7 +17,7 @@ from homeassistant.components.deconz.const import (
CONF_MASTER_GATEWAY, CONF_MASTER_GATEWAY,
DOMAIN, 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 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": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80},
{"id": "1234E567890A", "internalipaddress": "5.6.7.8", "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( result = await hass.config_entries.flow.async_init(
@ -52,7 +52,7 @@ async def test_flow_discovered_bridges(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[{"id": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80}], 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( 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( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://1.2.3.4:80/api/{API_KEY}/config", f"http://1.2.3.4:80/api/{API_KEY}/config",
json={"bridgeid": BRIDGEID}, json={"bridgeid": BRIDGEID},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
@ -125,7 +125,7 @@ async def test_flow_manual_configuration(hass, aioclient_mock):
aioclient_mock.get( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[], json=[],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -146,13 +146,13 @@ async def test_flow_manual_configuration(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://1.2.3.4:80/api/{API_KEY}/config", f"http://1.2.3.4:80/api/{API_KEY}/config",
json={"bridgeid": BRIDGEID}, json={"bridgeid": BRIDGEID},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[], json=[],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_init( 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( aioclient_mock.post(
"http://2.3.4.5:80/api", "http://2.3.4.5:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://2.3.4.5:80/api/{API_KEY}/config", f"http://2.3.4.5:80/api/{API_KEY}/config",
json={"bridgeid": BRIDGEID}, json={"bridgeid": BRIDGEID},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[], json=[],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_init( 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( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://1.2.3.4:80/api/{API_KEY}/config", f"http://1.2.3.4:80/api/{API_KEY}/config",
json={"bridgeid": BRIDGEID}, json={"bridgeid": BRIDGEID},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[], json=[],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_init( 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( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
@ -331,7 +331,7 @@ async def test_link_get_api_key_ResponseError(hass, aioclient_mock):
aioclient_mock.get( aioclient_mock.get(
pydeconz.utils.URL_DISCOVER, pydeconz.utils.URL_DISCOVER,
json=[{"id": BRIDGEID, "internalipaddress": "1.2.3.4", "internalport": 80}], 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( result = await hass.config_entries.flow.async_init(
@ -374,7 +374,7 @@ async def test_flow_ssdp_discovery(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"http://1.2.3.4:80/api", "http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}], json=[{"success": {"username": API_KEY}}],
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(

View file

@ -1,7 +1,12 @@
"""Tests for the DirecTV component.""" """Tests for the DirecTV component."""
from homeassistant.components.directv.const import CONF_RECEIVER_ID, DOMAIN from homeassistant.components.directv.const import CONF_RECEIVER_ID, DOMAIN
from homeassistant.components.ssdp import ATTR_SSDP_LOCATION 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 homeassistant.helpers.typing import HomeAssistantType
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@ -22,20 +27,20 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None:
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/info/getVersion", f"http://{HOST}:8080/info/getVersion",
text=load_fixture("directv/info-get-version.json"), text=load_fixture("directv/info-get-version.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/info/getLocations", f"http://{HOST}:8080/info/getLocations",
text=load_fixture("directv/info-get-locations.json"), text=load_fixture("directv/info-get-locations.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/info/mode", f"http://{HOST}:8080/info/mode",
params={"clientAddr": "B01234567890"}, params={"clientAddr": "B01234567890"},
text=load_fixture("directv/info-mode-standby.json"), text=load_fixture("directv/info-mode-standby.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
@ -43,39 +48,39 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None:
params={"clientAddr": "9XXXXXXXXXX9"}, params={"clientAddr": "9XXXXXXXXXX9"},
status=HTTP_INTERNAL_SERVER_ERROR, status=HTTP_INTERNAL_SERVER_ERROR,
text=load_fixture("directv/info-mode-error.json"), text=load_fixture("directv/info-mode-error.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/info/mode", f"http://{HOST}:8080/info/mode",
text=load_fixture("directv/info-mode.json"), text=load_fixture("directv/info-mode.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/remote/processKey", f"http://{HOST}:8080/remote/processKey",
text=load_fixture("directv/remote-process-key.json"), text=load_fixture("directv/remote-process-key.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/tv/tune", f"http://{HOST}:8080/tv/tune",
text=load_fixture("directv/tv-tune.json"), text=load_fixture("directv/tv-tune.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/tv/getTuned", f"http://{HOST}:8080/tv/getTuned",
params={"clientAddr": "2CA17D1CD30X"}, params={"clientAddr": "2CA17D1CD30X"},
text=load_fixture("directv/tv-get-tuned.json"), text=load_fixture("directv/tv-get-tuned.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/tv/getTuned", f"http://{HOST}:8080/tv/getTuned",
params={"clientAddr": "A01234567890"}, params={"clientAddr": "A01234567890"},
text=load_fixture("directv/tv-get-tuned-music.json"), text=load_fixture("directv/tv-get-tuned-music.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
@ -83,13 +88,13 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None:
params={"clientAddr": "C01234567890"}, params={"clientAddr": "C01234567890"},
status=HTTP_FORBIDDEN, status=HTTP_FORBIDDEN,
text=load_fixture("directv/tv-get-tuned-restricted.json"), text=load_fixture("directv/tv-get-tuned-restricted.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"http://{HOST}:8080/tv/getTuned", f"http://{HOST}:8080/tv/getTuned",
text=load_fixture("directv/tv-get-tuned-movie.json"), text=load_fixture("directv/tv-get-tuned-movie.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )

View file

@ -1,7 +1,7 @@
"""Tests for the Elgato Key Light integration.""" """Tests for the Elgato Key Light integration."""
from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER, DOMAIN 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 homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@ -18,25 +18,25 @@ async def init_integration(
aioclient_mock.get( aioclient_mock.get(
"http://1.2.3.4:9123/elgato/accessory-info", "http://1.2.3.4:9123/elgato/accessory-info",
text=load_fixture("elgato/info.json"), text=load_fixture("elgato/info.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.put( aioclient_mock.put(
"http://1.2.3.4:9123/elgato/lights", "http://1.2.3.4:9123/elgato/lights",
text=load_fixture("elgato/state.json"), text=load_fixture("elgato/state.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://1.2.3.4:9123/elgato/lights", "http://1.2.3.4:9123/elgato/lights",
text=load_fixture("elgato/state.json"), text=load_fixture("elgato/state.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://5.6.7.8:9123/elgato/accessory-info", "http://5.6.7.8:9123/elgato/accessory-info",
text=load_fixture("elgato/info.json"), text=load_fixture("elgato/info.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry( entry = MockConfigEntry(

View file

@ -5,7 +5,7 @@ from homeassistant import data_entry_flow
from homeassistant.components.elgato import config_flow from homeassistant.components.elgato import config_flow
from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF 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 homeassistant.core import HomeAssistant
from . import init_integration from . import init_integration
@ -44,7 +44,7 @@ async def test_show_zerconf_form(
aioclient_mock.get( aioclient_mock.get(
"http://1.2.3.4:9123/elgato/accessory-info", "http://1.2.3.4:9123/elgato/accessory-info",
text=load_fixture("elgato/info.json"), text=load_fixture("elgato/info.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.ElgatoFlowHandler() flow = config_flow.ElgatoFlowHandler()
@ -176,7 +176,7 @@ async def test_full_user_flow_implementation(
aioclient_mock.get( aioclient_mock.get(
"http://1.2.3.4:9123/elgato/accessory-info", "http://1.2.3.4:9123/elgato/accessory-info",
text=load_fixture("elgato/info.json"), 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( result = await hass.config_entries.flow.async_init(
@ -208,7 +208,7 @@ async def test_full_zeroconf_flow_implementation(
aioclient_mock.get( aioclient_mock.get(
"http://1.2.3.4:9123/elgato/accessory-info", "http://1.2.3.4:9123/elgato/accessory-info",
text=load_fixture("elgato/info.json"), text=load_fixture("elgato/info.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.ElgatoFlowHandler() flow = config_flow.ElgatoFlowHandler()

View file

@ -38,6 +38,7 @@ from homeassistant.components.emulated_hue.hue_api import (
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
CONTENT_TYPE_JSON,
HTTP_NOT_FOUND, HTTP_NOT_FOUND,
HTTP_OK, HTTP_OK,
HTTP_UNAUTHORIZED, HTTP_UNAUTHORIZED,
@ -245,7 +246,7 @@ async def test_discover_lights(hue_client):
result = await hue_client.get("/api/username/lights") result = await hue_client.get("/api/username/lights")
assert result.status == HTTP_OK 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() 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() no_brightness_result_json = await no_brightness_result.json()
assert no_brightness_result.status == HTTP_OK 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 assert len(no_brightness_result_json) == 1
# Verify that SERVICE_TURN_OFF has been called # 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() no_brightness_result_json = await no_brightness_result.json()
assert no_brightness_result.status == HTTP_OK 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 assert len(no_brightness_result_json) == 1
# Verify that SERVICE_TURN_ON has been called # 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}") result = await hue_client.get(f"/api/{HUE_API_USERNAME}")
assert result.status == HTTP_OK 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() 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") result = await hue_client.get(f"/api/{HUE_API_USERNAME}/config")
assert result.status == 200 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() config_json = await result.json()
@ -508,7 +509,7 @@ async def test_discover_config(hue_client):
result = await hue_client.get("/api/config") result = await hue_client.get("/api/config")
assert result.status == 200 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() config_json = await result.json()
assert "error" not in config_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") result = await hue_client.get("/api/wronguser/config")
assert result.status == 200 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() config_json = await result.json()
assert "error" not in config_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") result = await hue_client.get("/api/username/lights")
assert result.status == HTTP_OK 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() 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() ceiling_result_json = await ceiling_result.json()
assert ceiling_result.status == HTTP_OK 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 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 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): for _ in range(7):
future = dt_util.utcnow() + timedelta(seconds=1) 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 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() cover_result_json = await cover_result.json()
@ -1104,7 +1105,7 @@ async def test_get_empty_groups_state(hue_client):
# pylint: disable=invalid-name # pylint: disable=invalid-name
async def perform_put_test_on_ceiling_lights( 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.""" """Test the setting of a light."""
# Turn the office light off first # 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 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() 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 assert result.status == expected_status
if expected_status == HTTP_OK: 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() return await result.json()
@ -1164,7 +1165,7 @@ async def perform_put_light_state(
entity_id, entity_id,
is_on, is_on,
brightness=None, brightness=None,
content_type="application/json", content_type=CONTENT_TYPE_JSON,
hue=None, hue=None,
saturation=None, saturation=None,
color_temp=None, color_temp=None,

View file

@ -9,7 +9,7 @@ import requests
from homeassistant import const, setup from homeassistant import const, setup
from homeassistant.components import emulated_hue from homeassistant.components import emulated_hue
from homeassistant.components.emulated_hue import upnp 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 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 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() resp_json = result.json()
success_json = resp_json[0] success_json = resp_json[0]
@ -186,7 +186,7 @@ MX:3
) )
assert result.status_code == HTTP_OK 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() resp_json = result.json()
assert len(resp_json) == 1 assert len(resp_json) == 1

View file

@ -5,7 +5,7 @@ import time
import pytest import pytest
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN 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 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, "timeNow": now,
} }
), ),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
status=200, status=200,
) )
# Mocks the device for flo. # Mocks the device for flo.
@ -48,28 +48,28 @@ def aioclient_mock_fixture(aioclient_mock):
"https://api-gw.meetflo.com/api/v2/devices/98765", "https://api-gw.meetflo.com/api/v2/devices/98765",
text=load_fixture("flo/device_info_response.json"), text=load_fixture("flo/device_info_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
# Mocks the water consumption for flo. # Mocks the water consumption for flo.
aioclient_mock.get( aioclient_mock.get(
"https://api-gw.meetflo.com/api/v2/water/consumption", "https://api-gw.meetflo.com/api/v2/water/consumption",
text=load_fixture("flo/water_consumption_info_response.json"), text=load_fixture("flo/water_consumption_info_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
# Mocks the location info for flo. # Mocks the location info for flo.
aioclient_mock.get( aioclient_mock.get(
"https://api-gw.meetflo.com/api/v2/locations/mmnnoopp", "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp",
text=load_fixture("flo/location_info_expand_devices_response.json"), text=load_fixture("flo/location_info_expand_devices_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
# Mocks the user info for flo. # Mocks the user info for flo.
aioclient_mock.get( aioclient_mock.get(
"https://api-gw.meetflo.com/api/v2/users/12345abcde", "https://api-gw.meetflo.com/api/v2/users/12345abcde",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
params={"expand": "locations"}, params={"expand": "locations"},
) )
# Mocks the user info for flo. # 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", "https://api-gw.meetflo.com/api/v2/users/12345abcde",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
# Mocks the valve open call for flo. # Mocks the valve open call for flo.
aioclient_mock.post( aioclient_mock.post(
"https://api-gw.meetflo.com/api/v2/devices/98765", "https://api-gw.meetflo.com/api/v2/devices/98765",
text=load_fixture("flo/device_info_response.json"), text=load_fixture("flo/device_info_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
json={"valve": {"target": "open"}}, json={"valve": {"target": "open"}},
) )
# Mocks the valve close call for flo. # 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", "https://api-gw.meetflo.com/api/v2/devices/98765",
text=load_fixture("flo/device_info_response_closed.json"), text=load_fixture("flo/device_info_response_closed.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
json={"valve": {"target": "closed"}}, json={"valve": {"target": "closed"}},
) )
# Mocks the health test call for flo. # 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", "https://api-gw.meetflo.com/api/v2/devices/98765/healthTest/run",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
# Mocks the health test call for flo. # Mocks the health test call for flo.
aioclient_mock.post( aioclient_mock.post(
"https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode", "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
json={"systemMode": {"target": "home"}}, json={"systemMode": {"target": "home"}},
) )
# Mocks the health test call for flo. # 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", "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
json={"systemMode": {"target": "away"}}, json={"systemMode": {"target": "away"}},
) )
# Mocks the health test call for flo. # 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", "https://api-gw.meetflo.com/api/v2/locations/mmnnoopp/systemMode",
text=load_fixture("flo/user_info_expand_locations_response.json"), text=load_fixture("flo/user_info_expand_locations_response.json"),
status=200, status=200,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
json={ json={
"systemMode": { "systemMode": {
"target": "sleep", "target": "sleep",

View file

@ -4,6 +4,7 @@ import time
from homeassistant import config_entries, setup from homeassistant import config_entries, setup
from homeassistant.components.flo.const import DOMAIN 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 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, "timeNow": now,
} }
), ),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
status=400, status=400,
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(

View file

@ -9,7 +9,7 @@ import requests_mock
import homeassistant.components.binary_sensor as binary_sensor import homeassistant.components.binary_sensor as binary_sensor
import homeassistant.components.rest.binary_sensor as rest 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.exceptions import PlatformNotReady
from homeassistant.helpers import template from homeassistant.helpers import template
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
@ -143,7 +143,7 @@ class TestRestBinarySensorSetup(unittest.TestCase):
"authentication": "basic", "authentication": "basic",
"username": "my username", "username": "my username",
"password": "my password", "password": "my password",
"headers": {"Accept": "application/json"}, "headers": {"Accept": CONTENT_TYPE_JSON},
} }
}, },
) )
@ -170,7 +170,7 @@ class TestRestBinarySensorSetup(unittest.TestCase):
"authentication": "basic", "authentication": "basic",
"username": "my username", "username": "my username",
"password": "my password", "password": "my password",
"headers": {"Accept": "application/json"}, "headers": {"Accept": CONTENT_TYPE_JSON},
} }
}, },
) )

View file

@ -12,7 +12,12 @@ import requests_mock
from homeassistant import config as hass_config from homeassistant import config as hass_config
import homeassistant.components.rest.sensor as rest import homeassistant.components.rest.sensor as rest
import homeassistant.components.sensor as sensor 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.exceptions import PlatformNotReady
from homeassistant.helpers.config_validation import template from homeassistant.helpers.config_validation import template
from homeassistant.setup import async_setup_component, setup_component from homeassistant.setup import async_setup_component, setup_component
@ -135,7 +140,7 @@ class TestRestSensorSetup(unittest.TestCase):
"authentication": "basic", "authentication": "basic",
"username": "my username", "username": "my username",
"password": "my password", "password": "my password",
"headers": {"Accept": "application/json"}, "headers": {"Accept": CONTENT_TYPE_JSON},
} }
}, },
) )
@ -164,7 +169,7 @@ class TestRestSensorSetup(unittest.TestCase):
"authentication": "basic", "authentication": "basic",
"username": "my username", "username": "my username",
"password": "my password", "password": "my password",
"headers": {"Accept": "application/json"}, "headers": {"Accept": CONTENT_TYPE_JSON},
} }
}, },
) )
@ -212,7 +217,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'{ "key": "' + self.initial_state + '" }', '{ "key": "' + self.initial_state + '" }',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.name = "foo" self.name = "foo"
@ -276,7 +281,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'{ "key": "updated_state" }', '{ "key": "updated_state" }',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.sensor.update() self.sensor.update()
@ -288,7 +293,7 @@ class TestRestSensor(unittest.TestCase):
self.rest.update = Mock( self.rest.update = Mock(
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( 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( self.sensor = rest.RestSensor(
@ -313,7 +318,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'{ "key": "some_json_value" }', '{ "key": "some_json_value" }',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.sensor = rest.RestSensor( self.sensor = rest.RestSensor(
@ -337,7 +342,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'[{ "key": "another_value" }]', '[{ "key": "another_value" }]',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.sensor = rest.RestSensor( self.sensor = rest.RestSensor(
@ -361,7 +366,7 @@ class TestRestSensor(unittest.TestCase):
self.rest.update = Mock( self.rest.update = Mock(
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
None, CaseInsensitiveDict({"Content-Type": "application/json"}) None, CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON})
), ),
) )
self.sensor = rest.RestSensor( self.sensor = rest.RestSensor(
@ -387,7 +392,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'["list", "of", "things"]', '["list", "of", "things"]',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.sensor = rest.RestSensor( self.sensor = rest.RestSensor(
@ -439,7 +444,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'{ "key": "json_state_updated_value" }', '{ "key": "json_state_updated_value" }',
CaseInsensitiveDict({"Content-Type": "application/json"}), CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_JSON}),
), ),
) )
self.sensor = rest.RestSensor( self.sensor = rest.RestSensor(
@ -471,7 +476,7 @@ class TestRestSensor(unittest.TestCase):
"rest.RestData.update", "rest.RestData.update",
side_effect=self.update_side_effect( side_effect=self.update_side_effect(
'{ "toplevel": {"master_value": "master", "second_level": {"some_json_key": "some_json_value", "some_json_key2": "some_json_value2" } } }', '{ "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( self.sensor = rest.RestSensor(

View file

@ -123,7 +123,7 @@ class TestRestSwitchSetup:
CONF_NAME: "foo", CONF_NAME: "foo",
CONF_RESOURCE: "http://localhost", CONF_RESOURCE: "http://localhost",
rest.CONF_STATE_RESOURCE: "http://localhost/state", 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_ON: "custom on text",
rest.CONF_BODY_OFF: "custom off text", rest.CONF_BODY_OFF: "custom off text",
} }
@ -143,7 +143,7 @@ class TestRestSwitch:
self.method = "post" self.method = "post"
self.resource = "http://localhost/" self.resource = "http://localhost/"
self.state_resource = self.resource self.state_resource = self.resource
self.headers = {"Content-type": "application/json"} self.headers = {"Content-type": CONTENT_TYPE_JSON}
self.auth = None self.auth = None
self.body_on = Template("on", self.hass) self.body_on = Template("on", self.hass)
self.body_off = Template("off", self.hass) self.body_off = Template("off", self.hass)

View file

@ -4,7 +4,7 @@ import asyncio
import aiohttp import aiohttp
import homeassistant.components.rest_command as rc 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 homeassistant.setup import setup_component
from tests.common import assert_setup_component, get_test_home_assistant 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}, "content_type_test": {"content_type": CONTENT_TYPE_TEXT_PLAIN},
"headers_test": { "headers_test": {
"headers": { "headers": {
"Accept": "application/json", "Accept": CONTENT_TYPE_JSON,
"User-Agent": "Mozilla/5.0", "User-Agent": "Mozilla/5.0",
} }
}, },
"headers_and_content_type_test": { "headers_and_content_type_test": {
"headers": {"Accept": "application/json"}, "headers": {"Accept": CONTENT_TYPE_JSON},
"content_type": CONTENT_TYPE_TEXT_PLAIN, "content_type": CONTENT_TYPE_TEXT_PLAIN,
}, },
"headers_and_content_type_override_test": { "headers_and_content_type_override_test": {
"headers": { "headers": {
"Accept": "application/json", "Accept": CONTENT_TYPE_JSON,
aiohttp.hdrs.CONTENT_TYPE: "application/pdf", aiohttp.hdrs.CONTENT_TYPE: "application/pdf",
}, },
"content_type": CONTENT_TYPE_TEXT_PLAIN, "content_type": CONTENT_TYPE_TEXT_PLAIN,
}, },
"headers_template_test": { "headers_template_test": {
"headers": { "headers": {
"Accept": "application/json", "Accept": CONTENT_TYPE_JSON,
"User-Agent": "Mozilla/{{ 3 + 2 }}.0", "User-Agent": "Mozilla/{{ 3 + 2 }}.0",
} }
}, },
@ -291,7 +291,7 @@ class TestRestCommandComponent:
# headers_test # headers_test
assert len(aioclient_mock.mock_calls[2][3]) == 2 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" assert aioclient_mock.mock_calls[2][3].get("User-Agent") == "Mozilla/5.0"
# headers_and_content_type_test # headers_and_content_type_test
@ -300,7 +300,7 @@ class TestRestCommandComponent:
aioclient_mock.mock_calls[3][3].get(aiohttp.hdrs.CONTENT_TYPE) aioclient_mock.mock_calls[3][3].get(aiohttp.hdrs.CONTENT_TYPE)
== CONTENT_TYPE_TEXT_PLAIN == 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 # headers_and_content_type_override_test
assert len(aioclient_mock.mock_calls[4][3]) == 2 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) aioclient_mock.mock_calls[4][3].get(aiohttp.hdrs.CONTENT_TYPE)
== CONTENT_TYPE_TEXT_PLAIN == 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 # headers_template_test
assert len(aioclient_mock.mock_calls[5][3]) == 2 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" assert aioclient_mock.mock_calls[5][3].get("User-Agent") == "Mozilla/5.0"
# headers_and_content_type_override_template_test # headers_and_content_type_override_template_test

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
CONF_PORT, CONF_PORT,
CONF_SSL, CONF_SSL,
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
CONTENT_TYPE_JSON,
) )
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
@ -85,43 +86,43 @@ def mock_connection(
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/system/status", f"{sonarr_url}/system/status",
text=load_fixture("sonarr/system-status.json"), text=load_fixture("sonarr/system-status.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/diskspace", f"{sonarr_url}/diskspace",
text=load_fixture("sonarr/diskspace.json"), text=load_fixture("sonarr/diskspace.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/calendar", f"{sonarr_url}/calendar",
text=load_fixture("sonarr/calendar.json"), text=load_fixture("sonarr/calendar.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/command", f"{sonarr_url}/command",
text=load_fixture("sonarr/command.json"), text=load_fixture("sonarr/command.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/queue", f"{sonarr_url}/queue",
text=load_fixture("sonarr/queue.json"), text=load_fixture("sonarr/queue.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/series", f"{sonarr_url}/series",
text=load_fixture("sonarr/series.json"), text=load_fixture("sonarr/series.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
f"{sonarr_url}/wanted/missing", f"{sonarr_url}/wanted/missing",
text=load_fixture("sonarr/wanted-missing.json"), text=load_fixture("sonarr/wanted-missing.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )

View file

@ -9,7 +9,7 @@ from homeassistant.components.twentemilieu.const import (
CONF_POST_CODE, CONF_POST_CODE,
DOMAIN, DOMAIN,
) )
from homeassistant.const import CONF_ID from homeassistant.const import CONF_ID, CONTENT_TYPE_JSON
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -51,7 +51,7 @@ async def test_invalid_address(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"https://twentemilieuapi.ximmio.com/api/FetchAdress", "https://twentemilieuapi.ximmio.com/api/FetchAdress",
json={"dataList": []}, json={"dataList": []},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.TwenteMilieuFlowHandler() flow = config_flow.TwenteMilieuFlowHandler()
@ -72,7 +72,7 @@ async def test_address_already_set_up(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"https://twentemilieuapi.ximmio.com/api/FetchAdress", "https://twentemilieuapi.ximmio.com/api/FetchAdress",
json={"dataList": [{"UniqueId": "12345"}]}, json={"dataList": [{"UniqueId": "12345"}]},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.TwenteMilieuFlowHandler() flow = config_flow.TwenteMilieuFlowHandler()
@ -88,7 +88,7 @@ async def test_full_flow_implementation(hass, aioclient_mock):
aioclient_mock.post( aioclient_mock.post(
"https://twentemilieuapi.ximmio.com/api/FetchAdress", "https://twentemilieuapi.ximmio.com/api/FetchAdress",
json={"dataList": [{"UniqueId": "12345"}]}, json={"dataList": [{"UniqueId": "12345"}]},
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.TwenteMilieuFlowHandler() flow = config_flow.TwenteMilieuFlowHandler()

View file

@ -23,6 +23,7 @@ from homeassistant.const import (
CONF_PORT, CONF_PORT,
CONF_USERNAME, CONF_USERNAME,
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
CONTENT_TYPE_JSON,
) )
from .test_controller import setup_unifi_integration from .test_controller import setup_unifi_integration
@ -94,7 +95,7 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery):
aioclient_mock.post( aioclient_mock.post(
"https://1.2.3.4:1234/api/login", "https://1.2.3.4:1234/api/login",
json={"data": "login successful", "meta": {"rc": "ok"}}, json={"data": "login successful", "meta": {"rc": "ok"}},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( 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"}], "data": [{"desc": "Site name", "name": "site_id", "role": "admin"}],
"meta": {"rc": "ok"}, "meta": {"rc": "ok"},
}, },
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.post(
"https://1.2.3.4:1234/api/login", "https://1.2.3.4:1234/api/login",
json={"data": "login successful", "meta": {"rc": "ok"}}, json={"data": "login successful", "meta": {"rc": "ok"}},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
@ -157,7 +158,7 @@ async def test_flow_works_multiple_sites(hass, aioclient_mock):
], ],
"meta": {"rc": "ok"}, "meta": {"rc": "ok"},
}, },
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( 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( aioclient_mock.post(
"https://1.2.3.4:1234/api/login", "https://1.2.3.4:1234/api/login",
json={"data": "login successful", "meta": {"rc": "ok"}}, json={"data": "login successful", "meta": {"rc": "ok"}},
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( 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"}], "data": [{"desc": "Site name", "name": "site_id", "role": "admin"}],
"meta": {"rc": "ok"}, "meta": {"rc": "ok"},
}, },
headers={"content-type": "application/json"}, headers={"content-type": CONTENT_TYPE_JSON},
) )
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(

View file

@ -3,7 +3,7 @@
import json import json
from homeassistant.components.wled.const import DOMAIN 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 homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@ -24,25 +24,25 @@ async def init_integration(
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/", "http://192.168.1.123:80/json/",
json=data, json=data,
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.post( aioclient_mock.post(
"http://192.168.1.123:80/json/state", "http://192.168.1.123:80/json/state",
json=data["state"], json=data["state"],
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/info", "http://192.168.1.123:80/json/info",
json=data["info"], json=data["info"],
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/state", "http://192.168.1.123:80/json/state",
json=data["state"], json=data["state"],
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
entry = MockConfigEntry( entry = MockConfigEntry(

View file

@ -5,7 +5,7 @@ from wled import WLEDConnectionError
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.wled import config_flow from homeassistant.components.wled import config_flow
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF 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 homeassistant.core import HomeAssistant
from . import init_integration from . import init_integration
@ -45,7 +45,7 @@ async def test_show_zerconf_form(
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/", "http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.json"), text=load_fixture("wled/rgb.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.WLEDFlowHandler() flow = config_flow.WLEDFlowHandler()
@ -190,7 +190,7 @@ async def test_full_user_flow_implementation(
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/", "http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.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( result = await hass.config_entries.flow.async_init(
@ -218,7 +218,7 @@ async def test_full_zeroconf_flow_implementation(
aioclient_mock.get( aioclient_mock.get(
"http://192.168.1.123:80/json/", "http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.json"), text=load_fixture("wled/rgb.json"),
headers={"Content-Type": "application/json"}, headers={"Content-Type": CONTENT_TYPE_JSON},
) )
flow = config_flow.WLEDFlowHandler() flow = config_flow.WLEDFlowHandler()