Use f-strings in integrations starting with "A" (#32110)
* Use f-strings in integrations starting with A * Use f-strings in tests for integrations starting with A * Fix pylint by renaming variable * Fix nested for loop in f-string for aprs device_tracker * Break long lines into multiple short lines * Break long lines into multiple short lines v2
This commit is contained in:
1 parent
a85808e325
commit
524a1a7587
48 files changed
+162
-229
No files matched your search
@@ -40,11 +40,9 @@ async def test_show_authenticate_form(hass):
|
||||
async def test_connection_error(hass, aioclient_mock):
|
||||
"""Test we show user form on AdGuard Home connection error."""
|
||||
aioclient_mock.get(
|
||||
"{}://{}:{}/control/status".format(
|
||||
"https" if FIXTURE_USER_INPUT[CONF_SSL] else "http",
|
||||
FIXTURE_USER_INPUT[CONF_HOST],
|
||||
FIXTURE_USER_INPUT[CONF_PORT],
|
||||
),
|
||||
f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
|
||||
f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
|
||||
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
|
||||
exc=aiohttp.ClientError,
|
||||
)
|
||||
|
||||
@@ -60,11 +58,9 @@ async def test_connection_error(hass, aioclient_mock):
|
||||
async def test_full_flow_implementation(hass, aioclient_mock):
|
||||
"""Test registering an integration and finishing flow works."""
|
||||
aioclient_mock.get(
|
||||
"{}://{}:{}/control/status".format(
|
||||
"https" if FIXTURE_USER_INPUT[CONF_SSL] else "http",
|
||||
FIXTURE_USER_INPUT[CONF_HOST],
|
||||
FIXTURE_USER_INPUT[CONF_PORT],
|
||||
),
|
||||
f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
|
||||
f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
|
||||
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
|
||||
json={"version": "v0.99.0"},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
@@ -244,11 +240,9 @@ async def test_hassio_connection_error(hass, aioclient_mock):
|
||||
async def test_outdated_adguard_version(hass, aioclient_mock):
|
||||
"""Test we show abort when connecting with unsupported AdGuard version."""
|
||||
aioclient_mock.get(
|
||||
"{}://{}:{}/control/status".format(
|
||||
"https" if FIXTURE_USER_INPUT[CONF_SSL] else "http",
|
||||
FIXTURE_USER_INPUT[CONF_HOST],
|
||||
FIXTURE_USER_INPUT[CONF_PORT],
|
||||
),
|
||||
f"{'https' if FIXTURE_USER_INPUT[CONF_SSL] else 'http'}"
|
||||
f"://{FIXTURE_USER_INPUT[CONF_HOST]}"
|
||||
f":{FIXTURE_USER_INPUT[CONF_PORT]}/control/status",
|
||||
json={"version": "v0.98.0"},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
@@ -207,20 +207,18 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||
hass.states.async_set("alarm_control_panel.entity", STATE_ALARM_TRIGGERED)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data[
|
||||
"some"
|
||||
] == "triggered - device - {} - pending - triggered - None".format(
|
||||
"alarm_control_panel.entity"
|
||||
assert (
|
||||
calls[0].data["some"]
|
||||
== "triggered - device - alarm_control_panel.entity - pending - triggered - None"
|
||||
)
|
||||
|
||||
# Fake that the entity is disarmed.
|
||||
hass.states.async_set("alarm_control_panel.entity", STATE_ALARM_DISARMED)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data[
|
||||
"some"
|
||||
] == "disarmed - device - {} - triggered - disarmed - None".format(
|
||||
"alarm_control_panel.entity"
|
||||
assert (
|
||||
calls[1].data["some"]
|
||||
== "disarmed - device - alarm_control_panel.entity - triggered - disarmed - None"
|
||||
)
|
||||
|
||||
# Fake that the entity is armed home.
|
||||
@@ -228,10 +226,9 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||
hass.states.async_set("alarm_control_panel.entity", STATE_ALARM_ARMED_HOME)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 3
|
||||
assert calls[2].data[
|
||||
"some"
|
||||
] == "armed_home - device - {} - pending - armed_home - None".format(
|
||||
"alarm_control_panel.entity"
|
||||
assert (
|
||||
calls[2].data["some"]
|
||||
== "armed_home - device - alarm_control_panel.entity - pending - armed_home - None"
|
||||
)
|
||||
|
||||
# Fake that the entity is armed away.
|
||||
@@ -239,10 +236,9 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||
hass.states.async_set("alarm_control_panel.entity", STATE_ALARM_ARMED_AWAY)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 4
|
||||
assert calls[3].data[
|
||||
"some"
|
||||
] == "armed_away - device - {} - pending - armed_away - None".format(
|
||||
"alarm_control_panel.entity"
|
||||
assert (
|
||||
calls[3].data["some"]
|
||||
== "armed_away - device - alarm_control_panel.entity - pending - armed_away - None"
|
||||
)
|
||||
|
||||
# Fake that the entity is armed night.
|
||||
@@ -250,8 +246,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||
hass.states.async_set("alarm_control_panel.entity", STATE_ALARM_ARMED_NIGHT)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 5
|
||||
assert calls[4].data[
|
||||
"some"
|
||||
] == "armed_night - device - {} - pending - armed_night - None".format(
|
||||
"alarm_control_panel.entity"
|
||||
assert (
|
||||
calls[4].data["some"]
|
||||
== "armed_night - device - alarm_control_panel.entity - pending - armed_night - None"
|
||||
)
|
||||
@@ -60,7 +60,7 @@ TEST_NOACK = [
|
||||
None,
|
||||
None,
|
||||
]
|
||||
ENTITY_ID = alert.ENTITY_ID_FORMAT.format(NAME)
|
||||
ENTITY_ID = f"{alert.DOMAIN}.{NAME}"
|
||||
|
||||
|
||||
def turn_on(hass, entity_id):
|
||||
|
||||
@@ -63,7 +63,7 @@ def alexa_client(loop, hass, hass_client):
|
||||
|
||||
|
||||
def _flash_briefing_req(client, briefing_id):
|
||||
return client.get("/api/alexa/flash_briefings/{}".format(briefing_id))
|
||||
return client.get(f"/api/alexa/flash_briefings/{briefing_id}")
|
||||
|
||||
|
||||
async def test_flash_briefing_invalid_id(alexa_client):
|
||||
|
||||
@@ -36,7 +36,7 @@ async def test_api_list_state_entities(hass, mock_api_client):
|
||||
async def test_api_get_state(hass, mock_api_client):
|
||||
"""Test if the debug interface allows us to get a state."""
|
||||
hass.states.async_set("hello.world", "nice", {"attr": 1})
|
||||
resp = await mock_api_client.get(const.URL_API_STATES_ENTITY.format("hello.world"))
|
||||
resp = await mock_api_client.get("/api/states/hello.world")
|
||||
assert resp.status == 200
|
||||
json = await resp.json()
|
||||
|
||||
@@ -51,9 +51,7 @@ async def test_api_get_state(hass, mock_api_client):
|
||||
|
||||
async def test_api_get_non_existing_state(hass, mock_api_client):
|
||||
"""Test if the debug interface allows us to get a state."""
|
||||
resp = await mock_api_client.get(
|
||||
const.URL_API_STATES_ENTITY.format("does_not_exist")
|
||||
)
|
||||
resp = await mock_api_client.get("/api/states/does_not_exist")
|
||||
assert resp.status == 404
|
||||
|
||||
|
||||
@@ -62,8 +60,7 @@ async def test_api_state_change(hass, mock_api_client):
|
||||
hass.states.async_set("test.test", "not_to_be_set")
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test.test"),
|
||||
json={"state": "debug_state_change2"},
|
||||
"/api/states/test.test", json={"state": "debug_state_change2"}
|
||||
)
|
||||
|
||||
assert hass.states.get("test.test").state == "debug_state_change2"
|
||||
@@ -75,8 +72,7 @@ async def test_api_state_change_of_non_existing_entity(hass, mock_api_client):
|
||||
new_state = "debug_state_change"
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test_entity.that_does_not_exist"),
|
||||
json={"state": new_state},
|
||||
"/api/states/test_entity.that_does_not_exist", json={"state": new_state}
|
||||
)
|
||||
|
||||
assert resp.status == 201
|
||||
@@ -88,7 +84,7 @@ async def test_api_state_change_of_non_existing_entity(hass, mock_api_client):
|
||||
async def test_api_state_change_with_bad_data(hass, mock_api_client):
|
||||
"""Test if API sends appropriate error if we omit state."""
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test_entity.that_does_not_exist"), json={}
|
||||
"/api/states/test_entity.that_does_not_exist", json={}
|
||||
)
|
||||
|
||||
assert resp.status == 400
|
||||
@@ -98,15 +94,13 @@ async def test_api_state_change_with_bad_data(hass, mock_api_client):
|
||||
async def test_api_state_change_to_zero_value(hass, mock_api_client):
|
||||
"""Test if changing a state to a zero value is possible."""
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test_entity.with_zero_state"),
|
||||
json={"state": 0},
|
||||
"/api/states/test_entity.with_zero_state", json={"state": 0}
|
||||
)
|
||||
|
||||
assert resp.status == 201
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test_entity.with_zero_state"),
|
||||
json={"state": 0.0},
|
||||
"/api/states/test_entity.with_zero_state", json={"state": 0.0}
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
@@ -126,15 +120,12 @@ async def test_api_state_change_push(hass, mock_api_client):
|
||||
|
||||
hass.bus.async_listen(const.EVENT_STATE_CHANGED, event_listener)
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test.test"), json={"state": "not_to_be_set"}
|
||||
)
|
||||
await mock_api_client.post("/api/states/test.test", json={"state": "not_to_be_set"})
|
||||
await hass.async_block_till_done()
|
||||
assert len(events) == 0
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_STATES_ENTITY.format("test.test"),
|
||||
json={"state": "not_to_be_set", "force_update": True},
|
||||
"/api/states/test.test", json={"state": "not_to_be_set", "force_update": True}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(events) == 1
|
||||
@@ -152,7 +143,7 @@ async def test_api_fire_event_with_no_data(hass, mock_api_client):
|
||||
|
||||
hass.bus.async_listen_once("test.event_no_data", listener)
|
||||
|
||||
await mock_api_client.post(const.URL_API_EVENTS_EVENT.format("test.event_no_data"))
|
||||
await mock_api_client.post("/api/events/test.event_no_data")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(test_value) == 1
|
||||
@@ -174,9 +165,7 @@ async def test_api_fire_event_with_data(hass, mock_api_client):
|
||||
|
||||
hass.bus.async_listen_once("test_event_with_data", listener)
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_EVENTS_EVENT.format("test_event_with_data"), json={"test": 1}
|
||||
)
|
||||
await mock_api_client.post("/api/events/test_event_with_data", json={"test": 1})
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -196,8 +185,7 @@ async def test_api_fire_event_with_invalid_json(hass, mock_api_client):
|
||||
hass.bus.async_listen_once("test_event_bad_data", listener)
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_EVENTS_EVENT.format("test_event_bad_data"),
|
||||
data=json.dumps("not an object"),
|
||||
"/api/events/test_event_bad_data", data=json.dumps("not an object")
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@@ -207,8 +195,7 @@ async def test_api_fire_event_with_invalid_json(hass, mock_api_client):
|
||||
|
||||
# Try now with valid but unusable JSON
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_EVENTS_EVENT.format("test_event_bad_data"),
|
||||
data=json.dumps([1, 2, 3]),
|
||||
"/api/events/test_event_bad_data", data=json.dumps([1, 2, 3])
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@@ -272,9 +259,7 @@ async def test_api_call_service_no_data(hass, mock_api_client):
|
||||
|
||||
hass.services.async_register("test_domain", "test_service", listener)
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format("test_domain", "test_service")
|
||||
)
|
||||
await mock_api_client.post("/api/services/test_domain/test_service")
|
||||
await hass.async_block_till_done()
|
||||
assert len(test_value) == 1
|
||||
|
||||
@@ -295,8 +280,7 @@ async def test_api_call_service_with_data(hass, mock_api_client):
|
||||
hass.services.async_register("test_domain", "test_service", listener)
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format("test_domain", "test_service"),
|
||||
json={"test": 1},
|
||||
"/api/services/test_domain/test_service", json={"test": 1}
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@@ -348,7 +332,7 @@ async def test_stream_with_restricted(hass, mock_api_client):
|
||||
listen_count = _listen_count(hass)
|
||||
|
||||
resp = await mock_api_client.get(
|
||||
"{}?restrict=test_event1,test_event3".format(const.URL_API_STREAM)
|
||||
f"{const.URL_API_STREAM}?restrict=test_event1,test_event3"
|
||||
)
|
||||
assert resp.status == 200
|
||||
assert listen_count + 1 == _listen_count(hass)
|
||||
@@ -403,7 +387,7 @@ async def test_api_error_log(hass, aiohttp_client, hass_access_token, hass_admin
|
||||
) as mock_file:
|
||||
resp = await client.get(
|
||||
const.URL_API_ERROR_LOG,
|
||||
headers={"Authorization": "Bearer {}".format(hass_access_token)},
|
||||
headers={"Authorization": f"Bearer {hass_access_token}"},
|
||||
)
|
||||
|
||||
assert len(mock_file.mock_calls) == 1
|
||||
@@ -415,7 +399,7 @@ async def test_api_error_log(hass, aiohttp_client, hass_access_token, hass_admin
|
||||
hass_admin_user.groups = []
|
||||
resp = await client.get(
|
||||
const.URL_API_ERROR_LOG,
|
||||
headers={"Authorization": "Bearer {}".format(hass_access_token)},
|
||||
headers={"Authorization": f"Bearer {hass_access_token}"},
|
||||
)
|
||||
assert resp.status == 401
|
||||
|
||||
@@ -432,8 +416,8 @@ async def test_api_fire_event_context(hass, mock_api_client, hass_access_token):
|
||||
hass.bus.async_listen("test.event", listener)
|
||||
|
||||
await mock_api_client.post(
|
||||
const.URL_API_EVENTS_EVENT.format("test.event"),
|
||||
headers={"authorization": "Bearer {}".format(hass_access_token)},
|
||||
"/api/events/test.event",
|
||||
headers={"authorization": f"Bearer {hass_access_token}"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -449,7 +433,7 @@ async def test_api_call_service_context(hass, mock_api_client, hass_access_token
|
||||
|
||||
await mock_api_client.post(
|
||||
"/api/services/test_domain/test_service",
|
||||
headers={"authorization": "Bearer {}".format(hass_access_token)},
|
||||
headers={"authorization": f"Bearer {hass_access_token}"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -464,7 +448,7 @@ async def test_api_set_state_context(hass, mock_api_client, hass_access_token):
|
||||
await mock_api_client.post(
|
||||
"/api/states/light.kitchen",
|
||||
json={"state": "on"},
|
||||
headers={"authorization": "Bearer {}".format(hass_access_token)},
|
||||
headers={"authorization": f"Bearer {hass_access_token}"},
|
||||
)
|
||||
|
||||
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
|
||||
@@ -542,9 +526,7 @@ async def test_rendering_template_legacy_user(
|
||||
|
||||
async def test_api_call_service_not_found(hass, mock_api_client):
|
||||
"""Test if the API fails 400 if unknown service."""
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format("test_domain", "test_service")
|
||||
)
|
||||
resp = await mock_api_client.post("/api/services/test_domain/test_service")
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
@@ -562,7 +544,6 @@ async def test_api_call_service_bad_data(hass, mock_api_client):
|
||||
)
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_SERVICES_SERVICE.format("test_domain", "test_service"),
|
||||
json={"hello": 5},
|
||||
"/api/services/test_domain/test_service", json={"hello": 5}
|
||||
)
|
||||
assert resp.status == 400
|
||||
@@ -28,7 +28,7 @@ async def test_login_new_user_and_trying_refresh_token(hass, aiohttp_client):
|
||||
step = await resp.json()
|
||||
|
||||
resp = await client.post(
|
||||
"/auth/login_flow/{}".format(step["flow_id"]),
|
||||
f"/auth/login_flow/{step['flow_id']}",
|
||||
json={"client_id": CLIENT_ID, "username": "test-user", "password": "test-pass"},
|
||||
)
|
||||
|
||||
@@ -71,7 +71,7 @@ async def test_login_new_user_and_trying_refresh_token(hass, aiohttp_client):
|
||||
assert resp.status == 401
|
||||
|
||||
resp = await client.get(
|
||||
"/api/", headers={"authorization": "Bearer {}".format(tokens["access_token"])}
|
||||
"/api/", headers={"authorization": f"Bearer {tokens['access_token']}"}
|
||||
)
|
||||
assert resp.status == 200
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ async def async_get_code(hass, aiohttp_client):
|
||||
step = await resp.json()
|
||||
|
||||
resp = await client.post(
|
||||
"/auth/login_flow/{}".format(step["flow_id"]),
|
||||
f"/auth/login_flow/{step['flow_id']}",
|
||||
json={"client_id": CLIENT_ID, "username": "2nd-user", "password": "2nd-pass"},
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ async def test_link_user(hass, aiohttp_client):
|
||||
resp = await client.post(
|
||||
"/auth/link_user",
|
||||
json={"client_id": CLIENT_ID, "code": code},
|
||||
headers={"authorization": "Bearer {}".format(info["access_token"])},
|
||||
headers={"authorization": f"Bearer {info['access_token']}"},
|
||||
)
|
||||
|
||||
assert resp.status == 200
|
||||
@@ -84,7 +84,7 @@ async def test_link_user_invalid_client_id(hass, aiohttp_client):
|
||||
resp = await client.post(
|
||||
"/auth/link_user",
|
||||
json={"client_id": "invalid", "code": code},
|
||||
headers={"authorization": "Bearer {}".format(info["access_token"])},
|
||||
headers={"authorization": f"Bearer {info['access_token']}"},
|
||||
)
|
||||
|
||||
assert resp.status == 400
|
||||
@@ -100,7 +100,7 @@ async def test_link_user_invalid_code(hass, aiohttp_client):
|
||||
resp = await client.post(
|
||||
"/auth/link_user",
|
||||
json={"client_id": CLIENT_ID, "code": "invalid"},
|
||||
headers={"authorization": "Bearer {}".format(info["access_token"])},
|
||||
headers={"authorization": f"Bearer {info['access_token']}"},
|
||||
)
|
||||
|
||||
assert resp.status == 400
|
||||
|
||||
@@ -54,7 +54,7 @@ async def test_invalid_username_password(hass, aiohttp_client):
|
||||
|
||||
# Incorrect username
|
||||
resp = await client.post(
|
||||
"/auth/login_flow/{}".format(step["flow_id"]),
|
||||
f"/auth/login_flow/{step['flow_id']}",
|
||||
json={
|
||||
"client_id": CLIENT_ID,
|
||||
"username": "wrong-user",
|
||||
@@ -70,7 +70,7 @@ async def test_invalid_username_password(hass, aiohttp_client):
|
||||
|
||||
# Incorrect password
|
||||
resp = await client.post(
|
||||
"/auth/login_flow/{}".format(step["flow_id"]),
|
||||
f"/auth/login_flow/{step['flow_id']}",
|
||||
json={
|
||||
"client_id": CLIENT_ID,
|
||||
"username": "test-user",
|
||||
@@ -105,7 +105,7 @@ async def test_login_exist_user(hass, aiohttp_client):
|
||||
step = await resp.json()
|
||||
|
||||
resp = await client.post(
|
||||
"/auth/login_flow/{}".format(step["flow_id"]),
|
||||
f"/auth/login_flow/{step['flow_id']}",
|
||||
json={"client_id": CLIENT_ID, "username": "test-user", "password": "test-pass"},
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user