Use content type json constant (#40312)
This commit is contained in:
parent
9c1eb78a0f
commit
6a7caad8dc
28 changed files with 170 additions and 153 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue