Use content type text plain constant (#40313)
This commit is contained in:
parent
4f5d3b4035
commit
0c077685b6
3 changed files with 11 additions and 9 deletions
|
@ -9,6 +9,7 @@ from homeassistant.components.demo.sensor import DemoSensor
|
||||||
import homeassistant.components.prometheus as prometheus
|
import homeassistant.components.prometheus as prometheus
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
CONTENT_TYPE_TEXT_PLAIN,
|
||||||
DEGREE,
|
DEGREE,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
@ -97,7 +98,7 @@ async def test_view(hass, hass_client):
|
||||||
resp = await client.get(prometheus.API_ENDPOINT)
|
resp = await client.get(prometheus.API_ENDPOINT)
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
assert resp.headers["content-type"] == "text/plain"
|
assert resp.headers["content-type"] == CONTENT_TYPE_TEXT_PLAIN
|
||||||
body = await resp.text()
|
body = await resp.text()
|
||||||
body = body.split("\n")
|
body = body.split("\n")
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ 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 DATA_MEGABYTES, SERVICE_RELOAD
|
from homeassistant.const import 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
|
||||||
|
@ -413,7 +413,7 @@ class TestRestSensor(unittest.TestCase):
|
||||||
"rest.RestData.update",
|
"rest.RestData.update",
|
||||||
side_effect=self.update_side_effect(
|
side_effect=self.update_side_effect(
|
||||||
"This is text rather than JSON data.",
|
"This is text rather than JSON data.",
|
||||||
CaseInsensitiveDict({"Content-Type": "text/plain"}),
|
CaseInsensitiveDict({"Content-Type": CONTENT_TYPE_TEXT_PLAIN}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.sensor = rest.RestSensor(
|
self.sensor = rest.RestSensor(
|
||||||
|
|
|
@ -4,6 +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.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
|
||||||
|
@ -218,7 +219,7 @@ class TestRestCommandComponent:
|
||||||
header_config_variations = {
|
header_config_variations = {
|
||||||
rc.DOMAIN: {
|
rc.DOMAIN: {
|
||||||
"no_headers_test": {},
|
"no_headers_test": {},
|
||||||
"content_type_test": {"content_type": "text/plain"},
|
"content_type_test": {"content_type": CONTENT_TYPE_TEXT_PLAIN},
|
||||||
"headers_test": {
|
"headers_test": {
|
||||||
"headers": {
|
"headers": {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
@ -227,14 +228,14 @@ class TestRestCommandComponent:
|
||||||
},
|
},
|
||||||
"headers_and_content_type_test": {
|
"headers_and_content_type_test": {
|
||||||
"headers": {"Accept": "application/json"},
|
"headers": {"Accept": "application/json"},
|
||||||
"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": "application/json",
|
||||||
aiohttp.hdrs.CONTENT_TYPE: "application/pdf",
|
aiohttp.hdrs.CONTENT_TYPE: "application/pdf",
|
||||||
},
|
},
|
||||||
"content_type": "text/plain",
|
"content_type": CONTENT_TYPE_TEXT_PLAIN,
|
||||||
},
|
},
|
||||||
"headers_template_test": {
|
"headers_template_test": {
|
||||||
"headers": {
|
"headers": {
|
||||||
|
@ -285,7 +286,7 @@ class TestRestCommandComponent:
|
||||||
assert len(aioclient_mock.mock_calls[1][3]) == 1
|
assert len(aioclient_mock.mock_calls[1][3]) == 1
|
||||||
assert (
|
assert (
|
||||||
aioclient_mock.mock_calls[1][3].get(aiohttp.hdrs.CONTENT_TYPE)
|
aioclient_mock.mock_calls[1][3].get(aiohttp.hdrs.CONTENT_TYPE)
|
||||||
== "text/plain"
|
== CONTENT_TYPE_TEXT_PLAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
# headers_test
|
# headers_test
|
||||||
|
@ -297,7 +298,7 @@ class TestRestCommandComponent:
|
||||||
assert len(aioclient_mock.mock_calls[3][3]) == 2
|
assert len(aioclient_mock.mock_calls[3][3]) == 2
|
||||||
assert (
|
assert (
|
||||||
aioclient_mock.mock_calls[3][3].get(aiohttp.hdrs.CONTENT_TYPE)
|
aioclient_mock.mock_calls[3][3].get(aiohttp.hdrs.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") == "application/json"
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ class TestRestCommandComponent:
|
||||||
assert len(aioclient_mock.mock_calls[4][3]) == 2
|
assert len(aioclient_mock.mock_calls[4][3]) == 2
|
||||||
assert (
|
assert (
|
||||||
aioclient_mock.mock_calls[4][3].get(aiohttp.hdrs.CONTENT_TYPE)
|
aioclient_mock.mock_calls[4][3].get(aiohttp.hdrs.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") == "application/json"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue