Use f-strings in integrations starting with "F"and"G" (#32150)
* Use f-strings in integrations starting with F * Use f-strings in tests for integrations starting with F * Use f-strings in integrations starting with G * Use f-strings in tests for integrations starting with G * Fix pylint error * Fix broken test
This commit is contained in:
1 parent
496bd3dddf
commit
ad102b3840
59 files changed
+219
-344
No files matched your search
@@ -119,7 +119,7 @@ def mock_open_file():
|
||||
def test_check_box_health(caplog):
|
||||
"""Test check box health."""
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/healthz".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/healthz"
|
||||
mock_req.get(url, status_code=HTTP_OK, json=MOCK_HEALTH)
|
||||
assert fb.check_box_health(url, "user", "pass") == MOCK_BOX_ID
|
||||
|
||||
@@ -184,7 +184,7 @@ async def test_process_image(hass, mock_healthybox, mock_image):
|
||||
hass.bus.async_listen("image_processing.detect_face", mock_face_event)
|
||||
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/check".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/check"
|
||||
mock_req.post(url, json=MOCK_JSON)
|
||||
data = {ATTR_ENTITY_ID: VALID_ENTITY_ID}
|
||||
await hass.services.async_call(ip.DOMAIN, ip.SERVICE_SCAN, service_data=data)
|
||||
@@ -219,7 +219,7 @@ async def test_process_image_errors(hass, mock_healthybox, mock_image, caplog):
|
||||
|
||||
# Test connection error.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/check".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/check"
|
||||
mock_req.register_uri("POST", url, exc=requests.exceptions.ConnectTimeout)
|
||||
data = {ATTR_ENTITY_ID: VALID_ENTITY_ID}
|
||||
await hass.services.async_call(ip.DOMAIN, ip.SERVICE_SCAN, service_data=data)
|
||||
@@ -233,7 +233,7 @@ async def test_process_image_errors(hass, mock_healthybox, mock_image, caplog):
|
||||
|
||||
# Now test with bad auth.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/check".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/check"
|
||||
mock_req.register_uri("POST", url, status_code=HTTP_UNAUTHORIZED)
|
||||
data = {ATTR_ENTITY_ID: VALID_ENTITY_ID}
|
||||
await hass.services.async_call(ip.DOMAIN, ip.SERVICE_SCAN, service_data=data)
|
||||
@@ -253,7 +253,7 @@ async def test_teach_service(
|
||||
|
||||
# Test successful teach.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/teach".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_OK)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
@@ -267,7 +267,7 @@ async def test_teach_service(
|
||||
|
||||
# Now test with bad auth.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/teach".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_UNAUTHORIZED)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
@@ -282,7 +282,7 @@ async def test_teach_service(
|
||||
|
||||
# Now test the failed teaching.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/teach".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, status_code=HTTP_BAD_REQUEST, text=MOCK_ERROR_NO_FACE)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
@@ -297,7 +297,7 @@ async def test_teach_service(
|
||||
|
||||
# Now test connection error.
|
||||
with requests_mock.Mocker() as mock_req:
|
||||
url = "http://{}:{}/facebox/teach".format(MOCK_IP, MOCK_PORT)
|
||||
url = f"http://{MOCK_IP}:{MOCK_PORT}/facebox/teach"
|
||||
mock_req.post(url, exc=requests.exceptions.ConnectTimeout)
|
||||
data = {
|
||||
ATTR_ENTITY_ID: VALID_ENTITY_ID,
|
||||
@@ -313,7 +313,7 @@ async def test_teach_service(
|
||||
|
||||
async def test_setup_platform_with_name(hass, mock_healthybox):
|
||||
"""Set up platform with one entity and a name."""
|
||||
named_entity_id = "image_processing.{}".format(MOCK_NAME)
|
||||
named_entity_id = f"image_processing.{MOCK_NAME}"
|
||||
|
||||
valid_config_named = VALID_CONFIG.copy()
|
||||
valid_config_named[ip.DOMAIN][ip.CONF_SOURCE][ip.CONF_NAME] = MOCK_NAME
|
||||
|
||||
@@ -119,14 +119,10 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||
hass.states.async_set("fan.entity", STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "turn_on - device - {} - off - on - None".format(
|
||||
"fan.entity"
|
||||
)
|
||||
assert calls[0].data["some"] == "turn_on - device - fan.entity - off - on - None"
|
||||
|
||||
# Fake that the entity is turning off.
|
||||
hass.states.async_set("fan.entity", STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == "turn_off - device - {} - on - off - None".format(
|
||||
"fan.entity"
|
||||
)
|
||||
assert calls[1].data["some"] == "turn_off - device - fan.entity - on - off - None"
|
||||
@@ -39,7 +39,7 @@ class TestFeedreaderComponent(unittest.TestCase):
|
||||
"""Initialize values for this testcase class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
# Delete any previously stored data
|
||||
data_file = self.hass.config.path("{}.pickle".format("feedreader"))
|
||||
data_file = self.hass.config.path(f"{feedreader.DOMAIN}.pickle")
|
||||
if exists(data_file):
|
||||
remove(data_file)
|
||||
|
||||
@@ -85,7 +85,7 @@ class TestFeedreaderComponent(unittest.TestCase):
|
||||
# Loading raw data from fixture and plug in to data object as URL
|
||||
# works since the third-party feedparser library accepts a URL
|
||||
# as well as the actual data.
|
||||
data_file = self.hass.config.path("{}.pickle".format(feedreader.DOMAIN))
|
||||
data_file = self.hass.config.path(f"{feedreader.DOMAIN}.pickle")
|
||||
storage = StoredData(data_file)
|
||||
with patch(
|
||||
"homeassistant.components.feedreader.track_time_interval"
|
||||
@@ -179,7 +179,7 @@ class TestFeedreaderComponent(unittest.TestCase):
|
||||
@mock.patch("feedparser.parse", return_value=None)
|
||||
def test_feed_parsing_failed(self, mock_parse):
|
||||
"""Test feed where parsing fails."""
|
||||
data_file = self.hass.config.path("{}.pickle".format(feedreader.DOMAIN))
|
||||
data_file = self.hass.config.path(f"{feedreader.DOMAIN}.pickle")
|
||||
storage = StoredData(data_file)
|
||||
manager = FeedManager(
|
||||
"FEED DATA", DEFAULT_SCAN_INTERVAL, DEFAULT_MAX_ENTRIES, self.hass, storage
|
||||
|
||||
@@ -56,8 +56,9 @@ class TestNotifyFile(unittest.TestCase):
|
||||
):
|
||||
|
||||
mock_st.return_value.st_size = 0
|
||||
title = "{} notifications (Log started: {})\n{}\n".format(
|
||||
ATTR_TITLE_DEFAULT, dt_util.utcnow().isoformat(), "-" * 80
|
||||
title = (
|
||||
f"{ATTR_TITLE_DEFAULT} notifications "
|
||||
f"(Log started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
|
||||
)
|
||||
|
||||
self.hass.services.call(
|
||||
@@ -72,12 +73,12 @@ class TestNotifyFile(unittest.TestCase):
|
||||
if not timestamp:
|
||||
assert m_open.return_value.write.call_args_list == [
|
||||
call(title),
|
||||
call("{}\n".format(message)),
|
||||
call(f"{message}\n"),
|
||||
]
|
||||
else:
|
||||
assert m_open.return_value.write.call_args_list == [
|
||||
call(title),
|
||||
call("{} {}\n".format(dt_util.utcnow().isoformat(), message)),
|
||||
call(f"{dt_util.utcnow().isoformat()} {message}\n"),
|
||||
]
|
||||
|
||||
def test_notify_file(self):
|
||||
|
||||
@@ -923,9 +923,9 @@ async def test_flux_with_multiple_lights(hass):
|
||||
|
||||
def event_date(hass, event, now=None):
|
||||
if event == SUN_EVENT_SUNRISE:
|
||||
print("sunrise {}".format(sunrise_time))
|
||||
print(f"sunrise {sunrise_time}")
|
||||
return sunrise_time
|
||||
print("sunset {}".format(sunset_time))
|
||||
print(f"sunset {sunset_time}")
|
||||
return sunset_time
|
||||
|
||||
with patch(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""The tests for frontend storage."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.frontend import storage
|
||||
from homeassistant.components.frontend import DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ async def test_get_user_data_empty(hass, hass_ws_client, hass_storage):
|
||||
|
||||
async def test_get_user_data(hass, hass_ws_client, hass_admin_user, hass_storage):
|
||||
"""Test get_user_data command."""
|
||||
storage_key = storage.STORAGE_KEY_USER_DATA.format(hass_admin_user.id)
|
||||
storage_key = f"{DOMAIN}.user_data_{hass_admin_user.id}"
|
||||
hass_storage[storage_key] = {
|
||||
"key": storage_key,
|
||||
"version": 1,
|
||||
@@ -102,7 +102,7 @@ async def test_set_user_data_empty(hass, hass_ws_client, hass_storage):
|
||||
|
||||
async def test_set_user_data(hass, hass_ws_client, hass_storage, hass_admin_user):
|
||||
"""Test set_user_data command with initial data."""
|
||||
storage_key = storage.STORAGE_KEY_USER_DATA.format(hass_admin_user.id)
|
||||
storage_key = f"{DOMAIN}.user_data_{hass_admin_user.id}"
|
||||
hass_storage[storage_key] = {
|
||||
"version": 1,
|
||||
"data": {"test-key": "test-value", "test-complex": "string"},
|
||||
|
||||
@@ -5,8 +5,6 @@ from homeassistant.components import geo_location
|
||||
from homeassistant.components.geo_json_events.geo_location import (
|
||||
ATTR_EXTERNAL_ID,
|
||||
SCAN_INTERVAL,
|
||||
SIGNAL_DELETE_ENTITY,
|
||||
SIGNAL_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.geo_location import ATTR_SOURCE
|
||||
from homeassistant.const import (
|
||||
@@ -190,8 +188,8 @@ async def test_setup_race_condition(hass):
|
||||
|
||||
# Set up some mock feed entries for this test.
|
||||
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 15.5, (-31.0, 150.0))
|
||||
delete_signal = SIGNAL_DELETE_ENTITY.format("1234")
|
||||
update_signal = SIGNAL_UPDATE_ENTITY.format("1234")
|
||||
delete_signal = f"geo_json_events_delete_1234"
|
||||
update_signal = f"geo_json_events_update_1234"
|
||||
|
||||
# Patching 'utcnow' to gain more control over the timed update.
|
||||
utcnow = dt_util.utcnow()
|
||||
|
||||
@@ -163,7 +163,7 @@ async def webhook_id(hass, geofency_client):
|
||||
|
||||
async def test_data_validation(geofency_client, webhook_id):
|
||||
"""Test data validation."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# No data
|
||||
req = await geofency_client.post(url)
|
||||
@@ -181,14 +181,14 @@ async def test_data_validation(geofency_client, webhook_id):
|
||||
|
||||
async def test_gps_enter_and_exit_home(hass, geofency_client, webhook_id):
|
||||
"""Test GPS based zone enter and exit."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# Enter the Home zone
|
||||
req = await geofency_client.post(url, data=GPS_ENTER_HOME)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify(GPS_ENTER_HOME["device"])
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
# Exit the Home zone
|
||||
@@ -196,7 +196,7 @@ async def test_gps_enter_and_exit_home(hass, geofency_client, webhook_id):
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify(GPS_EXIT_HOME["device"])
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_NOT_HOME == state_name
|
||||
|
||||
# Exit the Home zone with "Send Current Position" enabled
|
||||
@@ -208,13 +208,13 @@ async def test_gps_enter_and_exit_home(hass, geofency_client, webhook_id):
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify(GPS_EXIT_HOME["device"])
|
||||
current_latitude = hass.states.get(
|
||||
"{}.{}".format("device_tracker", device_name)
|
||||
).attributes["latitude"]
|
||||
current_latitude = hass.states.get(f"device_tracker.{device_name}").attributes[
|
||||
"latitude"
|
||||
]
|
||||
assert NOT_HOME_LATITUDE == current_latitude
|
||||
current_longitude = hass.states.get(
|
||||
"{}.{}".format("device_tracker", device_name)
|
||||
).attributes["longitude"]
|
||||
current_longitude = hass.states.get(f"device_tracker.{device_name}").attributes[
|
||||
"longitude"
|
||||
]
|
||||
assert NOT_HOME_LONGITUDE == current_longitude
|
||||
|
||||
dev_reg = await hass.helpers.device_registry.async_get_registry()
|
||||
@@ -226,43 +226,43 @@ async def test_gps_enter_and_exit_home(hass, geofency_client, webhook_id):
|
||||
|
||||
async def test_beacon_enter_and_exit_home(hass, geofency_client, webhook_id):
|
||||
"""Test iBeacon based zone enter and exit - a.k.a stationary iBeacon."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# Enter the Home zone
|
||||
req = await geofency_client.post(url, data=BEACON_ENTER_HOME)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(BEACON_ENTER_HOME["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{BEACON_ENTER_HOME['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
# Exit the Home zone
|
||||
req = await geofency_client.post(url, data=BEACON_EXIT_HOME)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(BEACON_ENTER_HOME["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{BEACON_ENTER_HOME['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_NOT_HOME == state_name
|
||||
|
||||
|
||||
async def test_beacon_enter_and_exit_car(hass, geofency_client, webhook_id):
|
||||
"""Test use of mobile iBeacon."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# Enter the Car away from Home zone
|
||||
req = await geofency_client.post(url, data=BEACON_ENTER_CAR)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(BEACON_ENTER_CAR["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{BEACON_ENTER_CAR['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_NOT_HOME == state_name
|
||||
|
||||
# Exit the Car away from Home zone
|
||||
req = await geofency_client.post(url, data=BEACON_EXIT_CAR)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(BEACON_ENTER_CAR["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{BEACON_ENTER_CAR['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_NOT_HOME == state_name
|
||||
|
||||
# Enter the Car in the Home zone
|
||||
@@ -272,29 +272,29 @@ async def test_beacon_enter_and_exit_car(hass, geofency_client, webhook_id):
|
||||
req = await geofency_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(data["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{data['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
# Exit the Car in the Home zone
|
||||
req = await geofency_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify("beacon_{}".format(data["name"]))
|
||||
state_name = hass.states.get("{}.{}".format("device_tracker", device_name)).state
|
||||
device_name = slugify(f"beacon_{data['name']}")
|
||||
state_name = hass.states.get(f"device_tracker.{device_name}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
|
||||
async def test_load_unload_entry(hass, geofency_client, webhook_id):
|
||||
"""Test that the appropriate dispatch signals are added and removed."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# Enter the Home zone
|
||||
req = await geofency_client.post(url, data=GPS_ENTER_HOME)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
device_name = slugify(GPS_ENTER_HOME["device"])
|
||||
state_1 = hass.states.get("{}.{}".format("device_tracker", device_name))
|
||||
state_1 = hass.states.get(f"device_tracker.{device_name}")
|
||||
assert STATE_HOME == state_1.state
|
||||
|
||||
assert len(hass.data[DOMAIN]["devices"]) == 1
|
||||
@@ -307,7 +307,7 @@ async def test_load_unload_entry(hass, geofency_client, webhook_id):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state_2 = hass.states.get("{}.{}".format("device_tracker", device_name))
|
||||
state_2 = hass.states.get(f"device_tracker.{device_name}")
|
||||
assert state_2 is not None
|
||||
assert state_1 is not state_2
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ async def test_offset_in_progress_event(hass, mock_next_event):
|
||||
event = copy.deepcopy(TEST_EVENT)
|
||||
event["start"]["dateTime"] = start
|
||||
event["end"]["dateTime"] = end
|
||||
event["summary"] = "{} !!-15".format(event_summary)
|
||||
event["summary"] = f"{event_summary} !!-15"
|
||||
mock_next_event.return_value.event = event
|
||||
|
||||
assert await async_setup_component(hass, "google", {"google": GOOGLE_CONFIG})
|
||||
@@ -250,7 +250,7 @@ async def test_all_day_offset_in_progress_event(hass, mock_next_event):
|
||||
event = copy.deepcopy(TEST_EVENT)
|
||||
event["start"]["date"] = start
|
||||
event["end"]["date"] = end
|
||||
event["summary"] = "{} !!-25:0".format(event_summary)
|
||||
event["summary"] = f"{event_summary} !!-25:0"
|
||||
mock_next_event.return_value.event = event
|
||||
|
||||
assert await async_setup_component(hass, "google", {"google": GOOGLE_CONFIG})
|
||||
@@ -282,7 +282,7 @@ async def test_all_day_offset_event(hass, mock_next_event):
|
||||
event = copy.deepcopy(TEST_EVENT)
|
||||
event["start"]["date"] = start
|
||||
event["end"]["date"] = end
|
||||
event["summary"] = "{} !!-{}:0".format(event_summary, offset_hours)
|
||||
event["summary"] = f"{event_summary} !!-{offset_hours}:0"
|
||||
mock_next_event.return_value.event = event
|
||||
|
||||
assert await async_setup_component(hass, "google", {"google": GOOGLE_CONFIG})
|
||||
|
||||
@@ -31,7 +31,7 @@ ACCESS_TOKEN = "superdoublesecret"
|
||||
@pytest.fixture
|
||||
def auth_header(hass_access_token):
|
||||
"""Generate an HTTP header with bearer token authorization."""
|
||||
return {AUTHORIZATION: "Bearer {}".format(hass_access_token)}
|
||||
return {AUTHORIZATION: f"Bearer {hass_access_token}"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -27,7 +27,7 @@ MOCK_TOKEN = {"access_token": "dummtoken", "expires_in": 3600}
|
||||
MOCK_JSON = {"devices": {}}
|
||||
MOCK_URL = "https://dummy"
|
||||
MOCK_HEADER = {
|
||||
"Authorization": "Bearer {}".format(MOCK_TOKEN["access_token"]),
|
||||
"Authorization": f"Bearer {MOCK_TOKEN['access_token']}",
|
||||
"X-GFE-SSL": "yes",
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ async def test_get_access_token(hass, aioclient_mock):
|
||||
await _get_homegraph_token(hass, jwt)
|
||||
assert aioclient_mock.call_count == 1
|
||||
assert aioclient_mock.mock_calls[0][3] == {
|
||||
"Authorization": "Bearer {}".format(jwt),
|
||||
"Authorization": f"Bearer {jwt}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ DOMAIN = "test.example.com"
|
||||
USERNAME = "abc123"
|
||||
PASSWORD = "xyz789"
|
||||
|
||||
UPDATE_URL = google_domains.UPDATE_URL.format(USERNAME, PASSWORD)
|
||||
UPDATE_URL = f"https://{USERNAME}:{PASSWORD}@domains.google.com/nic/update"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -48,9 +48,7 @@ class TestGoogleWifiSetup(unittest.TestCase):
|
||||
@requests_mock.Mocker()
|
||||
def test_setup_minimum(self, mock_req):
|
||||
"""Test setup with minimum configuration."""
|
||||
resource = "{}{}{}".format(
|
||||
"http://", google_wifi.DEFAULT_HOST, google_wifi.ENDPOINT
|
||||
)
|
||||
resource = f"http://{google_wifi.DEFAULT_HOST}{google_wifi.ENDPOINT}"
|
||||
mock_req.get(resource, status_code=200)
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
@@ -62,7 +60,7 @@ class TestGoogleWifiSetup(unittest.TestCase):
|
||||
@requests_mock.Mocker()
|
||||
def test_setup_get(self, mock_req):
|
||||
"""Test setup with full configuration."""
|
||||
resource = "{}{}{}".format("http://", "localhost", google_wifi.ENDPOINT)
|
||||
resource = f"http://localhost{google_wifi.ENDPOINT}"
|
||||
mock_req.get(resource, status_code=200)
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
@@ -101,7 +99,7 @@ class TestGoogleWifiSensor(unittest.TestCase):
|
||||
|
||||
def setup_api(self, data, mock_req):
|
||||
"""Set up API with fake data."""
|
||||
resource = "{}{}{}".format("http://", "localhost", google_wifi.ENDPOINT)
|
||||
resource = f"http://localhost{google_wifi.ENDPOINT}"
|
||||
now = datetime(1970, month=1, day=1)
|
||||
with patch("homeassistant.util.dt.now", return_value=now):
|
||||
mock_req.get(resource, text=data, status_code=200)
|
||||
@@ -111,7 +109,7 @@ class TestGoogleWifiSensor(unittest.TestCase):
|
||||
self.sensor_dict = dict()
|
||||
for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
|
||||
sensor = google_wifi.GoogleWifiSensor(self.api, self.name, condition)
|
||||
name = "{}_{}".format(self.name, condition)
|
||||
name = f"{self.name}_{condition}"
|
||||
units = cond_list[1]
|
||||
icon = cond_list[2]
|
||||
self.sensor_dict[condition] = {
|
||||
|
||||
@@ -77,7 +77,7 @@ async def webhook_id(hass, gpslogger_client):
|
||||
|
||||
async def test_missing_data(hass, gpslogger_client, webhook_id):
|
||||
"""Test missing data."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
data = {"latitude": 1.0, "longitude": 1.1, "device": "123"}
|
||||
|
||||
@@ -103,7 +103,7 @@ async def test_missing_data(hass, gpslogger_client, webhook_id):
|
||||
|
||||
async def test_enter_and_exit(hass, gpslogger_client, webhook_id):
|
||||
"""Test when there is a known zone."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
data = {"latitude": HOME_LATITUDE, "longitude": HOME_LONGITUDE, "device": "123"}
|
||||
|
||||
@@ -111,18 +111,14 @@ async def test_enter_and_exit(hass, gpslogger_client, webhook_id):
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
|
||||
).state
|
||||
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
# Enter Home again
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
|
||||
).state
|
||||
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
|
||||
assert STATE_HOME == state_name
|
||||
|
||||
data["longitude"] = 0
|
||||
@@ -132,9 +128,7 @@ async def test_enter_and_exit(hass, gpslogger_client, webhook_id):
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
|
||||
).state
|
||||
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
|
||||
assert STATE_NOT_HOME == state_name
|
||||
|
||||
dev_reg = await hass.helpers.device_registry.async_get_registry()
|
||||
@@ -146,7 +140,7 @@ async def test_enter_and_exit(hass, gpslogger_client, webhook_id):
|
||||
|
||||
async def test_enter_with_attrs(hass, gpslogger_client, webhook_id):
|
||||
"""Test when additional attributes are present."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
data = {
|
||||
"latitude": 1.0,
|
||||
@@ -164,7 +158,7 @@ async def test_enter_with_attrs(hass, gpslogger_client, webhook_id):
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
|
||||
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
|
||||
assert state.state == STATE_NOT_HOME
|
||||
assert state.attributes["gps_accuracy"] == 10.5
|
||||
assert state.attributes["battery_level"] == 10.0
|
||||
@@ -190,7 +184,7 @@ async def test_enter_with_attrs(hass, gpslogger_client, webhook_id):
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
|
||||
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
|
||||
assert state.state == STATE_HOME
|
||||
assert state.attributes["gps_accuracy"] == 123
|
||||
assert state.attributes["battery_level"] == 23
|
||||
@@ -206,16 +200,14 @@ async def test_enter_with_attrs(hass, gpslogger_client, webhook_id):
|
||||
)
|
||||
async def test_load_unload_entry(hass, gpslogger_client, webhook_id):
|
||||
"""Test that the appropriate dispatch signals are added and removed."""
|
||||
url = "/api/webhook/{}".format(webhook_id)
|
||||
url = f"/api/webhook/{webhook_id}"
|
||||
data = {"latitude": HOME_LATITUDE, "longitude": HOME_LONGITUDE, "device": "123"}
|
||||
|
||||
# Enter the Home
|
||||
req = await gpslogger_client.post(url, data=data)
|
||||
await hass.async_block_till_done()
|
||||
assert req.status == HTTP_OK
|
||||
state_name = hass.states.get(
|
||||
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
|
||||
).state
|
||||
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
|
||||
assert STATE_HOME == state_name
|
||||
assert len(hass.data[DATA_DISPATCHER][TRACKER_UPDATE]) == 1
|
||||
|
||||
|
||||
@@ -43,10 +43,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
)
|
||||
|
||||
assert (
|
||||
STATE_ON
|
||||
== self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format("person_and_light")
|
||||
).state
|
||||
STATE_ON == self.hass.states.get(f"{group.DOMAIN}.person_and_light").state
|
||||
)
|
||||
|
||||
def test_setup_group_with_a_non_existing_state(self):
|
||||
@@ -296,9 +293,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
setup_component(self.hass, "group", {"group": group_conf})
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format("second_group")
|
||||
)
|
||||
group_state = self.hass.states.get(f"{group.DOMAIN}.second_group")
|
||||
assert STATE_ON == group_state.state
|
||||
assert set((test_group.entity_id, "light.bowl")) == set(
|
||||
group_state.attributes["entity_id"]
|
||||
@@ -307,7 +302,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
assert "mdi:work" == group_state.attributes.get(ATTR_ICON)
|
||||
assert 1 == group_state.attributes.get(group.ATTR_ORDER)
|
||||
|
||||
group_state = self.hass.states.get(group.ENTITY_ID_FORMAT.format("test_group"))
|
||||
group_state = self.hass.states.get(f"{group.DOMAIN}.test_group")
|
||||
assert STATE_UNKNOWN == group_state.state
|
||||
assert set(("sensor.happy", "hello.world")) == set(
|
||||
group_state.attributes["entity_id"]
|
||||
@@ -373,10 +368,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
)
|
||||
self.hass.states.set("device_tracker.Adam", "cool_state_not_home")
|
||||
self.hass.block_till_done()
|
||||
assert (
|
||||
STATE_NOT_HOME
|
||||
== self.hass.states.get(group.ENTITY_ID_FORMAT.format("peeps")).state
|
||||
)
|
||||
assert STATE_NOT_HOME == self.hass.states.get(f"{group.DOMAIN}.peeps").state
|
||||
|
||||
def test_reloading_groups(self):
|
||||
"""Test reloading the group config."""
|
||||
@@ -431,9 +423,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
common.set_group(self.hass, "modify_group", icon="mdi:play")
|
||||
self.hass.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format("modify_group")
|
||||
)
|
||||
group_state = self.hass.states.get(f"{group.DOMAIN}.modify_group")
|
||||
|
||||
assert self.hass.states.entity_ids() == ["group.modify_group"]
|
||||
assert group_state.attributes.get(ATTR_ICON) == "mdi:play"
|
||||
@@ -463,9 +453,7 @@ async def test_service_group_set_group_remove_group(hass):
|
||||
assert group_state.attributes[group.ATTR_AUTO]
|
||||
assert group_state.attributes["friendly_name"] == "Test"
|
||||
|
||||
common.async_set_group(
|
||||
hass, "user_test_group", entity_ids=["test.entity_bla1"],
|
||||
)
|
||||
common.async_set_group(hass, "user_test_group", entity_ids=["test.entity_bla1"])
|
||||
await hass.async_block_till_done()
|
||||
|
||||
group_state = hass.states.get("group.user_test_group")
|
||||
|
||||
Reference in new issue
Block a user