Use content type json constant (#40312)
This commit is contained in:
1 parent
9c1eb78a0f
commit
6a7caad8dc
28 files changed
+170
-153
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user